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); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 13 | _Py_IDENTIFIER(type_ignores); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 14 | static char *Module_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 15 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 16 | "type_ignores", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 17 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 18 | static PyTypeObject *Interactive_type; |
| 19 | static char *Interactive_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 20 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 21 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 22 | static PyTypeObject *Expression_type; |
| 23 | static char *Expression_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 24 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 25 | }; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 26 | static PyTypeObject *FunctionType_type; |
| 27 | _Py_IDENTIFIER(argtypes); |
| 28 | _Py_IDENTIFIER(returns); |
| 29 | static char *FunctionType_fields[]={ |
| 30 | "argtypes", |
| 31 | "returns", |
| 32 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 33 | static PyTypeObject *Suite_type; |
| 34 | static char *Suite_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 35 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 36 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 37 | static PyTypeObject *stmt_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 38 | _Py_IDENTIFIER(lineno); |
| 39 | _Py_IDENTIFIER(col_offset); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 40 | _Py_IDENTIFIER(end_lineno); |
| 41 | _Py_IDENTIFIER(end_col_offset); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 42 | static char *stmt_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 43 | "lineno", |
| 44 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 45 | "end_lineno", |
| 46 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 47 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 48 | static PyObject* ast2obj_stmt(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 49 | static PyTypeObject *FunctionDef_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 50 | _Py_IDENTIFIER(name); |
| 51 | _Py_IDENTIFIER(args); |
| 52 | _Py_IDENTIFIER(decorator_list); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 53 | _Py_IDENTIFIER(type_comment); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 54 | static char *FunctionDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 55 | "name", |
| 56 | "args", |
| 57 | "body", |
| 58 | "decorator_list", |
| 59 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 60 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 61 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 62 | static PyTypeObject *AsyncFunctionDef_type; |
| 63 | static char *AsyncFunctionDef_fields[]={ |
| 64 | "name", |
| 65 | "args", |
| 66 | "body", |
| 67 | "decorator_list", |
| 68 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 69 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 70 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 71 | static PyTypeObject *ClassDef_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 72 | _Py_IDENTIFIER(bases); |
| 73 | _Py_IDENTIFIER(keywords); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 74 | static char *ClassDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 75 | "name", |
| 76 | "bases", |
| 77 | "keywords", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 78 | "body", |
| 79 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 80 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 81 | static PyTypeObject *Return_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 82 | _Py_IDENTIFIER(value); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 83 | static char *Return_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 84 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 85 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 86 | static PyTypeObject *Delete_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 87 | _Py_IDENTIFIER(targets); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 88 | static char *Delete_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 89 | "targets", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 90 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 91 | static PyTypeObject *Assign_type; |
| 92 | static char *Assign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 93 | "targets", |
| 94 | "value", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 95 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 96 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 97 | static PyTypeObject *AugAssign_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 98 | _Py_IDENTIFIER(target); |
| 99 | _Py_IDENTIFIER(op); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 100 | static char *AugAssign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 101 | "target", |
| 102 | "op", |
| 103 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 104 | }; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 105 | static PyTypeObject *AnnAssign_type; |
| 106 | _Py_IDENTIFIER(annotation); |
| 107 | _Py_IDENTIFIER(simple); |
| 108 | static char *AnnAssign_fields[]={ |
| 109 | "target", |
| 110 | "annotation", |
| 111 | "value", |
| 112 | "simple", |
| 113 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 114 | static PyTypeObject *For_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 115 | _Py_IDENTIFIER(iter); |
| 116 | _Py_IDENTIFIER(orelse); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 117 | static char *For_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 118 | "target", |
| 119 | "iter", |
| 120 | "body", |
| 121 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 122 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 123 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 124 | static PyTypeObject *AsyncFor_type; |
| 125 | static char *AsyncFor_fields[]={ |
| 126 | "target", |
| 127 | "iter", |
| 128 | "body", |
| 129 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 130 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 131 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 132 | static PyTypeObject *While_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 133 | _Py_IDENTIFIER(test); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 134 | static char *While_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 135 | "test", |
| 136 | "body", |
| 137 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 138 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 139 | static PyTypeObject *If_type; |
| 140 | static char *If_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 141 | "test", |
| 142 | "body", |
| 143 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 144 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 145 | static PyTypeObject *With_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 146 | _Py_IDENTIFIER(items); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 147 | static char *With_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 148 | "items", |
| 149 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 150 | "type_comment", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 151 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 152 | static PyTypeObject *AsyncWith_type; |
| 153 | static char *AsyncWith_fields[]={ |
| 154 | "items", |
| 155 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 156 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 157 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 158 | static PyTypeObject *Raise_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 159 | _Py_IDENTIFIER(exc); |
| 160 | _Py_IDENTIFIER(cause); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 161 | static char *Raise_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 162 | "exc", |
| 163 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 164 | }; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 165 | static PyTypeObject *Try_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 166 | _Py_IDENTIFIER(handlers); |
| 167 | _Py_IDENTIFIER(finalbody); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 168 | static char *Try_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 169 | "body", |
| 170 | "handlers", |
| 171 | "orelse", |
| 172 | "finalbody", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 173 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 174 | static PyTypeObject *Assert_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 175 | _Py_IDENTIFIER(msg); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 176 | static char *Assert_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 177 | "test", |
| 178 | "msg", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 179 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 180 | static PyTypeObject *Import_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 181 | _Py_IDENTIFIER(names); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 182 | static char *Import_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 183 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 184 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 185 | static PyTypeObject *ImportFrom_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 186 | _Py_IDENTIFIER(module); |
| 187 | _Py_IDENTIFIER(level); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 188 | static char *ImportFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 189 | "module", |
| 190 | "names", |
| 191 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 192 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 193 | static PyTypeObject *Global_type; |
| 194 | static char *Global_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 195 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 196 | }; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 197 | static PyTypeObject *Nonlocal_type; |
| 198 | static char *Nonlocal_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 199 | "names", |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 200 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 201 | static PyTypeObject *Expr_type; |
| 202 | static char *Expr_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 203 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 204 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 205 | static PyTypeObject *Pass_type; |
| 206 | static PyTypeObject *Break_type; |
| 207 | static PyTypeObject *Continue_type; |
| 208 | static PyTypeObject *expr_type; |
| 209 | static char *expr_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 210 | "lineno", |
| 211 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 212 | "end_lineno", |
| 213 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 214 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 215 | static PyObject* ast2obj_expr(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 216 | static PyTypeObject *BoolOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 217 | _Py_IDENTIFIER(values); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 218 | static char *BoolOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 219 | "op", |
| 220 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 221 | }; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 222 | static PyTypeObject *NamedExpr_type; |
| 223 | static char *NamedExpr_fields[]={ |
| 224 | "target", |
| 225 | "value", |
| 226 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 227 | static PyTypeObject *BinOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 228 | _Py_IDENTIFIER(left); |
| 229 | _Py_IDENTIFIER(right); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 230 | static char *BinOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 231 | "left", |
| 232 | "op", |
| 233 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 234 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 235 | static PyTypeObject *UnaryOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 236 | _Py_IDENTIFIER(operand); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 237 | static char *UnaryOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 238 | "op", |
| 239 | "operand", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 240 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 241 | static PyTypeObject *Lambda_type; |
| 242 | static char *Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 243 | "args", |
| 244 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 245 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 246 | static PyTypeObject *IfExp_type; |
| 247 | static char *IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 248 | "test", |
| 249 | "body", |
| 250 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 251 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 252 | static PyTypeObject *Dict_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 253 | _Py_IDENTIFIER(keys); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 254 | static char *Dict_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 255 | "keys", |
| 256 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 257 | }; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 258 | static PyTypeObject *Set_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 259 | _Py_IDENTIFIER(elts); |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 260 | static char *Set_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 261 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 262 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 263 | static PyTypeObject *ListComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 264 | _Py_IDENTIFIER(elt); |
| 265 | _Py_IDENTIFIER(generators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 266 | static char *ListComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 267 | "elt", |
| 268 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 269 | }; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 270 | static PyTypeObject *SetComp_type; |
| 271 | static char *SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 272 | "elt", |
| 273 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 274 | }; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 275 | static PyTypeObject *DictComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 276 | _Py_IDENTIFIER(key); |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 277 | static char *DictComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 278 | "key", |
| 279 | "value", |
| 280 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 281 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 282 | static PyTypeObject *GeneratorExp_type; |
| 283 | static char *GeneratorExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 284 | "elt", |
| 285 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 286 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 287 | static PyTypeObject *Await_type; |
| 288 | static char *Await_fields[]={ |
| 289 | "value", |
| 290 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 291 | static PyTypeObject *Yield_type; |
| 292 | static char *Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 293 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 294 | }; |
| 295 | static PyTypeObject *YieldFrom_type; |
| 296 | static char *YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 297 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 298 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 299 | static PyTypeObject *Compare_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 300 | _Py_IDENTIFIER(ops); |
| 301 | _Py_IDENTIFIER(comparators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 302 | static char *Compare_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 303 | "left", |
| 304 | "ops", |
| 305 | "comparators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 306 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 307 | static PyTypeObject *Call_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 308 | _Py_IDENTIFIER(func); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 309 | static char *Call_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 310 | "func", |
| 311 | "args", |
| 312 | "keywords", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 313 | }; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 314 | static PyTypeObject *FormattedValue_type; |
| 315 | _Py_IDENTIFIER(conversion); |
| 316 | _Py_IDENTIFIER(format_spec); |
| 317 | static char *FormattedValue_fields[]={ |
| 318 | "value", |
| 319 | "conversion", |
| 320 | "format_spec", |
| 321 | }; |
| 322 | static PyTypeObject *JoinedStr_type; |
| 323 | static char *JoinedStr_fields[]={ |
| 324 | "values", |
| 325 | }; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 326 | static PyTypeObject *Constant_type; |
| 327 | static char *Constant_fields[]={ |
| 328 | "value", |
| 329 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 330 | static PyTypeObject *Attribute_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 331 | _Py_IDENTIFIER(attr); |
| 332 | _Py_IDENTIFIER(ctx); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 333 | static char *Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 334 | "value", |
| 335 | "attr", |
| 336 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 337 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 338 | static PyTypeObject *Subscript_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 339 | _Py_IDENTIFIER(slice); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 340 | static char *Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 341 | "value", |
| 342 | "slice", |
| 343 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 344 | }; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 345 | static PyTypeObject *Starred_type; |
| 346 | static char *Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 347 | "value", |
| 348 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 349 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 350 | static PyTypeObject *Name_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 351 | _Py_IDENTIFIER(id); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 352 | static char *Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 353 | "id", |
| 354 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 355 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 356 | static PyTypeObject *List_type; |
| 357 | static char *List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 358 | "elts", |
| 359 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 360 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 361 | static PyTypeObject *Tuple_type; |
| 362 | static char *Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 363 | "elts", |
| 364 | "ctx", |
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 *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 367 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
Serhiy Storchaka | d8b3a98 | 2019-03-05 20:42:06 +0200 | [diff] [blame] | 368 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 369 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 370 | static PyTypeObject *Load_type; |
| 371 | static PyTypeObject *Store_type; |
| 372 | static PyTypeObject *Del_type; |
| 373 | static PyTypeObject *AugLoad_type; |
| 374 | static PyTypeObject *AugStore_type; |
| 375 | static PyTypeObject *Param_type; |
| 376 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 377 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 378 | static PyTypeObject *Slice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 379 | _Py_IDENTIFIER(lower); |
| 380 | _Py_IDENTIFIER(upper); |
| 381 | _Py_IDENTIFIER(step); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 382 | static char *Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 383 | "lower", |
| 384 | "upper", |
| 385 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 386 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 387 | static PyTypeObject *ExtSlice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 388 | _Py_IDENTIFIER(dims); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 389 | static char *ExtSlice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 390 | "dims", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 391 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 392 | static PyTypeObject *Index_type; |
| 393 | static char *Index_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 394 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 395 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 396 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 397 | static PyObject *And_singleton, *Or_singleton; |
| 398 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 399 | static PyTypeObject *And_type; |
| 400 | static PyTypeObject *Or_type; |
| 401 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 402 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 403 | *MatMult_singleton, *Div_singleton, *Mod_singleton, *Pow_singleton, |
| 404 | *LShift_singleton, *RShift_singleton, *BitOr_singleton, *BitXor_singleton, |
| 405 | *BitAnd_singleton, *FloorDiv_singleton; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 406 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 407 | static PyTypeObject *Add_type; |
| 408 | static PyTypeObject *Sub_type; |
| 409 | static PyTypeObject *Mult_type; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 410 | static PyTypeObject *MatMult_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 411 | static PyTypeObject *Div_type; |
| 412 | static PyTypeObject *Mod_type; |
| 413 | static PyTypeObject *Pow_type; |
| 414 | static PyTypeObject *LShift_type; |
| 415 | static PyTypeObject *RShift_type; |
| 416 | static PyTypeObject *BitOr_type; |
| 417 | static PyTypeObject *BitXor_type; |
| 418 | static PyTypeObject *BitAnd_type; |
| 419 | static PyTypeObject *FloorDiv_type; |
| 420 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 421 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 422 | *USub_singleton; |
| 423 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 424 | static PyTypeObject *Invert_type; |
| 425 | static PyTypeObject *Not_type; |
| 426 | static PyTypeObject *UAdd_type; |
| 427 | static PyTypeObject *USub_type; |
| 428 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 429 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 430 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 431 | *NotIn_singleton; |
| 432 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 433 | static PyTypeObject *Eq_type; |
| 434 | static PyTypeObject *NotEq_type; |
| 435 | static PyTypeObject *Lt_type; |
| 436 | static PyTypeObject *LtE_type; |
| 437 | static PyTypeObject *Gt_type; |
| 438 | static PyTypeObject *GtE_type; |
| 439 | static PyTypeObject *Is_type; |
| 440 | static PyTypeObject *IsNot_type; |
| 441 | static PyTypeObject *In_type; |
| 442 | static PyTypeObject *NotIn_type; |
| 443 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 444 | static PyObject* ast2obj_comprehension(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 445 | _Py_IDENTIFIER(ifs); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 446 | _Py_IDENTIFIER(is_async); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 447 | static char *comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 448 | "target", |
| 449 | "iter", |
| 450 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 451 | "is_async", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 452 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 453 | static PyTypeObject *excepthandler_type; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 454 | static char *excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 455 | "lineno", |
| 456 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 457 | "end_lineno", |
| 458 | "end_col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 459 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 460 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 461 | static PyTypeObject *ExceptHandler_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 462 | _Py_IDENTIFIER(type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 463 | static char *ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 464 | "type", |
| 465 | "name", |
| 466 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 467 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 468 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 469 | static PyObject* ast2obj_arguments(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 470 | _Py_IDENTIFIER(vararg); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 471 | _Py_IDENTIFIER(kwonlyargs); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 472 | _Py_IDENTIFIER(kw_defaults); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 473 | _Py_IDENTIFIER(kwarg); |
| 474 | _Py_IDENTIFIER(defaults); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 475 | static char *arguments_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 476 | "args", |
| 477 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 478 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 479 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 480 | "kwarg", |
| 481 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 482 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 483 | static PyTypeObject *arg_type; |
| 484 | static PyObject* ast2obj_arg(void*); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 485 | static char *arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 486 | "lineno", |
| 487 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 488 | "end_lineno", |
| 489 | "end_col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 490 | }; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 491 | _Py_IDENTIFIER(arg); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 492 | static char *arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 493 | "arg", |
| 494 | "annotation", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 495 | "type_comment", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 496 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 497 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 498 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 499 | static char *keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 500 | "arg", |
| 501 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 502 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 503 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 504 | static PyObject* ast2obj_alias(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 505 | _Py_IDENTIFIER(asname); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 506 | static char *alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 507 | "name", |
| 508 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 509 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 510 | static PyTypeObject *withitem_type; |
| 511 | static PyObject* ast2obj_withitem(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 512 | _Py_IDENTIFIER(context_expr); |
| 513 | _Py_IDENTIFIER(optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 514 | static char *withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 515 | "context_expr", |
| 516 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 517 | }; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 518 | static PyTypeObject *type_ignore_type; |
| 519 | static PyObject* ast2obj_type_ignore(void*); |
| 520 | static PyTypeObject *TypeIgnore_type; |
| 521 | static char *TypeIgnore_fields[]={ |
| 522 | "lineno", |
| 523 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 524 | |
| 525 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 526 | _Py_IDENTIFIER(_fields); |
| 527 | _Py_IDENTIFIER(_attributes); |
| 528 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 529 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 530 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 531 | PyObject *dict; |
| 532 | } AST_object; |
| 533 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 534 | static void |
| 535 | ast_dealloc(AST_object *self) |
| 536 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 537 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
| 538 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 539 | Py_CLEAR(self->dict); |
Antoine Pitrou | 5075074 | 2012-07-08 12:43:32 +0200 | [diff] [blame] | 540 | Py_TYPE(self)->tp_free(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 541 | } |
| 542 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 543 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 544 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 545 | { |
| 546 | Py_VISIT(self->dict); |
| 547 | return 0; |
| 548 | } |
| 549 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 550 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 551 | ast_clear(AST_object *self) |
| 552 | { |
| 553 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 554 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 558 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 559 | { |
| 560 | Py_ssize_t i, numfields = 0; |
| 561 | int res = -1; |
| 562 | PyObject *key, *value, *fields; |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 563 | if (_PyObject_LookupAttrId((PyObject*)Py_TYPE(self), &PyId__fields, &fields) < 0) { |
| 564 | goto cleanup; |
| 565 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 566 | if (fields) { |
| 567 | numfields = PySequence_Size(fields); |
| 568 | if (numfields == -1) |
| 569 | goto cleanup; |
| 570 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 571 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 572 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 573 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 574 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 575 | "%zd positional argument%s", |
| 576 | Py_TYPE(self)->tp_name, |
| 577 | numfields, numfields == 1 ? "" : "s"); |
| 578 | res = -1; |
| 579 | goto cleanup; |
| 580 | } |
| 581 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 582 | /* cannot be reached when fields is NULL */ |
| 583 | PyObject *name = PySequence_GetItem(fields, i); |
| 584 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 585 | res = -1; |
| 586 | goto cleanup; |
| 587 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 588 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 589 | Py_DECREF(name); |
| 590 | if (res < 0) |
| 591 | goto cleanup; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 592 | } |
| 593 | if (kw) { |
| 594 | i = 0; /* needed by PyDict_Next */ |
| 595 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 596 | res = PyObject_SetAttr(self, key, value); |
| 597 | if (res < 0) |
| 598 | goto cleanup; |
| 599 | } |
| 600 | } |
| 601 | cleanup: |
| 602 | Py_XDECREF(fields); |
| 603 | return res; |
| 604 | } |
| 605 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 606 | /* Pickling support */ |
| 607 | static PyObject * |
| 608 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 609 | { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 610 | _Py_IDENTIFIER(__dict__); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 611 | PyObject *dict; |
| 612 | if (_PyObject_LookupAttrId(self, &PyId___dict__, &dict) < 0) { |
| 613 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 614 | } |
| 615 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 616 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 617 | } |
| 618 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 619 | } |
| 620 | |
| 621 | static PyMethodDef ast_type_methods[] = { |
| 622 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 623 | {NULL} |
| 624 | }; |
| 625 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 626 | static PyGetSetDef ast_type_getsets[] = { |
| 627 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 628 | {NULL} |
| 629 | }; |
| 630 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 631 | static PyTypeObject AST_type = { |
| 632 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 633 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 634 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 635 | 0, |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 636 | (destructor)ast_dealloc, /* tp_dealloc */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 637 | 0, /* tp_print */ |
| 638 | 0, /* tp_getattr */ |
| 639 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 640 | 0, /* tp_reserved */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 641 | 0, /* tp_repr */ |
| 642 | 0, /* tp_as_number */ |
| 643 | 0, /* tp_as_sequence */ |
| 644 | 0, /* tp_as_mapping */ |
| 645 | 0, /* tp_hash */ |
| 646 | 0, /* tp_call */ |
| 647 | 0, /* tp_str */ |
| 648 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 649 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 650 | 0, /* tp_as_buffer */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 651 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 652 | 0, /* tp_doc */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 653 | (traverseproc)ast_traverse, /* tp_traverse */ |
| 654 | (inquiry)ast_clear, /* tp_clear */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 655 | 0, /* tp_richcompare */ |
| 656 | 0, /* tp_weaklistoffset */ |
| 657 | 0, /* tp_iter */ |
| 658 | 0, /* tp_iternext */ |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 659 | ast_type_methods, /* tp_methods */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 660 | 0, /* tp_members */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 661 | ast_type_getsets, /* tp_getset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 662 | 0, /* tp_base */ |
| 663 | 0, /* tp_dict */ |
| 664 | 0, /* tp_descr_get */ |
| 665 | 0, /* tp_descr_set */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 666 | offsetof(AST_object, dict),/* tp_dictoffset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 667 | (initproc)ast_type_init, /* tp_init */ |
| 668 | PyType_GenericAlloc, /* tp_alloc */ |
| 669 | PyType_GenericNew, /* tp_new */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 670 | PyObject_GC_Del, /* tp_free */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 671 | }; |
| 672 | |
| 673 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 674 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 675 | { |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 676 | _Py_IDENTIFIER(__module__); |
| 677 | _Py_IDENTIFIER(_ast); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 678 | PyObject *fnames, *result; |
| 679 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 680 | fnames = PyTuple_New(num_fields); |
| 681 | if (!fnames) return NULL; |
| 682 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 683 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 684 | if (!field) { |
| 685 | Py_DECREF(fnames); |
| 686 | return NULL; |
| 687 | } |
| 688 | PyTuple_SET_ITEM(fnames, i, field); |
| 689 | } |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 690 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}", |
| 691 | type, base, |
| 692 | _PyUnicode_FromId(&PyId__fields), fnames, |
| 693 | _PyUnicode_FromId(&PyId___module__), |
| 694 | _PyUnicode_FromId(&PyId__ast)); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 695 | Py_DECREF(fnames); |
| 696 | return (PyTypeObject*)result; |
| 697 | } |
| 698 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 699 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 700 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 701 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 702 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 703 | if (!l) |
| 704 | return 0; |
| 705 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 706 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 707 | if (!s) { |
| 708 | Py_DECREF(l); |
| 709 | return 0; |
| 710 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 711 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 712 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 713 | result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 714 | Py_DECREF(l); |
| 715 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 718 | /* Conversion AST -> Python */ |
| 719 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 720 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 721 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 722 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 723 | PyObject *result = PyList_New(n); |
| 724 | PyObject *value; |
| 725 | if (!result) |
| 726 | return NULL; |
| 727 | for (i = 0; i < n; i++) { |
| 728 | value = func(asdl_seq_GET(seq, i)); |
| 729 | if (!value) { |
| 730 | Py_DECREF(result); |
| 731 | return NULL; |
| 732 | } |
| 733 | PyList_SET_ITEM(result, i, value); |
| 734 | } |
| 735 | return result; |
| 736 | } |
| 737 | |
| 738 | static PyObject* ast2obj_object(void *o) |
| 739 | { |
| 740 | if (!o) |
| 741 | o = Py_None; |
| 742 | Py_INCREF((PyObject*)o); |
| 743 | return (PyObject*)o; |
| 744 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 745 | #define ast2obj_singleton ast2obj_object |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 746 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 747 | #define ast2obj_identifier ast2obj_object |
| 748 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 749 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 750 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 751 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 752 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 753 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 754 | } |
| 755 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 756 | /* Conversion Python -> AST */ |
| 757 | |
| 758 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 759 | { |
| 760 | if (obj == Py_None) |
| 761 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 762 | if (obj) { |
| 763 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 764 | *out = NULL; |
| 765 | return -1; |
| 766 | } |
| 767 | Py_INCREF(obj); |
| 768 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 769 | *out = obj; |
| 770 | return 0; |
| 771 | } |
| 772 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 773 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 774 | { |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 775 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 776 | *out = NULL; |
| 777 | return -1; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 778 | } |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 779 | Py_INCREF(obj); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 780 | *out = obj; |
| 781 | return 0; |
| 782 | } |
| 783 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 784 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 785 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 786 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 787 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 788 | return 1; |
| 789 | } |
| 790 | return obj2ast_object(obj, out, arena); |
| 791 | } |
| 792 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 793 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 794 | { |
| 795 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
| 796 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 797 | return 1; |
| 798 | } |
| 799 | return obj2ast_object(obj, out, arena); |
| 800 | } |
| 801 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 802 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 803 | { |
| 804 | int i; |
| 805 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 806 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 807 | return 1; |
| 808 | } |
| 809 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 810 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 811 | if (i == -1 && PyErr_Occurred()) |
| 812 | return 1; |
| 813 | *out = i; |
| 814 | return 0; |
| 815 | } |
| 816 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 817 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 818 | { |
| 819 | PyObject *empty_tuple, *d; |
| 820 | if (PyType_Ready(&AST_type) < 0) |
| 821 | return -1; |
| 822 | d = AST_type.tp_dict; |
| 823 | empty_tuple = PyTuple_New(0); |
| 824 | if (!empty_tuple || |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 825 | _PyDict_SetItemId(d, &PyId__fields, empty_tuple) < 0 || |
| 826 | _PyDict_SetItemId(d, &PyId__attributes, empty_tuple) < 0) { |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 827 | Py_XDECREF(empty_tuple); |
| 828 | return -1; |
| 829 | } |
| 830 | Py_DECREF(empty_tuple); |
| 831 | return 0; |
| 832 | } |
| 833 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 834 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 835 | static int init_types(void) |
| 836 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 837 | static int initialized; |
| 838 | if (initialized) return 1; |
| 839 | if (add_ast_fields() < 0) return 0; |
| 840 | mod_type = make_type("mod", &AST_type, NULL, 0); |
| 841 | if (!mod_type) return 0; |
| 842 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 843 | Module_type = make_type("Module", mod_type, Module_fields, 2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 844 | if (!Module_type) return 0; |
| 845 | Interactive_type = make_type("Interactive", mod_type, Interactive_fields, |
| 846 | 1); |
| 847 | if (!Interactive_type) return 0; |
| 848 | Expression_type = make_type("Expression", mod_type, Expression_fields, 1); |
| 849 | if (!Expression_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 850 | FunctionType_type = make_type("FunctionType", mod_type, |
| 851 | FunctionType_fields, 2); |
| 852 | if (!FunctionType_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 853 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
| 854 | if (!Suite_type) return 0; |
| 855 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
| 856 | if (!stmt_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 857 | if (!add_attributes(stmt_type, stmt_attributes, 4)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 858 | FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 859 | 6); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 860 | if (!FunctionDef_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 861 | AsyncFunctionDef_type = make_type("AsyncFunctionDef", stmt_type, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 862 | AsyncFunctionDef_fields, 6); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 863 | if (!AsyncFunctionDef_type) return 0; |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 864 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 5); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 865 | if (!ClassDef_type) return 0; |
| 866 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
| 867 | if (!Return_type) return 0; |
| 868 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
| 869 | if (!Delete_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 870 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 871 | if (!Assign_type) return 0; |
| 872 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
| 873 | if (!AugAssign_type) return 0; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 874 | AnnAssign_type = make_type("AnnAssign", stmt_type, AnnAssign_fields, 4); |
| 875 | if (!AnnAssign_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 876 | For_type = make_type("For", stmt_type, For_fields, 5); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 877 | if (!For_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 878 | AsyncFor_type = make_type("AsyncFor", stmt_type, AsyncFor_fields, 5); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 879 | if (!AsyncFor_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 880 | While_type = make_type("While", stmt_type, While_fields, 3); |
| 881 | if (!While_type) return 0; |
| 882 | If_type = make_type("If", stmt_type, If_fields, 3); |
| 883 | if (!If_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 884 | With_type = make_type("With", stmt_type, With_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 885 | if (!With_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 886 | AsyncWith_type = make_type("AsyncWith", stmt_type, AsyncWith_fields, 3); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 887 | if (!AsyncWith_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 888 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
| 889 | if (!Raise_type) return 0; |
| 890 | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
| 891 | if (!Try_type) return 0; |
| 892 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
| 893 | if (!Assert_type) return 0; |
| 894 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
| 895 | if (!Import_type) return 0; |
| 896 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, 3); |
| 897 | if (!ImportFrom_type) return 0; |
| 898 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
| 899 | if (!Global_type) return 0; |
| 900 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 901 | if (!Nonlocal_type) return 0; |
| 902 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
| 903 | if (!Expr_type) return 0; |
| 904 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
| 905 | if (!Pass_type) return 0; |
| 906 | Break_type = make_type("Break", stmt_type, NULL, 0); |
| 907 | if (!Break_type) return 0; |
| 908 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
| 909 | if (!Continue_type) return 0; |
| 910 | expr_type = make_type("expr", &AST_type, NULL, 0); |
| 911 | if (!expr_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 912 | if (!add_attributes(expr_type, expr_attributes, 4)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 913 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
| 914 | if (!BoolOp_type) return 0; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 915 | NamedExpr_type = make_type("NamedExpr", expr_type, NamedExpr_fields, 2); |
| 916 | if (!NamedExpr_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 917 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
| 918 | if (!BinOp_type) return 0; |
| 919 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
| 920 | if (!UnaryOp_type) return 0; |
| 921 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
| 922 | if (!Lambda_type) return 0; |
| 923 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
| 924 | if (!IfExp_type) return 0; |
| 925 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
| 926 | if (!Dict_type) return 0; |
| 927 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 928 | if (!Set_type) return 0; |
| 929 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
| 930 | if (!ListComp_type) return 0; |
| 931 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 932 | if (!SetComp_type) return 0; |
| 933 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 934 | if (!DictComp_type) return 0; |
| 935 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 936 | GeneratorExp_fields, 2); |
| 937 | if (!GeneratorExp_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 938 | Await_type = make_type("Await", expr_type, Await_fields, 1); |
| 939 | if (!Await_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 940 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
| 941 | if (!Yield_type) return 0; |
| 942 | YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); |
| 943 | if (!YieldFrom_type) return 0; |
| 944 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
| 945 | if (!Compare_type) return 0; |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 946 | Call_type = make_type("Call", expr_type, Call_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 947 | if (!Call_type) return 0; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 948 | FormattedValue_type = make_type("FormattedValue", expr_type, |
| 949 | FormattedValue_fields, 3); |
| 950 | if (!FormattedValue_type) return 0; |
| 951 | JoinedStr_type = make_type("JoinedStr", expr_type, JoinedStr_fields, 1); |
| 952 | if (!JoinedStr_type) return 0; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 953 | Constant_type = make_type("Constant", expr_type, Constant_fields, 1); |
| 954 | if (!Constant_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 955 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
| 956 | if (!Attribute_type) return 0; |
| 957 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
| 958 | if (!Subscript_type) return 0; |
| 959 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 960 | if (!Starred_type) return 0; |
| 961 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
| 962 | if (!Name_type) return 0; |
| 963 | List_type = make_type("List", expr_type, List_fields, 2); |
| 964 | if (!List_type) return 0; |
| 965 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
| 966 | if (!Tuple_type) return 0; |
| 967 | expr_context_type = make_type("expr_context", &AST_type, NULL, 0); |
| 968 | if (!expr_context_type) return 0; |
| 969 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
| 970 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
| 971 | if (!Load_type) return 0; |
| 972 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
| 973 | if (!Load_singleton) return 0; |
| 974 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
| 975 | if (!Store_type) return 0; |
| 976 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
| 977 | if (!Store_singleton) return 0; |
| 978 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
| 979 | if (!Del_type) return 0; |
| 980 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
| 981 | if (!Del_singleton) return 0; |
| 982 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
| 983 | if (!AugLoad_type) return 0; |
| 984 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
| 985 | if (!AugLoad_singleton) return 0; |
| 986 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
| 987 | if (!AugStore_type) return 0; |
| 988 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
| 989 | if (!AugStore_singleton) return 0; |
| 990 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
| 991 | if (!Param_type) return 0; |
| 992 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
| 993 | if (!Param_singleton) return 0; |
| 994 | slice_type = make_type("slice", &AST_type, NULL, 0); |
| 995 | if (!slice_type) return 0; |
| 996 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
| 997 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
| 998 | if (!Slice_type) return 0; |
| 999 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
| 1000 | if (!ExtSlice_type) return 0; |
| 1001 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
| 1002 | if (!Index_type) return 0; |
| 1003 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
| 1004 | if (!boolop_type) return 0; |
| 1005 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
| 1006 | And_type = make_type("And", boolop_type, NULL, 0); |
| 1007 | if (!And_type) return 0; |
| 1008 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
| 1009 | if (!And_singleton) return 0; |
| 1010 | Or_type = make_type("Or", boolop_type, NULL, 0); |
| 1011 | if (!Or_type) return 0; |
| 1012 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
| 1013 | if (!Or_singleton) return 0; |
| 1014 | operator_type = make_type("operator", &AST_type, NULL, 0); |
| 1015 | if (!operator_type) return 0; |
| 1016 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
| 1017 | Add_type = make_type("Add", operator_type, NULL, 0); |
| 1018 | if (!Add_type) return 0; |
| 1019 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
| 1020 | if (!Add_singleton) return 0; |
| 1021 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
| 1022 | if (!Sub_type) return 0; |
| 1023 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
| 1024 | if (!Sub_singleton) return 0; |
| 1025 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
| 1026 | if (!Mult_type) return 0; |
| 1027 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
| 1028 | if (!Mult_singleton) return 0; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 1029 | MatMult_type = make_type("MatMult", operator_type, NULL, 0); |
| 1030 | if (!MatMult_type) return 0; |
| 1031 | MatMult_singleton = PyType_GenericNew(MatMult_type, NULL, NULL); |
| 1032 | if (!MatMult_singleton) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1033 | Div_type = make_type("Div", operator_type, NULL, 0); |
| 1034 | if (!Div_type) return 0; |
| 1035 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
| 1036 | if (!Div_singleton) return 0; |
| 1037 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
| 1038 | if (!Mod_type) return 0; |
| 1039 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
| 1040 | if (!Mod_singleton) return 0; |
| 1041 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
| 1042 | if (!Pow_type) return 0; |
| 1043 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
| 1044 | if (!Pow_singleton) return 0; |
| 1045 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
| 1046 | if (!LShift_type) return 0; |
| 1047 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
| 1048 | if (!LShift_singleton) return 0; |
| 1049 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
| 1050 | if (!RShift_type) return 0; |
| 1051 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
| 1052 | if (!RShift_singleton) return 0; |
| 1053 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
| 1054 | if (!BitOr_type) return 0; |
| 1055 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
| 1056 | if (!BitOr_singleton) return 0; |
| 1057 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
| 1058 | if (!BitXor_type) return 0; |
| 1059 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
| 1060 | if (!BitXor_singleton) return 0; |
| 1061 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
| 1062 | if (!BitAnd_type) return 0; |
| 1063 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
| 1064 | if (!BitAnd_singleton) return 0; |
| 1065 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
| 1066 | if (!FloorDiv_type) return 0; |
| 1067 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
| 1068 | if (!FloorDiv_singleton) return 0; |
| 1069 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
| 1070 | if (!unaryop_type) return 0; |
| 1071 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
| 1072 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
| 1073 | if (!Invert_type) return 0; |
| 1074 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
| 1075 | if (!Invert_singleton) return 0; |
| 1076 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
| 1077 | if (!Not_type) return 0; |
| 1078 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
| 1079 | if (!Not_singleton) return 0; |
| 1080 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
| 1081 | if (!UAdd_type) return 0; |
| 1082 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
| 1083 | if (!UAdd_singleton) return 0; |
| 1084 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
| 1085 | if (!USub_type) return 0; |
| 1086 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
| 1087 | if (!USub_singleton) return 0; |
| 1088 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
| 1089 | if (!cmpop_type) return 0; |
| 1090 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
| 1091 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
| 1092 | if (!Eq_type) return 0; |
| 1093 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
| 1094 | if (!Eq_singleton) return 0; |
| 1095 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
| 1096 | if (!NotEq_type) return 0; |
| 1097 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
| 1098 | if (!NotEq_singleton) return 0; |
| 1099 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
| 1100 | if (!Lt_type) return 0; |
| 1101 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
| 1102 | if (!Lt_singleton) return 0; |
| 1103 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
| 1104 | if (!LtE_type) return 0; |
| 1105 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
| 1106 | if (!LtE_singleton) return 0; |
| 1107 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
| 1108 | if (!Gt_type) return 0; |
| 1109 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
| 1110 | if (!Gt_singleton) return 0; |
| 1111 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
| 1112 | if (!GtE_type) return 0; |
| 1113 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
| 1114 | if (!GtE_singleton) return 0; |
| 1115 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
| 1116 | if (!Is_type) return 0; |
| 1117 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
| 1118 | if (!Is_singleton) return 0; |
| 1119 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
| 1120 | if (!IsNot_type) return 0; |
| 1121 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
| 1122 | if (!IsNot_singleton) return 0; |
| 1123 | In_type = make_type("In", cmpop_type, NULL, 0); |
| 1124 | if (!In_type) return 0; |
| 1125 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
| 1126 | if (!In_singleton) return 0; |
| 1127 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
| 1128 | if (!NotIn_type) return 0; |
| 1129 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
| 1130 | if (!NotIn_singleton) return 0; |
| 1131 | comprehension_type = make_type("comprehension", &AST_type, |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 1132 | comprehension_fields, 4); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1133 | if (!comprehension_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1134 | if (!add_attributes(comprehension_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1135 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
| 1136 | if (!excepthandler_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1137 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 4)) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1138 | return 0; |
| 1139 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 1140 | ExceptHandler_fields, 3); |
| 1141 | if (!ExceptHandler_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1142 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 6); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1143 | if (!arguments_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1144 | if (!add_attributes(arguments_type, NULL, 0)) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1145 | arg_type = make_type("arg", &AST_type, arg_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1146 | if (!arg_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1147 | if (!add_attributes(arg_type, arg_attributes, 4)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1148 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
| 1149 | if (!keyword_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1150 | if (!add_attributes(keyword_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1151 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
| 1152 | if (!alias_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1153 | if (!add_attributes(alias_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1154 | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
| 1155 | if (!withitem_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1156 | if (!add_attributes(withitem_type, NULL, 0)) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1157 | type_ignore_type = make_type("type_ignore", &AST_type, NULL, 0); |
| 1158 | if (!type_ignore_type) return 0; |
| 1159 | if (!add_attributes(type_ignore_type, NULL, 0)) return 0; |
| 1160 | TypeIgnore_type = make_type("TypeIgnore", type_ignore_type, |
| 1161 | TypeIgnore_fields, 1); |
| 1162 | if (!TypeIgnore_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1163 | initialized = 1; |
| 1164 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1165 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1166 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1167 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1168 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1169 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1170 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1171 | arena); |
| 1172 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1173 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1174 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1175 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1176 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1177 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1178 | arena); |
| 1179 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1180 | arena); |
| 1181 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1182 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1183 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1184 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1185 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1186 | static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* |
| 1187 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1188 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1189 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1190 | Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1191 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1192 | mod_ty p; |
| 1193 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1194 | if (!p) |
| 1195 | return NULL; |
| 1196 | p->kind = Module_kind; |
| 1197 | p->v.Module.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1198 | p->v.Module.type_ignores = type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1199 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1203 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1204 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1205 | mod_ty p; |
| 1206 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1207 | if (!p) |
| 1208 | return NULL; |
| 1209 | p->kind = Interactive_kind; |
| 1210 | p->v.Interactive.body = body; |
| 1211 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1215 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1216 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1217 | mod_ty p; |
| 1218 | if (!body) { |
| 1219 | PyErr_SetString(PyExc_ValueError, |
| 1220 | "field body is required for Expression"); |
| 1221 | return NULL; |
| 1222 | } |
| 1223 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1224 | if (!p) |
| 1225 | return NULL; |
| 1226 | p->kind = Expression_kind; |
| 1227 | p->v.Expression.body = body; |
| 1228 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1232 | FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena) |
| 1233 | { |
| 1234 | mod_ty p; |
| 1235 | if (!returns) { |
| 1236 | PyErr_SetString(PyExc_ValueError, |
| 1237 | "field returns is required for FunctionType"); |
| 1238 | return NULL; |
| 1239 | } |
| 1240 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1241 | if (!p) |
| 1242 | return NULL; |
| 1243 | p->kind = FunctionType_kind; |
| 1244 | p->v.FunctionType.argtypes = argtypes; |
| 1245 | p->v.FunctionType.returns = returns; |
| 1246 | return p; |
| 1247 | } |
| 1248 | |
| 1249 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1250 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1251 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1252 | mod_ty p; |
| 1253 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1254 | if (!p) |
| 1255 | return NULL; |
| 1256 | p->kind = Suite_kind; |
| 1257 | p->v.Suite.body = body; |
| 1258 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | stmt_ty |
| 1262 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1263 | decorator_list, expr_ty returns, string type_comment, int lineno, |
| 1264 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1265 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1266 | stmt_ty p; |
| 1267 | if (!name) { |
| 1268 | PyErr_SetString(PyExc_ValueError, |
| 1269 | "field name is required for FunctionDef"); |
| 1270 | return NULL; |
| 1271 | } |
| 1272 | if (!args) { |
| 1273 | PyErr_SetString(PyExc_ValueError, |
| 1274 | "field args is required for FunctionDef"); |
| 1275 | return NULL; |
| 1276 | } |
| 1277 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1278 | if (!p) |
| 1279 | return NULL; |
| 1280 | p->kind = FunctionDef_kind; |
| 1281 | p->v.FunctionDef.name = name; |
| 1282 | p->v.FunctionDef.args = args; |
| 1283 | p->v.FunctionDef.body = body; |
| 1284 | p->v.FunctionDef.decorator_list = decorator_list; |
| 1285 | p->v.FunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1286 | p->v.FunctionDef.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1287 | p->lineno = lineno; |
| 1288 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1289 | p->end_lineno = end_lineno; |
| 1290 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1291 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1295 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1296 | * decorator_list, expr_ty returns, string type_comment, int |
| 1297 | lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1298 | PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1299 | { |
| 1300 | stmt_ty p; |
| 1301 | if (!name) { |
| 1302 | PyErr_SetString(PyExc_ValueError, |
| 1303 | "field name is required for AsyncFunctionDef"); |
| 1304 | return NULL; |
| 1305 | } |
| 1306 | if (!args) { |
| 1307 | PyErr_SetString(PyExc_ValueError, |
| 1308 | "field args is required for AsyncFunctionDef"); |
| 1309 | return NULL; |
| 1310 | } |
| 1311 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1312 | if (!p) |
| 1313 | return NULL; |
| 1314 | p->kind = AsyncFunctionDef_kind; |
| 1315 | p->v.AsyncFunctionDef.name = name; |
| 1316 | p->v.AsyncFunctionDef.args = args; |
| 1317 | p->v.AsyncFunctionDef.body = body; |
| 1318 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 1319 | p->v.AsyncFunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1320 | p->v.AsyncFunctionDef.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1321 | p->lineno = lineno; |
| 1322 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1323 | p->end_lineno = end_lineno; |
| 1324 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1325 | return p; |
| 1326 | } |
| 1327 | |
| 1328 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 1329 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1330 | body, asdl_seq * decorator_list, int lineno, int col_offset, int |
| 1331 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1332 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1333 | stmt_ty p; |
| 1334 | if (!name) { |
| 1335 | PyErr_SetString(PyExc_ValueError, |
| 1336 | "field name is required for ClassDef"); |
| 1337 | return NULL; |
| 1338 | } |
| 1339 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1340 | if (!p) |
| 1341 | return NULL; |
| 1342 | p->kind = ClassDef_kind; |
| 1343 | p->v.ClassDef.name = name; |
| 1344 | p->v.ClassDef.bases = bases; |
| 1345 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1346 | p->v.ClassDef.body = body; |
| 1347 | p->v.ClassDef.decorator_list = decorator_list; |
| 1348 | p->lineno = lineno; |
| 1349 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1350 | p->end_lineno = end_lineno; |
| 1351 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1352 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1356 | Return(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 1357 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1358 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1359 | stmt_ty p; |
| 1360 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1361 | if (!p) |
| 1362 | return NULL; |
| 1363 | p->kind = Return_kind; |
| 1364 | p->v.Return.value = value; |
| 1365 | p->lineno = lineno; |
| 1366 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1367 | p->end_lineno = end_lineno; |
| 1368 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1369 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1373 | Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int |
| 1374 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1375 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1376 | stmt_ty p; |
| 1377 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1378 | if (!p) |
| 1379 | return NULL; |
| 1380 | p->kind = Delete_kind; |
| 1381 | p->v.Delete.targets = targets; |
| 1382 | p->lineno = lineno; |
| 1383 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1384 | p->end_lineno = end_lineno; |
| 1385 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1386 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1390 | Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int |
| 1391 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1392 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1393 | stmt_ty p; |
| 1394 | if (!value) { |
| 1395 | PyErr_SetString(PyExc_ValueError, |
| 1396 | "field value is required for Assign"); |
| 1397 | return NULL; |
| 1398 | } |
| 1399 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1400 | if (!p) |
| 1401 | return NULL; |
| 1402 | p->kind = Assign_kind; |
| 1403 | p->v.Assign.targets = targets; |
| 1404 | p->v.Assign.value = value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1405 | p->v.Assign.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1406 | p->lineno = lineno; |
| 1407 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1408 | p->end_lineno = end_lineno; |
| 1409 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1410 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1414 | 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] | 1415 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1416 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1417 | stmt_ty p; |
| 1418 | if (!target) { |
| 1419 | PyErr_SetString(PyExc_ValueError, |
| 1420 | "field target is required for AugAssign"); |
| 1421 | return NULL; |
| 1422 | } |
| 1423 | if (!op) { |
| 1424 | PyErr_SetString(PyExc_ValueError, |
| 1425 | "field op is required for AugAssign"); |
| 1426 | return NULL; |
| 1427 | } |
| 1428 | if (!value) { |
| 1429 | PyErr_SetString(PyExc_ValueError, |
| 1430 | "field value is required for AugAssign"); |
| 1431 | return NULL; |
| 1432 | } |
| 1433 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1434 | if (!p) |
| 1435 | return NULL; |
| 1436 | p->kind = AugAssign_kind; |
| 1437 | p->v.AugAssign.target = target; |
| 1438 | p->v.AugAssign.op = op; |
| 1439 | p->v.AugAssign.value = value; |
| 1440 | p->lineno = lineno; |
| 1441 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1442 | p->end_lineno = end_lineno; |
| 1443 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1444 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 1448 | 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] | 1449 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1450 | *arena) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 1451 | { |
| 1452 | stmt_ty p; |
| 1453 | if (!target) { |
| 1454 | PyErr_SetString(PyExc_ValueError, |
| 1455 | "field target is required for AnnAssign"); |
| 1456 | return NULL; |
| 1457 | } |
| 1458 | if (!annotation) { |
| 1459 | PyErr_SetString(PyExc_ValueError, |
| 1460 | "field annotation is required for AnnAssign"); |
| 1461 | return NULL; |
| 1462 | } |
| 1463 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1464 | if (!p) |
| 1465 | return NULL; |
| 1466 | p->kind = AnnAssign_kind; |
| 1467 | p->v.AnnAssign.target = target; |
| 1468 | p->v.AnnAssign.annotation = annotation; |
| 1469 | p->v.AnnAssign.value = value; |
| 1470 | p->v.AnnAssign.simple = simple; |
| 1471 | p->lineno = lineno; |
| 1472 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1473 | p->end_lineno = end_lineno; |
| 1474 | p->end_col_offset = end_col_offset; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 1475 | return p; |
| 1476 | } |
| 1477 | |
| 1478 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1479 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string |
| 1480 | type_comment, int lineno, int col_offset, int end_lineno, int |
| 1481 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1482 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1483 | stmt_ty p; |
| 1484 | if (!target) { |
| 1485 | PyErr_SetString(PyExc_ValueError, |
| 1486 | "field target is required for For"); |
| 1487 | return NULL; |
| 1488 | } |
| 1489 | if (!iter) { |
| 1490 | PyErr_SetString(PyExc_ValueError, |
| 1491 | "field iter is required for For"); |
| 1492 | return NULL; |
| 1493 | } |
| 1494 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1495 | if (!p) |
| 1496 | return NULL; |
| 1497 | p->kind = For_kind; |
| 1498 | p->v.For.target = target; |
| 1499 | p->v.For.iter = iter; |
| 1500 | p->v.For.body = body; |
| 1501 | p->v.For.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1502 | p->v.For.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1503 | p->lineno = lineno; |
| 1504 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1505 | p->end_lineno = end_lineno; |
| 1506 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1507 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1511 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, |
| 1512 | string type_comment, int lineno, int col_offset, int end_lineno, int |
| 1513 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1514 | { |
| 1515 | stmt_ty p; |
| 1516 | if (!target) { |
| 1517 | PyErr_SetString(PyExc_ValueError, |
| 1518 | "field target is required for AsyncFor"); |
| 1519 | return NULL; |
| 1520 | } |
| 1521 | if (!iter) { |
| 1522 | PyErr_SetString(PyExc_ValueError, |
| 1523 | "field iter is required for AsyncFor"); |
| 1524 | return NULL; |
| 1525 | } |
| 1526 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1527 | if (!p) |
| 1528 | return NULL; |
| 1529 | p->kind = AsyncFor_kind; |
| 1530 | p->v.AsyncFor.target = target; |
| 1531 | p->v.AsyncFor.iter = iter; |
| 1532 | p->v.AsyncFor.body = body; |
| 1533 | p->v.AsyncFor.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1534 | p->v.AsyncFor.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1535 | p->lineno = lineno; |
| 1536 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1537 | p->end_lineno = end_lineno; |
| 1538 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1539 | return p; |
| 1540 | } |
| 1541 | |
| 1542 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1543 | 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] | 1544 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1545 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1546 | stmt_ty p; |
| 1547 | if (!test) { |
| 1548 | PyErr_SetString(PyExc_ValueError, |
| 1549 | "field test is required for While"); |
| 1550 | return NULL; |
| 1551 | } |
| 1552 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1553 | if (!p) |
| 1554 | return NULL; |
| 1555 | p->kind = While_kind; |
| 1556 | p->v.While.test = test; |
| 1557 | p->v.While.body = body; |
| 1558 | p->v.While.orelse = orelse; |
| 1559 | p->lineno = lineno; |
| 1560 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1561 | p->end_lineno = end_lineno; |
| 1562 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1563 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1567 | 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] | 1568 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1569 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1570 | stmt_ty p; |
| 1571 | if (!test) { |
| 1572 | PyErr_SetString(PyExc_ValueError, |
| 1573 | "field test is required for If"); |
| 1574 | return NULL; |
| 1575 | } |
| 1576 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1577 | if (!p) |
| 1578 | return NULL; |
| 1579 | p->kind = If_kind; |
| 1580 | p->v.If.test = test; |
| 1581 | p->v.If.body = body; |
| 1582 | p->v.If.orelse = orelse; |
| 1583 | p->lineno = lineno; |
| 1584 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1585 | p->end_lineno = end_lineno; |
| 1586 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1587 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1591 | With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int |
| 1592 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1593 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1594 | stmt_ty p; |
| 1595 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1596 | if (!p) |
| 1597 | return NULL; |
| 1598 | p->kind = With_kind; |
| 1599 | p->v.With.items = items; |
| 1600 | p->v.With.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1601 | p->v.With.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1602 | p->lineno = lineno; |
| 1603 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1604 | p->end_lineno = end_lineno; |
| 1605 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1606 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1610 | AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, |
| 1611 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1612 | { |
| 1613 | stmt_ty p; |
| 1614 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1615 | if (!p) |
| 1616 | return NULL; |
| 1617 | p->kind = AsyncWith_kind; |
| 1618 | p->v.AsyncWith.items = items; |
| 1619 | p->v.AsyncWith.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1620 | p->v.AsyncWith.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1621 | p->lineno = lineno; |
| 1622 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1623 | p->end_lineno = end_lineno; |
| 1624 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1625 | return p; |
| 1626 | } |
| 1627 | |
| 1628 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1629 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, |
| 1630 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1631 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1632 | stmt_ty p; |
| 1633 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1634 | if (!p) |
| 1635 | return NULL; |
| 1636 | p->kind = Raise_kind; |
| 1637 | p->v.Raise.exc = exc; |
| 1638 | p->v.Raise.cause = cause; |
| 1639 | p->lineno = lineno; |
| 1640 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1641 | p->end_lineno = end_lineno; |
| 1642 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1643 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1647 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1648 | finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1649 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1650 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1651 | stmt_ty p; |
| 1652 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1653 | if (!p) |
| 1654 | return NULL; |
| 1655 | p->kind = Try_kind; |
| 1656 | p->v.Try.body = body; |
| 1657 | p->v.Try.handlers = handlers; |
| 1658 | p->v.Try.orelse = orelse; |
| 1659 | p->v.Try.finalbody = finalbody; |
| 1660 | p->lineno = lineno; |
| 1661 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1662 | p->end_lineno = end_lineno; |
| 1663 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1664 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1668 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, |
| 1669 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1670 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1671 | stmt_ty p; |
| 1672 | if (!test) { |
| 1673 | PyErr_SetString(PyExc_ValueError, |
| 1674 | "field test is required for Assert"); |
| 1675 | return NULL; |
| 1676 | } |
| 1677 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1678 | if (!p) |
| 1679 | return NULL; |
| 1680 | p->kind = Assert_kind; |
| 1681 | p->v.Assert.test = test; |
| 1682 | p->v.Assert.msg = msg; |
| 1683 | p->lineno = lineno; |
| 1684 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1685 | p->end_lineno = end_lineno; |
| 1686 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1687 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1691 | Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 1692 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1693 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1694 | stmt_ty p; |
| 1695 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1696 | if (!p) |
| 1697 | return NULL; |
| 1698 | p->kind = Import_kind; |
| 1699 | p->v.Import.names = names; |
| 1700 | p->lineno = lineno; |
| 1701 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1702 | p->end_lineno = end_lineno; |
| 1703 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1704 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1708 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1709 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1710 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1711 | stmt_ty p; |
| 1712 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1713 | if (!p) |
| 1714 | return NULL; |
| 1715 | p->kind = ImportFrom_kind; |
| 1716 | p->v.ImportFrom.module = module; |
| 1717 | p->v.ImportFrom.names = names; |
| 1718 | p->v.ImportFrom.level = level; |
| 1719 | p->lineno = lineno; |
| 1720 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1721 | p->end_lineno = end_lineno; |
| 1722 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1723 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1727 | Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 1728 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1729 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1730 | stmt_ty p; |
| 1731 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1732 | if (!p) |
| 1733 | return NULL; |
| 1734 | p->kind = Global_kind; |
| 1735 | p->v.Global.names = names; |
| 1736 | p->lineno = lineno; |
| 1737 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1738 | p->end_lineno = end_lineno; |
| 1739 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1740 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1744 | Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 1745 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1746 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1747 | stmt_ty p; |
| 1748 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1749 | if (!p) |
| 1750 | return NULL; |
| 1751 | p->kind = Nonlocal_kind; |
| 1752 | p->v.Nonlocal.names = names; |
| 1753 | p->lineno = lineno; |
| 1754 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1755 | p->end_lineno = end_lineno; |
| 1756 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1757 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1761 | Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 1762 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1763 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1764 | stmt_ty p; |
| 1765 | if (!value) { |
| 1766 | PyErr_SetString(PyExc_ValueError, |
| 1767 | "field value is required for Expr"); |
| 1768 | return NULL; |
| 1769 | } |
| 1770 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1771 | if (!p) |
| 1772 | return NULL; |
| 1773 | p->kind = Expr_kind; |
| 1774 | p->v.Expr.value = value; |
| 1775 | p->lineno = lineno; |
| 1776 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1777 | p->end_lineno = end_lineno; |
| 1778 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1779 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1783 | Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1784 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1785 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1786 | stmt_ty p; |
| 1787 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1788 | if (!p) |
| 1789 | return NULL; |
| 1790 | p->kind = Pass_kind; |
| 1791 | p->lineno = lineno; |
| 1792 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1793 | p->end_lineno = end_lineno; |
| 1794 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1795 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1799 | Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1800 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1801 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1802 | stmt_ty p; |
| 1803 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1804 | if (!p) |
| 1805 | return NULL; |
| 1806 | p->kind = Break_kind; |
| 1807 | p->lineno = lineno; |
| 1808 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1809 | p->end_lineno = end_lineno; |
| 1810 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1811 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1815 | Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1816 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1817 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1818 | stmt_ty p; |
| 1819 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1820 | if (!p) |
| 1821 | return NULL; |
| 1822 | p->kind = Continue_kind; |
| 1823 | p->lineno = lineno; |
| 1824 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1825 | p->end_lineno = end_lineno; |
| 1826 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1827 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1831 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int |
| 1832 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1833 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1834 | expr_ty p; |
| 1835 | if (!op) { |
| 1836 | PyErr_SetString(PyExc_ValueError, |
| 1837 | "field op is required for BoolOp"); |
| 1838 | return NULL; |
| 1839 | } |
| 1840 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1841 | if (!p) |
| 1842 | return NULL; |
| 1843 | p->kind = BoolOp_kind; |
| 1844 | p->v.BoolOp.op = op; |
| 1845 | p->v.BoolOp.values = values; |
| 1846 | p->lineno = lineno; |
| 1847 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1848 | p->end_lineno = end_lineno; |
| 1849 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1850 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | expr_ty |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 1854 | NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int |
| 1855 | end_lineno, int end_col_offset, PyArena *arena) |
| 1856 | { |
| 1857 | expr_ty p; |
| 1858 | if (!target) { |
| 1859 | PyErr_SetString(PyExc_ValueError, |
| 1860 | "field target is required for NamedExpr"); |
| 1861 | return NULL; |
| 1862 | } |
| 1863 | if (!value) { |
| 1864 | PyErr_SetString(PyExc_ValueError, |
| 1865 | "field value is required for NamedExpr"); |
| 1866 | return NULL; |
| 1867 | } |
| 1868 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1869 | if (!p) |
| 1870 | return NULL; |
| 1871 | p->kind = NamedExpr_kind; |
| 1872 | p->v.NamedExpr.target = target; |
| 1873 | p->v.NamedExpr.value = value; |
| 1874 | p->lineno = lineno; |
| 1875 | p->col_offset = col_offset; |
| 1876 | p->end_lineno = end_lineno; |
| 1877 | p->end_col_offset = end_col_offset; |
| 1878 | return p; |
| 1879 | } |
| 1880 | |
| 1881 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1882 | 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] | 1883 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1884 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1885 | expr_ty p; |
| 1886 | if (!left) { |
| 1887 | PyErr_SetString(PyExc_ValueError, |
| 1888 | "field left is required for BinOp"); |
| 1889 | return NULL; |
| 1890 | } |
| 1891 | if (!op) { |
| 1892 | PyErr_SetString(PyExc_ValueError, |
| 1893 | "field op is required for BinOp"); |
| 1894 | return NULL; |
| 1895 | } |
| 1896 | if (!right) { |
| 1897 | PyErr_SetString(PyExc_ValueError, |
| 1898 | "field right is required for BinOp"); |
| 1899 | return NULL; |
| 1900 | } |
| 1901 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1902 | if (!p) |
| 1903 | return NULL; |
| 1904 | p->kind = BinOp_kind; |
| 1905 | p->v.BinOp.left = left; |
| 1906 | p->v.BinOp.op = op; |
| 1907 | p->v.BinOp.right = right; |
| 1908 | p->lineno = lineno; |
| 1909 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1910 | p->end_lineno = end_lineno; |
| 1911 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1912 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1916 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int |
| 1917 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1918 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1919 | expr_ty p; |
| 1920 | if (!op) { |
| 1921 | PyErr_SetString(PyExc_ValueError, |
| 1922 | "field op is required for UnaryOp"); |
| 1923 | return NULL; |
| 1924 | } |
| 1925 | if (!operand) { |
| 1926 | PyErr_SetString(PyExc_ValueError, |
| 1927 | "field operand is required for UnaryOp"); |
| 1928 | return NULL; |
| 1929 | } |
| 1930 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1931 | if (!p) |
| 1932 | return NULL; |
| 1933 | p->kind = UnaryOp_kind; |
| 1934 | p->v.UnaryOp.op = op; |
| 1935 | p->v.UnaryOp.operand = operand; |
| 1936 | p->lineno = lineno; |
| 1937 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1938 | p->end_lineno = end_lineno; |
| 1939 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1940 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1944 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int |
| 1945 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1946 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1947 | expr_ty p; |
| 1948 | if (!args) { |
| 1949 | PyErr_SetString(PyExc_ValueError, |
| 1950 | "field args is required for Lambda"); |
| 1951 | return NULL; |
| 1952 | } |
| 1953 | if (!body) { |
| 1954 | PyErr_SetString(PyExc_ValueError, |
| 1955 | "field body is required for Lambda"); |
| 1956 | return NULL; |
| 1957 | } |
| 1958 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1959 | if (!p) |
| 1960 | return NULL; |
| 1961 | p->kind = Lambda_kind; |
| 1962 | p->v.Lambda.args = args; |
| 1963 | p->v.Lambda.body = body; |
| 1964 | p->lineno = lineno; |
| 1965 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1966 | p->end_lineno = end_lineno; |
| 1967 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1968 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1972 | 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] | 1973 | int end_lineno, int end_col_offset, PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1974 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1975 | expr_ty p; |
| 1976 | if (!test) { |
| 1977 | PyErr_SetString(PyExc_ValueError, |
| 1978 | "field test is required for IfExp"); |
| 1979 | return NULL; |
| 1980 | } |
| 1981 | if (!body) { |
| 1982 | PyErr_SetString(PyExc_ValueError, |
| 1983 | "field body is required for IfExp"); |
| 1984 | return NULL; |
| 1985 | } |
| 1986 | if (!orelse) { |
| 1987 | PyErr_SetString(PyExc_ValueError, |
| 1988 | "field orelse is required for IfExp"); |
| 1989 | return NULL; |
| 1990 | } |
| 1991 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1992 | if (!p) |
| 1993 | return NULL; |
| 1994 | p->kind = IfExp_kind; |
| 1995 | p->v.IfExp.test = test; |
| 1996 | p->v.IfExp.body = body; |
| 1997 | p->v.IfExp.orelse = orelse; |
| 1998 | p->lineno = lineno; |
| 1999 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2000 | p->end_lineno = end_lineno; |
| 2001 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2002 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2006 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int |
| 2007 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2008 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2009 | expr_ty p; |
| 2010 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2011 | if (!p) |
| 2012 | return NULL; |
| 2013 | p->kind = Dict_kind; |
| 2014 | p->v.Dict.keys = keys; |
| 2015 | p->v.Dict.values = values; |
| 2016 | p->lineno = lineno; |
| 2017 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2018 | p->end_lineno = end_lineno; |
| 2019 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2020 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2024 | Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int |
| 2025 | end_col_offset, PyArena *arena) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2026 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2027 | expr_ty p; |
| 2028 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2029 | if (!p) |
| 2030 | return NULL; |
| 2031 | p->kind = Set_kind; |
| 2032 | p->v.Set.elts = elts; |
| 2033 | p->lineno = lineno; |
| 2034 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2035 | p->end_lineno = end_lineno; |
| 2036 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2037 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2041 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2042 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2043 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2044 | expr_ty p; |
| 2045 | if (!elt) { |
| 2046 | PyErr_SetString(PyExc_ValueError, |
| 2047 | "field elt is required for ListComp"); |
| 2048 | return NULL; |
| 2049 | } |
| 2050 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2051 | if (!p) |
| 2052 | return NULL; |
| 2053 | p->kind = ListComp_kind; |
| 2054 | p->v.ListComp.elt = elt; |
| 2055 | p->v.ListComp.generators = generators; |
| 2056 | p->lineno = lineno; |
| 2057 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2058 | p->end_lineno = end_lineno; |
| 2059 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2060 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2064 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2065 | end_lineno, int end_col_offset, PyArena *arena) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2066 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2067 | expr_ty p; |
| 2068 | if (!elt) { |
| 2069 | PyErr_SetString(PyExc_ValueError, |
| 2070 | "field elt is required for SetComp"); |
| 2071 | return NULL; |
| 2072 | } |
| 2073 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2074 | if (!p) |
| 2075 | return NULL; |
| 2076 | p->kind = SetComp_kind; |
| 2077 | p->v.SetComp.elt = elt; |
| 2078 | p->v.SetComp.generators = generators; |
| 2079 | p->lineno = lineno; |
| 2080 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2081 | p->end_lineno = end_lineno; |
| 2082 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2083 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2087 | 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] | 2088 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2089 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2090 | expr_ty p; |
| 2091 | if (!key) { |
| 2092 | PyErr_SetString(PyExc_ValueError, |
| 2093 | "field key is required for DictComp"); |
| 2094 | return NULL; |
| 2095 | } |
| 2096 | if (!value) { |
| 2097 | PyErr_SetString(PyExc_ValueError, |
| 2098 | "field value is required for DictComp"); |
| 2099 | return NULL; |
| 2100 | } |
| 2101 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2102 | if (!p) |
| 2103 | return NULL; |
| 2104 | p->kind = DictComp_kind; |
| 2105 | p->v.DictComp.key = key; |
| 2106 | p->v.DictComp.value = value; |
| 2107 | p->v.DictComp.generators = generators; |
| 2108 | p->lineno = lineno; |
| 2109 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2110 | p->end_lineno = end_lineno; |
| 2111 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2112 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2116 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2117 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2118 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2119 | expr_ty p; |
| 2120 | if (!elt) { |
| 2121 | PyErr_SetString(PyExc_ValueError, |
| 2122 | "field elt is required for GeneratorExp"); |
| 2123 | return NULL; |
| 2124 | } |
| 2125 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2126 | if (!p) |
| 2127 | return NULL; |
| 2128 | p->kind = GeneratorExp_kind; |
| 2129 | p->v.GeneratorExp.elt = elt; |
| 2130 | p->v.GeneratorExp.generators = generators; |
| 2131 | p->lineno = lineno; |
| 2132 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2133 | p->end_lineno = end_lineno; |
| 2134 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2135 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2139 | Await(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2140 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2141 | { |
| 2142 | expr_ty p; |
| 2143 | if (!value) { |
| 2144 | PyErr_SetString(PyExc_ValueError, |
| 2145 | "field value is required for Await"); |
| 2146 | return NULL; |
| 2147 | } |
| 2148 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2149 | if (!p) |
| 2150 | return NULL; |
| 2151 | p->kind = Await_kind; |
| 2152 | p->v.Await.value = value; |
| 2153 | p->lineno = lineno; |
| 2154 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2155 | p->end_lineno = end_lineno; |
| 2156 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2157 | return p; |
| 2158 | } |
| 2159 | |
| 2160 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2161 | Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2162 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2163 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2164 | expr_ty p; |
| 2165 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2166 | if (!p) |
| 2167 | return NULL; |
| 2168 | p->kind = Yield_kind; |
| 2169 | p->v.Yield.value = value; |
| 2170 | p->lineno = lineno; |
| 2171 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2172 | p->end_lineno = end_lineno; |
| 2173 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2174 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2178 | YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2179 | end_col_offset, PyArena *arena) |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2180 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2181 | expr_ty p; |
| 2182 | if (!value) { |
| 2183 | PyErr_SetString(PyExc_ValueError, |
| 2184 | "field value is required for YieldFrom"); |
| 2185 | return NULL; |
| 2186 | } |
| 2187 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2188 | if (!p) |
| 2189 | return NULL; |
| 2190 | p->kind = YieldFrom_kind; |
| 2191 | p->v.YieldFrom.value = value; |
| 2192 | p->lineno = lineno; |
| 2193 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2194 | p->end_lineno = end_lineno; |
| 2195 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2196 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2200 | 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] | 2201 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2202 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2203 | expr_ty p; |
| 2204 | if (!left) { |
| 2205 | PyErr_SetString(PyExc_ValueError, |
| 2206 | "field left is required for Compare"); |
| 2207 | return NULL; |
| 2208 | } |
| 2209 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2210 | if (!p) |
| 2211 | return NULL; |
| 2212 | p->kind = Compare_kind; |
| 2213 | p->v.Compare.left = left; |
| 2214 | p->v.Compare.ops = ops; |
| 2215 | p->v.Compare.comparators = comparators; |
| 2216 | p->lineno = lineno; |
| 2217 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2218 | p->end_lineno = end_lineno; |
| 2219 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2220 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2224 | 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] | 2225 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2226 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2227 | expr_ty p; |
| 2228 | if (!func) { |
| 2229 | PyErr_SetString(PyExc_ValueError, |
| 2230 | "field func is required for Call"); |
| 2231 | return NULL; |
| 2232 | } |
| 2233 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2234 | if (!p) |
| 2235 | return NULL; |
| 2236 | p->kind = Call_kind; |
| 2237 | p->v.Call.func = func; |
| 2238 | p->v.Call.args = args; |
| 2239 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2240 | p->lineno = lineno; |
| 2241 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2242 | p->end_lineno = end_lineno; |
| 2243 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2244 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | expr_ty |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2248 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2249 | int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2250 | *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2251 | { |
| 2252 | expr_ty p; |
| 2253 | if (!value) { |
| 2254 | PyErr_SetString(PyExc_ValueError, |
| 2255 | "field value is required for FormattedValue"); |
| 2256 | return NULL; |
| 2257 | } |
| 2258 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2259 | if (!p) |
| 2260 | return NULL; |
| 2261 | p->kind = FormattedValue_kind; |
| 2262 | p->v.FormattedValue.value = value; |
| 2263 | p->v.FormattedValue.conversion = conversion; |
| 2264 | p->v.FormattedValue.format_spec = format_spec; |
| 2265 | p->lineno = lineno; |
| 2266 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2267 | p->end_lineno = end_lineno; |
| 2268 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2269 | return p; |
| 2270 | } |
| 2271 | |
| 2272 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2273 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 2274 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2275 | { |
| 2276 | expr_ty p; |
| 2277 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2278 | if (!p) |
| 2279 | return NULL; |
| 2280 | p->kind = JoinedStr_kind; |
| 2281 | p->v.JoinedStr.values = values; |
| 2282 | p->lineno = lineno; |
| 2283 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2284 | p->end_lineno = end_lineno; |
| 2285 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2286 | return p; |
| 2287 | } |
| 2288 | |
| 2289 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2290 | Constant(constant value, int lineno, int col_offset, int end_lineno, int |
| 2291 | end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2292 | { |
| 2293 | expr_ty p; |
| 2294 | if (!value) { |
| 2295 | PyErr_SetString(PyExc_ValueError, |
| 2296 | "field value is required for Constant"); |
| 2297 | return NULL; |
| 2298 | } |
| 2299 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2300 | if (!p) |
| 2301 | return NULL; |
| 2302 | p->kind = Constant_kind; |
| 2303 | p->v.Constant.value = value; |
| 2304 | p->lineno = lineno; |
| 2305 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2306 | p->end_lineno = end_lineno; |
| 2307 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2308 | return p; |
| 2309 | } |
| 2310 | |
| 2311 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2312 | 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] | 2313 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2314 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2315 | expr_ty p; |
| 2316 | if (!value) { |
| 2317 | PyErr_SetString(PyExc_ValueError, |
| 2318 | "field value is required for Attribute"); |
| 2319 | return NULL; |
| 2320 | } |
| 2321 | if (!attr) { |
| 2322 | PyErr_SetString(PyExc_ValueError, |
| 2323 | "field attr is required for Attribute"); |
| 2324 | return NULL; |
| 2325 | } |
| 2326 | if (!ctx) { |
| 2327 | PyErr_SetString(PyExc_ValueError, |
| 2328 | "field ctx is required for Attribute"); |
| 2329 | return NULL; |
| 2330 | } |
| 2331 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2332 | if (!p) |
| 2333 | return NULL; |
| 2334 | p->kind = Attribute_kind; |
| 2335 | p->v.Attribute.value = value; |
| 2336 | p->v.Attribute.attr = attr; |
| 2337 | p->v.Attribute.ctx = ctx; |
| 2338 | p->lineno = lineno; |
| 2339 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2340 | p->end_lineno = end_lineno; |
| 2341 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2342 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2346 | 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] | 2347 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2348 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2349 | expr_ty p; |
| 2350 | if (!value) { |
| 2351 | PyErr_SetString(PyExc_ValueError, |
| 2352 | "field value is required for Subscript"); |
| 2353 | return NULL; |
| 2354 | } |
| 2355 | if (!slice) { |
| 2356 | PyErr_SetString(PyExc_ValueError, |
| 2357 | "field slice is required for Subscript"); |
| 2358 | return NULL; |
| 2359 | } |
| 2360 | if (!ctx) { |
| 2361 | PyErr_SetString(PyExc_ValueError, |
| 2362 | "field ctx is required for Subscript"); |
| 2363 | return NULL; |
| 2364 | } |
| 2365 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2366 | if (!p) |
| 2367 | return NULL; |
| 2368 | p->kind = Subscript_kind; |
| 2369 | p->v.Subscript.value = value; |
| 2370 | p->v.Subscript.slice = slice; |
| 2371 | p->v.Subscript.ctx = ctx; |
| 2372 | p->lineno = lineno; |
| 2373 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2374 | p->end_lineno = end_lineno; |
| 2375 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2376 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2380 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 2381 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2382 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2383 | expr_ty p; |
| 2384 | if (!value) { |
| 2385 | PyErr_SetString(PyExc_ValueError, |
| 2386 | "field value is required for Starred"); |
| 2387 | return NULL; |
| 2388 | } |
| 2389 | if (!ctx) { |
| 2390 | PyErr_SetString(PyExc_ValueError, |
| 2391 | "field ctx is required for Starred"); |
| 2392 | return NULL; |
| 2393 | } |
| 2394 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2395 | if (!p) |
| 2396 | return NULL; |
| 2397 | p->kind = Starred_kind; |
| 2398 | p->v.Starred.value = value; |
| 2399 | p->v.Starred.ctx = ctx; |
| 2400 | p->lineno = lineno; |
| 2401 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2402 | p->end_lineno = end_lineno; |
| 2403 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2404 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2408 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 2409 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2410 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2411 | expr_ty p; |
| 2412 | if (!id) { |
| 2413 | PyErr_SetString(PyExc_ValueError, |
| 2414 | "field id is required for Name"); |
| 2415 | return NULL; |
| 2416 | } |
| 2417 | if (!ctx) { |
| 2418 | PyErr_SetString(PyExc_ValueError, |
| 2419 | "field ctx is required for Name"); |
| 2420 | return NULL; |
| 2421 | } |
| 2422 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2423 | if (!p) |
| 2424 | return NULL; |
| 2425 | p->kind = Name_kind; |
| 2426 | p->v.Name.id = id; |
| 2427 | p->v.Name.ctx = ctx; |
| 2428 | p->lineno = lineno; |
| 2429 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2430 | p->end_lineno = end_lineno; |
| 2431 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2432 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2436 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 2437 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2438 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2439 | expr_ty p; |
| 2440 | if (!ctx) { |
| 2441 | PyErr_SetString(PyExc_ValueError, |
| 2442 | "field ctx is required for List"); |
| 2443 | return NULL; |
| 2444 | } |
| 2445 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2446 | if (!p) |
| 2447 | return NULL; |
| 2448 | p->kind = List_kind; |
| 2449 | p->v.List.elts = elts; |
| 2450 | p->v.List.ctx = ctx; |
| 2451 | p->lineno = lineno; |
| 2452 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2453 | p->end_lineno = end_lineno; |
| 2454 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2455 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2459 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 2460 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2461 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2462 | expr_ty p; |
| 2463 | if (!ctx) { |
| 2464 | PyErr_SetString(PyExc_ValueError, |
| 2465 | "field ctx is required for Tuple"); |
| 2466 | return NULL; |
| 2467 | } |
| 2468 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2469 | if (!p) |
| 2470 | return NULL; |
| 2471 | p->kind = Tuple_kind; |
| 2472 | p->v.Tuple.elts = elts; |
| 2473 | p->v.Tuple.ctx = ctx; |
| 2474 | p->lineno = lineno; |
| 2475 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2476 | p->end_lineno = end_lineno; |
| 2477 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2478 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2482 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2483 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2484 | slice_ty p; |
| 2485 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2486 | if (!p) |
| 2487 | return NULL; |
| 2488 | p->kind = Slice_kind; |
| 2489 | p->v.Slice.lower = lower; |
| 2490 | p->v.Slice.upper = upper; |
| 2491 | p->v.Slice.step = step; |
| 2492 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2496 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2497 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2498 | slice_ty p; |
| 2499 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2500 | if (!p) |
| 2501 | return NULL; |
| 2502 | p->kind = ExtSlice_kind; |
| 2503 | p->v.ExtSlice.dims = dims; |
| 2504 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2505 | } |
| 2506 | |
| 2507 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2508 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2509 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2510 | slice_ty p; |
| 2511 | if (!value) { |
| 2512 | PyErr_SetString(PyExc_ValueError, |
| 2513 | "field value is required for Index"); |
| 2514 | return NULL; |
| 2515 | } |
| 2516 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2517 | if (!p) |
| 2518 | return NULL; |
| 2519 | p->kind = Index_kind; |
| 2520 | p->v.Index.value = value; |
| 2521 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 2525 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 2526 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2527 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2528 | comprehension_ty p; |
| 2529 | if (!target) { |
| 2530 | PyErr_SetString(PyExc_ValueError, |
| 2531 | "field target is required for comprehension"); |
| 2532 | return NULL; |
| 2533 | } |
| 2534 | if (!iter) { |
| 2535 | PyErr_SetString(PyExc_ValueError, |
| 2536 | "field iter is required for comprehension"); |
| 2537 | return NULL; |
| 2538 | } |
| 2539 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2540 | if (!p) |
| 2541 | return NULL; |
| 2542 | p->target = target; |
| 2543 | p->iter = iter; |
| 2544 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 2545 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2546 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2547 | } |
| 2548 | |
| 2549 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2550 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2551 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2552 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2553 | excepthandler_ty p; |
| 2554 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2555 | if (!p) |
| 2556 | return NULL; |
| 2557 | p->kind = ExceptHandler_kind; |
| 2558 | p->v.ExceptHandler.type = type; |
| 2559 | p->v.ExceptHandler.name = name; |
| 2560 | p->v.ExceptHandler.body = body; |
| 2561 | p->lineno = lineno; |
| 2562 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2563 | p->end_lineno = end_lineno; |
| 2564 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2565 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2566 | } |
| 2567 | |
| 2568 | arguments_ty |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 2569 | arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq * |
| 2570 | kw_defaults, arg_ty kwarg, asdl_seq * defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2571 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2572 | arguments_ty p; |
| 2573 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2574 | if (!p) |
| 2575 | return NULL; |
| 2576 | p->args = args; |
| 2577 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2578 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2579 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 2580 | p->kwarg = kwarg; |
| 2581 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2582 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2583 | } |
| 2584 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2585 | arg_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2586 | arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int |
| 2587 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2588 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2589 | arg_ty p; |
| 2590 | if (!arg) { |
| 2591 | PyErr_SetString(PyExc_ValueError, |
| 2592 | "field arg is required for arg"); |
| 2593 | return NULL; |
| 2594 | } |
| 2595 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2596 | if (!p) |
| 2597 | return NULL; |
| 2598 | p->arg = arg; |
| 2599 | p->annotation = annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2600 | p->type_comment = type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 2601 | p->lineno = lineno; |
| 2602 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2603 | p->end_lineno = end_lineno; |
| 2604 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2605 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2606 | } |
| 2607 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2608 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2609 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2610 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2611 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2612 | if (!value) { |
| 2613 | PyErr_SetString(PyExc_ValueError, |
| 2614 | "field value is required for keyword"); |
| 2615 | return NULL; |
| 2616 | } |
| 2617 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2618 | if (!p) |
| 2619 | return NULL; |
| 2620 | p->arg = arg; |
| 2621 | p->value = value; |
| 2622 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2626 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2627 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2628 | alias_ty p; |
| 2629 | if (!name) { |
| 2630 | PyErr_SetString(PyExc_ValueError, |
| 2631 | "field name is required for alias"); |
| 2632 | return NULL; |
| 2633 | } |
| 2634 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2635 | if (!p) |
| 2636 | return NULL; |
| 2637 | p->name = name; |
| 2638 | p->asname = asname; |
| 2639 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2640 | } |
| 2641 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2642 | withitem_ty |
| 2643 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2644 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2645 | withitem_ty p; |
| 2646 | if (!context_expr) { |
| 2647 | PyErr_SetString(PyExc_ValueError, |
| 2648 | "field context_expr is required for withitem"); |
| 2649 | return NULL; |
| 2650 | } |
| 2651 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2652 | if (!p) |
| 2653 | return NULL; |
| 2654 | p->context_expr = context_expr; |
| 2655 | p->optional_vars = optional_vars; |
| 2656 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2657 | } |
| 2658 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2659 | type_ignore_ty |
| 2660 | TypeIgnore(int lineno, PyArena *arena) |
| 2661 | { |
| 2662 | type_ignore_ty p; |
| 2663 | p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2664 | if (!p) |
| 2665 | return NULL; |
| 2666 | p->kind = TypeIgnore_kind; |
| 2667 | p->v.TypeIgnore.lineno = lineno; |
| 2668 | return p; |
| 2669 | } |
| 2670 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2671 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2672 | PyObject* |
| 2673 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2674 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2675 | mod_ty o = (mod_ty)_o; |
| 2676 | PyObject *result = NULL, *value = NULL; |
| 2677 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 2678 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2679 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2680 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2681 | switch (o->kind) { |
| 2682 | case Module_kind: |
| 2683 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2684 | if (!result) goto failed; |
| 2685 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2686 | if (!value) goto failed; |
| 2687 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2688 | goto failed; |
| 2689 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2690 | value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); |
| 2691 | if (!value) goto failed; |
| 2692 | if (_PyObject_SetAttrId(result, &PyId_type_ignores, value) == -1) |
| 2693 | goto failed; |
| 2694 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2695 | break; |
| 2696 | case Interactive_kind: |
| 2697 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2698 | if (!result) goto failed; |
| 2699 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2700 | if (!value) goto failed; |
| 2701 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2702 | goto failed; |
| 2703 | Py_DECREF(value); |
| 2704 | break; |
| 2705 | case Expression_kind: |
| 2706 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2707 | if (!result) goto failed; |
| 2708 | value = ast2obj_expr(o->v.Expression.body); |
| 2709 | if (!value) goto failed; |
| 2710 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2711 | goto failed; |
| 2712 | Py_DECREF(value); |
| 2713 | break; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2714 | case FunctionType_kind: |
| 2715 | result = PyType_GenericNew(FunctionType_type, NULL, NULL); |
| 2716 | if (!result) goto failed; |
| 2717 | value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); |
| 2718 | if (!value) goto failed; |
| 2719 | if (_PyObject_SetAttrId(result, &PyId_argtypes, value) == -1) |
| 2720 | goto failed; |
| 2721 | Py_DECREF(value); |
| 2722 | value = ast2obj_expr(o->v.FunctionType.returns); |
| 2723 | if (!value) goto failed; |
| 2724 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2725 | goto failed; |
| 2726 | Py_DECREF(value); |
| 2727 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2728 | case Suite_kind: |
| 2729 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2730 | if (!result) goto failed; |
| 2731 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2732 | if (!value) goto failed; |
| 2733 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2734 | goto failed; |
| 2735 | Py_DECREF(value); |
| 2736 | break; |
| 2737 | } |
| 2738 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2739 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2740 | Py_XDECREF(value); |
| 2741 | Py_XDECREF(result); |
| 2742 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2743 | } |
| 2744 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2745 | PyObject* |
| 2746 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2747 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2748 | stmt_ty o = (stmt_ty)_o; |
| 2749 | PyObject *result = NULL, *value = NULL; |
| 2750 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 2751 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2752 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2753 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2754 | switch (o->kind) { |
| 2755 | case FunctionDef_kind: |
| 2756 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2757 | if (!result) goto failed; |
| 2758 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2759 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2760 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2761 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2762 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2763 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2764 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2765 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2766 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2767 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2768 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2769 | if (!value) goto failed; |
| 2770 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2771 | goto failed; |
| 2772 | Py_DECREF(value); |
| 2773 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 2774 | if (!value) goto failed; |
| 2775 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2776 | goto failed; |
| 2777 | Py_DECREF(value); |
| 2778 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2779 | if (!value) goto failed; |
| 2780 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2781 | goto failed; |
| 2782 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2783 | value = ast2obj_string(o->v.FunctionDef.type_comment); |
| 2784 | if (!value) goto failed; |
| 2785 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2786 | goto failed; |
| 2787 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2788 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2789 | case AsyncFunctionDef_kind: |
| 2790 | result = PyType_GenericNew(AsyncFunctionDef_type, NULL, NULL); |
| 2791 | if (!result) goto failed; |
| 2792 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 2793 | if (!value) goto failed; |
| 2794 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2795 | goto failed; |
| 2796 | Py_DECREF(value); |
| 2797 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 2798 | if (!value) goto failed; |
| 2799 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2800 | goto failed; |
| 2801 | Py_DECREF(value); |
| 2802 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 2803 | if (!value) goto failed; |
| 2804 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2805 | goto failed; |
| 2806 | Py_DECREF(value); |
| 2807 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 2808 | ast2obj_expr); |
| 2809 | if (!value) goto failed; |
| 2810 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2811 | goto failed; |
| 2812 | Py_DECREF(value); |
| 2813 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 2814 | if (!value) goto failed; |
| 2815 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2816 | goto failed; |
| 2817 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2818 | value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); |
| 2819 | if (!value) goto failed; |
| 2820 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2821 | goto failed; |
| 2822 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2823 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2824 | case ClassDef_kind: |
| 2825 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2826 | if (!result) goto failed; |
| 2827 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2828 | if (!value) goto failed; |
| 2829 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2830 | goto failed; |
| 2831 | Py_DECREF(value); |
| 2832 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2833 | if (!value) goto failed; |
| 2834 | if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) |
| 2835 | goto failed; |
| 2836 | Py_DECREF(value); |
| 2837 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2838 | if (!value) goto failed; |
| 2839 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 2840 | goto failed; |
| 2841 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2842 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2843 | if (!value) goto failed; |
| 2844 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2845 | goto failed; |
| 2846 | Py_DECREF(value); |
| 2847 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 2848 | if (!value) goto failed; |
| 2849 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2850 | goto failed; |
| 2851 | Py_DECREF(value); |
| 2852 | break; |
| 2853 | case Return_kind: |
| 2854 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2855 | if (!result) goto failed; |
| 2856 | value = ast2obj_expr(o->v.Return.value); |
| 2857 | if (!value) goto failed; |
| 2858 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2859 | goto failed; |
| 2860 | Py_DECREF(value); |
| 2861 | break; |
| 2862 | case Delete_kind: |
| 2863 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2864 | if (!result) goto failed; |
| 2865 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2866 | if (!value) goto failed; |
| 2867 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2868 | goto failed; |
| 2869 | Py_DECREF(value); |
| 2870 | break; |
| 2871 | case Assign_kind: |
| 2872 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2873 | if (!result) goto failed; |
| 2874 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2875 | if (!value) goto failed; |
| 2876 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2877 | goto failed; |
| 2878 | Py_DECREF(value); |
| 2879 | value = ast2obj_expr(o->v.Assign.value); |
| 2880 | if (!value) goto failed; |
| 2881 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2882 | goto failed; |
| 2883 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2884 | value = ast2obj_string(o->v.Assign.type_comment); |
| 2885 | if (!value) goto failed; |
| 2886 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2887 | goto failed; |
| 2888 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2889 | break; |
| 2890 | case AugAssign_kind: |
| 2891 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2892 | if (!result) goto failed; |
| 2893 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2894 | if (!value) goto failed; |
| 2895 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2896 | goto failed; |
| 2897 | Py_DECREF(value); |
| 2898 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2899 | if (!value) goto failed; |
| 2900 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2901 | goto failed; |
| 2902 | Py_DECREF(value); |
| 2903 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2904 | if (!value) goto failed; |
| 2905 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2906 | goto failed; |
| 2907 | Py_DECREF(value); |
| 2908 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2909 | case AnnAssign_kind: |
| 2910 | result = PyType_GenericNew(AnnAssign_type, NULL, NULL); |
| 2911 | if (!result) goto failed; |
| 2912 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 2913 | if (!value) goto failed; |
| 2914 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2915 | goto failed; |
| 2916 | Py_DECREF(value); |
| 2917 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 2918 | if (!value) goto failed; |
| 2919 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 2920 | goto failed; |
| 2921 | Py_DECREF(value); |
| 2922 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 2923 | if (!value) goto failed; |
| 2924 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2925 | goto failed; |
| 2926 | Py_DECREF(value); |
| 2927 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 2928 | if (!value) goto failed; |
| 2929 | if (_PyObject_SetAttrId(result, &PyId_simple, value) == -1) |
| 2930 | goto failed; |
| 2931 | Py_DECREF(value); |
| 2932 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2933 | case For_kind: |
| 2934 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2935 | if (!result) goto failed; |
| 2936 | value = ast2obj_expr(o->v.For.target); |
| 2937 | if (!value) goto failed; |
| 2938 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2939 | goto failed; |
| 2940 | Py_DECREF(value); |
| 2941 | value = ast2obj_expr(o->v.For.iter); |
| 2942 | if (!value) goto failed; |
| 2943 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2944 | goto failed; |
| 2945 | Py_DECREF(value); |
| 2946 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2947 | if (!value) goto failed; |
| 2948 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2949 | goto failed; |
| 2950 | Py_DECREF(value); |
| 2951 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2952 | if (!value) goto failed; |
| 2953 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2954 | goto failed; |
| 2955 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2956 | value = ast2obj_string(o->v.For.type_comment); |
| 2957 | if (!value) goto failed; |
| 2958 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2959 | goto failed; |
| 2960 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2961 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2962 | case AsyncFor_kind: |
| 2963 | result = PyType_GenericNew(AsyncFor_type, NULL, NULL); |
| 2964 | if (!result) goto failed; |
| 2965 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 2966 | if (!value) goto failed; |
| 2967 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2968 | goto failed; |
| 2969 | Py_DECREF(value); |
| 2970 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 2971 | if (!value) goto failed; |
| 2972 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2973 | goto failed; |
| 2974 | Py_DECREF(value); |
| 2975 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 2976 | if (!value) goto failed; |
| 2977 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2978 | goto failed; |
| 2979 | Py_DECREF(value); |
| 2980 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 2981 | if (!value) goto failed; |
| 2982 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2983 | goto failed; |
| 2984 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2985 | value = ast2obj_string(o->v.AsyncFor.type_comment); |
| 2986 | if (!value) goto failed; |
| 2987 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2988 | goto failed; |
| 2989 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2990 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2991 | case While_kind: |
| 2992 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2993 | if (!result) goto failed; |
| 2994 | value = ast2obj_expr(o->v.While.test); |
| 2995 | if (!value) goto failed; |
| 2996 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2997 | goto failed; |
| 2998 | Py_DECREF(value); |
| 2999 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 3000 | if (!value) goto failed; |
| 3001 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3002 | goto failed; |
| 3003 | Py_DECREF(value); |
| 3004 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 3005 | if (!value) goto failed; |
| 3006 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3007 | goto failed; |
| 3008 | Py_DECREF(value); |
| 3009 | break; |
| 3010 | case If_kind: |
| 3011 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 3012 | if (!result) goto failed; |
| 3013 | value = ast2obj_expr(o->v.If.test); |
| 3014 | if (!value) goto failed; |
| 3015 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3016 | goto failed; |
| 3017 | Py_DECREF(value); |
| 3018 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 3019 | if (!value) goto failed; |
| 3020 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3021 | goto failed; |
| 3022 | Py_DECREF(value); |
| 3023 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 3024 | if (!value) goto failed; |
| 3025 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3026 | goto failed; |
| 3027 | Py_DECREF(value); |
| 3028 | break; |
| 3029 | case With_kind: |
| 3030 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 3031 | if (!result) goto failed; |
| 3032 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 3033 | if (!value) goto failed; |
| 3034 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 3035 | goto failed; |
| 3036 | Py_DECREF(value); |
| 3037 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 3038 | if (!value) goto failed; |
| 3039 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3040 | goto failed; |
| 3041 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3042 | value = ast2obj_string(o->v.With.type_comment); |
| 3043 | if (!value) goto failed; |
| 3044 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 3045 | goto failed; |
| 3046 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3047 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3048 | case AsyncWith_kind: |
| 3049 | result = PyType_GenericNew(AsyncWith_type, NULL, NULL); |
| 3050 | if (!result) goto failed; |
| 3051 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 3052 | if (!value) goto failed; |
| 3053 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 3054 | goto failed; |
| 3055 | Py_DECREF(value); |
| 3056 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 3057 | if (!value) goto failed; |
| 3058 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3059 | goto failed; |
| 3060 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3061 | value = ast2obj_string(o->v.AsyncWith.type_comment); |
| 3062 | if (!value) goto failed; |
| 3063 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 3064 | goto failed; |
| 3065 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3066 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3067 | case Raise_kind: |
| 3068 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 3069 | if (!result) goto failed; |
| 3070 | value = ast2obj_expr(o->v.Raise.exc); |
| 3071 | if (!value) goto failed; |
| 3072 | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
| 3073 | goto failed; |
| 3074 | Py_DECREF(value); |
| 3075 | value = ast2obj_expr(o->v.Raise.cause); |
| 3076 | if (!value) goto failed; |
| 3077 | if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) |
| 3078 | goto failed; |
| 3079 | Py_DECREF(value); |
| 3080 | break; |
| 3081 | case Try_kind: |
| 3082 | result = PyType_GenericNew(Try_type, NULL, NULL); |
| 3083 | if (!result) goto failed; |
| 3084 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 3085 | if (!value) goto failed; |
| 3086 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3087 | goto failed; |
| 3088 | Py_DECREF(value); |
| 3089 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 3090 | if (!value) goto failed; |
| 3091 | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
| 3092 | goto failed; |
| 3093 | Py_DECREF(value); |
| 3094 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 3095 | if (!value) goto failed; |
| 3096 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3097 | goto failed; |
| 3098 | Py_DECREF(value); |
| 3099 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 3100 | if (!value) goto failed; |
| 3101 | if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) |
| 3102 | goto failed; |
| 3103 | Py_DECREF(value); |
| 3104 | break; |
| 3105 | case Assert_kind: |
| 3106 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 3107 | if (!result) goto failed; |
| 3108 | value = ast2obj_expr(o->v.Assert.test); |
| 3109 | if (!value) goto failed; |
| 3110 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3111 | goto failed; |
| 3112 | Py_DECREF(value); |
| 3113 | value = ast2obj_expr(o->v.Assert.msg); |
| 3114 | if (!value) goto failed; |
| 3115 | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
| 3116 | goto failed; |
| 3117 | Py_DECREF(value); |
| 3118 | break; |
| 3119 | case Import_kind: |
| 3120 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 3121 | if (!result) goto failed; |
| 3122 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 3123 | if (!value) goto failed; |
| 3124 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3125 | goto failed; |
| 3126 | Py_DECREF(value); |
| 3127 | break; |
| 3128 | case ImportFrom_kind: |
| 3129 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 3130 | if (!result) goto failed; |
| 3131 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 3132 | if (!value) goto failed; |
| 3133 | if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) |
| 3134 | goto failed; |
| 3135 | Py_DECREF(value); |
| 3136 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 3137 | if (!value) goto failed; |
| 3138 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3139 | goto failed; |
| 3140 | Py_DECREF(value); |
| 3141 | value = ast2obj_int(o->v.ImportFrom.level); |
| 3142 | if (!value) goto failed; |
| 3143 | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
| 3144 | goto failed; |
| 3145 | Py_DECREF(value); |
| 3146 | break; |
| 3147 | case Global_kind: |
| 3148 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 3149 | if (!result) goto failed; |
| 3150 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 3151 | if (!value) goto failed; |
| 3152 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3153 | goto failed; |
| 3154 | Py_DECREF(value); |
| 3155 | break; |
| 3156 | case Nonlocal_kind: |
| 3157 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 3158 | if (!result) goto failed; |
| 3159 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 3160 | if (!value) goto failed; |
| 3161 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3162 | goto failed; |
| 3163 | Py_DECREF(value); |
| 3164 | break; |
| 3165 | case Expr_kind: |
| 3166 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 3167 | if (!result) goto failed; |
| 3168 | value = ast2obj_expr(o->v.Expr.value); |
| 3169 | if (!value) goto failed; |
| 3170 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3171 | goto failed; |
| 3172 | Py_DECREF(value); |
| 3173 | break; |
| 3174 | case Pass_kind: |
| 3175 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 3176 | if (!result) goto failed; |
| 3177 | break; |
| 3178 | case Break_kind: |
| 3179 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 3180 | if (!result) goto failed; |
| 3181 | break; |
| 3182 | case Continue_kind: |
| 3183 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 3184 | if (!result) goto failed; |
| 3185 | break; |
| 3186 | } |
| 3187 | value = ast2obj_int(o->lineno); |
| 3188 | if (!value) goto failed; |
| 3189 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3190 | goto failed; |
| 3191 | Py_DECREF(value); |
| 3192 | value = ast2obj_int(o->col_offset); |
| 3193 | if (!value) goto failed; |
| 3194 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3195 | goto failed; |
| 3196 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3197 | value = ast2obj_int(o->end_lineno); |
| 3198 | if (!value) goto failed; |
| 3199 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3200 | goto failed; |
| 3201 | Py_DECREF(value); |
| 3202 | value = ast2obj_int(o->end_col_offset); |
| 3203 | if (!value) goto failed; |
| 3204 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3205 | goto failed; |
| 3206 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3207 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3208 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3209 | Py_XDECREF(value); |
| 3210 | Py_XDECREF(result); |
| 3211 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3212 | } |
| 3213 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3214 | PyObject* |
| 3215 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3216 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3217 | expr_ty o = (expr_ty)_o; |
| 3218 | PyObject *result = NULL, *value = NULL; |
| 3219 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3220 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3221 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3222 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3223 | switch (o->kind) { |
| 3224 | case BoolOp_kind: |
| 3225 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 3226 | if (!result) goto failed; |
| 3227 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 3228 | if (!value) goto failed; |
| 3229 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3230 | goto failed; |
| 3231 | Py_DECREF(value); |
| 3232 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 3233 | if (!value) goto failed; |
| 3234 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3235 | goto failed; |
| 3236 | Py_DECREF(value); |
| 3237 | break; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3238 | case NamedExpr_kind: |
| 3239 | result = PyType_GenericNew(NamedExpr_type, NULL, NULL); |
| 3240 | if (!result) goto failed; |
| 3241 | value = ast2obj_expr(o->v.NamedExpr.target); |
| 3242 | if (!value) goto failed; |
| 3243 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 3244 | goto failed; |
| 3245 | Py_DECREF(value); |
| 3246 | value = ast2obj_expr(o->v.NamedExpr.value); |
| 3247 | if (!value) goto failed; |
| 3248 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3249 | goto failed; |
| 3250 | Py_DECREF(value); |
| 3251 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3252 | case BinOp_kind: |
| 3253 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 3254 | if (!result) goto failed; |
| 3255 | value = ast2obj_expr(o->v.BinOp.left); |
| 3256 | if (!value) goto failed; |
| 3257 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3258 | goto failed; |
| 3259 | Py_DECREF(value); |
| 3260 | value = ast2obj_operator(o->v.BinOp.op); |
| 3261 | if (!value) goto failed; |
| 3262 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3263 | goto failed; |
| 3264 | Py_DECREF(value); |
| 3265 | value = ast2obj_expr(o->v.BinOp.right); |
| 3266 | if (!value) goto failed; |
| 3267 | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
| 3268 | goto failed; |
| 3269 | Py_DECREF(value); |
| 3270 | break; |
| 3271 | case UnaryOp_kind: |
| 3272 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 3273 | if (!result) goto failed; |
| 3274 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 3275 | if (!value) goto failed; |
| 3276 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3277 | goto failed; |
| 3278 | Py_DECREF(value); |
| 3279 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 3280 | if (!value) goto failed; |
| 3281 | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
| 3282 | goto failed; |
| 3283 | Py_DECREF(value); |
| 3284 | break; |
| 3285 | case Lambda_kind: |
| 3286 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 3287 | if (!result) goto failed; |
| 3288 | value = ast2obj_arguments(o->v.Lambda.args); |
| 3289 | if (!value) goto failed; |
| 3290 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3291 | goto failed; |
| 3292 | Py_DECREF(value); |
| 3293 | value = ast2obj_expr(o->v.Lambda.body); |
| 3294 | if (!value) goto failed; |
| 3295 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3296 | goto failed; |
| 3297 | Py_DECREF(value); |
| 3298 | break; |
| 3299 | case IfExp_kind: |
| 3300 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 3301 | if (!result) goto failed; |
| 3302 | value = ast2obj_expr(o->v.IfExp.test); |
| 3303 | if (!value) goto failed; |
| 3304 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3305 | goto failed; |
| 3306 | Py_DECREF(value); |
| 3307 | value = ast2obj_expr(o->v.IfExp.body); |
| 3308 | if (!value) goto failed; |
| 3309 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3310 | goto failed; |
| 3311 | Py_DECREF(value); |
| 3312 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 3313 | if (!value) goto failed; |
| 3314 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3315 | goto failed; |
| 3316 | Py_DECREF(value); |
| 3317 | break; |
| 3318 | case Dict_kind: |
| 3319 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 3320 | if (!result) goto failed; |
| 3321 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 3322 | if (!value) goto failed; |
| 3323 | if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) |
| 3324 | goto failed; |
| 3325 | Py_DECREF(value); |
| 3326 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 3327 | if (!value) goto failed; |
| 3328 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3329 | goto failed; |
| 3330 | Py_DECREF(value); |
| 3331 | break; |
| 3332 | case Set_kind: |
| 3333 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 3334 | if (!result) goto failed; |
| 3335 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 3336 | if (!value) goto failed; |
| 3337 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3338 | goto failed; |
| 3339 | Py_DECREF(value); |
| 3340 | break; |
| 3341 | case ListComp_kind: |
| 3342 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 3343 | if (!result) goto failed; |
| 3344 | value = ast2obj_expr(o->v.ListComp.elt); |
| 3345 | if (!value) goto failed; |
| 3346 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3347 | goto failed; |
| 3348 | Py_DECREF(value); |
| 3349 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 3350 | if (!value) goto failed; |
| 3351 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3352 | goto failed; |
| 3353 | Py_DECREF(value); |
| 3354 | break; |
| 3355 | case SetComp_kind: |
| 3356 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 3357 | if (!result) goto failed; |
| 3358 | value = ast2obj_expr(o->v.SetComp.elt); |
| 3359 | if (!value) goto failed; |
| 3360 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3361 | goto failed; |
| 3362 | Py_DECREF(value); |
| 3363 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 3364 | if (!value) goto failed; |
| 3365 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3366 | goto failed; |
| 3367 | Py_DECREF(value); |
| 3368 | break; |
| 3369 | case DictComp_kind: |
| 3370 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 3371 | if (!result) goto failed; |
| 3372 | value = ast2obj_expr(o->v.DictComp.key); |
| 3373 | if (!value) goto failed; |
| 3374 | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
| 3375 | goto failed; |
| 3376 | Py_DECREF(value); |
| 3377 | value = ast2obj_expr(o->v.DictComp.value); |
| 3378 | if (!value) goto failed; |
| 3379 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3380 | goto failed; |
| 3381 | Py_DECREF(value); |
| 3382 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 3383 | if (!value) goto failed; |
| 3384 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3385 | goto failed; |
| 3386 | Py_DECREF(value); |
| 3387 | break; |
| 3388 | case GeneratorExp_kind: |
| 3389 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 3390 | if (!result) goto failed; |
| 3391 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 3392 | if (!value) goto failed; |
| 3393 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3394 | goto failed; |
| 3395 | Py_DECREF(value); |
| 3396 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 3397 | ast2obj_comprehension); |
| 3398 | if (!value) goto failed; |
| 3399 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3400 | goto failed; |
| 3401 | Py_DECREF(value); |
| 3402 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3403 | case Await_kind: |
| 3404 | result = PyType_GenericNew(Await_type, NULL, NULL); |
| 3405 | if (!result) goto failed; |
| 3406 | value = ast2obj_expr(o->v.Await.value); |
| 3407 | if (!value) goto failed; |
| 3408 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3409 | goto failed; |
| 3410 | Py_DECREF(value); |
| 3411 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3412 | case Yield_kind: |
| 3413 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 3414 | if (!result) goto failed; |
| 3415 | value = ast2obj_expr(o->v.Yield.value); |
| 3416 | if (!value) goto failed; |
| 3417 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3418 | goto failed; |
| 3419 | Py_DECREF(value); |
| 3420 | break; |
| 3421 | case YieldFrom_kind: |
| 3422 | result = PyType_GenericNew(YieldFrom_type, NULL, NULL); |
| 3423 | if (!result) goto failed; |
| 3424 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 3425 | if (!value) goto failed; |
| 3426 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3427 | goto failed; |
| 3428 | Py_DECREF(value); |
| 3429 | break; |
| 3430 | case Compare_kind: |
| 3431 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 3432 | if (!result) goto failed; |
| 3433 | value = ast2obj_expr(o->v.Compare.left); |
| 3434 | if (!value) goto failed; |
| 3435 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3436 | goto failed; |
| 3437 | Py_DECREF(value); |
| 3438 | { |
| 3439 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 3440 | value = PyList_New(n); |
| 3441 | if (!value) goto failed; |
| 3442 | for(i = 0; i < n; i++) |
| 3443 | 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] | 3444 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3445 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3446 | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
| 3447 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3448 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3449 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3450 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3451 | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
| 3452 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3453 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3454 | break; |
| 3455 | case Call_kind: |
| 3456 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 3457 | if (!result) goto failed; |
| 3458 | value = ast2obj_expr(o->v.Call.func); |
| 3459 | if (!value) goto failed; |
| 3460 | if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) |
| 3461 | goto failed; |
| 3462 | Py_DECREF(value); |
| 3463 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 3464 | if (!value) goto failed; |
| 3465 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3466 | goto failed; |
| 3467 | Py_DECREF(value); |
| 3468 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 3469 | if (!value) goto failed; |
| 3470 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 3471 | goto failed; |
| 3472 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3473 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3474 | case FormattedValue_kind: |
| 3475 | result = PyType_GenericNew(FormattedValue_type, NULL, NULL); |
| 3476 | if (!result) goto failed; |
| 3477 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 3478 | if (!value) goto failed; |
| 3479 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3480 | goto failed; |
| 3481 | Py_DECREF(value); |
| 3482 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 3483 | if (!value) goto failed; |
| 3484 | if (_PyObject_SetAttrId(result, &PyId_conversion, value) == -1) |
| 3485 | goto failed; |
| 3486 | Py_DECREF(value); |
| 3487 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 3488 | if (!value) goto failed; |
| 3489 | if (_PyObject_SetAttrId(result, &PyId_format_spec, value) == -1) |
| 3490 | goto failed; |
| 3491 | Py_DECREF(value); |
| 3492 | break; |
| 3493 | case JoinedStr_kind: |
| 3494 | result = PyType_GenericNew(JoinedStr_type, NULL, NULL); |
| 3495 | if (!result) goto failed; |
| 3496 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 3497 | if (!value) goto failed; |
| 3498 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3499 | goto failed; |
| 3500 | Py_DECREF(value); |
| 3501 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3502 | case Constant_kind: |
| 3503 | result = PyType_GenericNew(Constant_type, NULL, NULL); |
| 3504 | if (!result) goto failed; |
| 3505 | value = ast2obj_constant(o->v.Constant.value); |
| 3506 | if (!value) goto failed; |
| 3507 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3508 | goto failed; |
| 3509 | Py_DECREF(value); |
| 3510 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3511 | case Attribute_kind: |
| 3512 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 3513 | if (!result) goto failed; |
| 3514 | value = ast2obj_expr(o->v.Attribute.value); |
| 3515 | if (!value) goto failed; |
| 3516 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3517 | goto failed; |
| 3518 | Py_DECREF(value); |
| 3519 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 3520 | if (!value) goto failed; |
| 3521 | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
| 3522 | goto failed; |
| 3523 | Py_DECREF(value); |
| 3524 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 3525 | if (!value) goto failed; |
| 3526 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3527 | goto failed; |
| 3528 | Py_DECREF(value); |
| 3529 | break; |
| 3530 | case Subscript_kind: |
| 3531 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 3532 | if (!result) goto failed; |
| 3533 | value = ast2obj_expr(o->v.Subscript.value); |
| 3534 | if (!value) goto failed; |
| 3535 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3536 | goto failed; |
| 3537 | Py_DECREF(value); |
| 3538 | value = ast2obj_slice(o->v.Subscript.slice); |
| 3539 | if (!value) goto failed; |
| 3540 | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
| 3541 | goto failed; |
| 3542 | Py_DECREF(value); |
| 3543 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 3544 | if (!value) goto failed; |
| 3545 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3546 | goto failed; |
| 3547 | Py_DECREF(value); |
| 3548 | break; |
| 3549 | case Starred_kind: |
| 3550 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 3551 | if (!result) goto failed; |
| 3552 | value = ast2obj_expr(o->v.Starred.value); |
| 3553 | if (!value) goto failed; |
| 3554 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3555 | goto failed; |
| 3556 | Py_DECREF(value); |
| 3557 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 3558 | if (!value) goto failed; |
| 3559 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3560 | goto failed; |
| 3561 | Py_DECREF(value); |
| 3562 | break; |
| 3563 | case Name_kind: |
| 3564 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 3565 | if (!result) goto failed; |
| 3566 | value = ast2obj_identifier(o->v.Name.id); |
| 3567 | if (!value) goto failed; |
| 3568 | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
| 3569 | goto failed; |
| 3570 | Py_DECREF(value); |
| 3571 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 3572 | if (!value) goto failed; |
| 3573 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3574 | goto failed; |
| 3575 | Py_DECREF(value); |
| 3576 | break; |
| 3577 | case List_kind: |
| 3578 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 3579 | if (!result) goto failed; |
| 3580 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 3581 | if (!value) goto failed; |
| 3582 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3583 | goto failed; |
| 3584 | Py_DECREF(value); |
| 3585 | value = ast2obj_expr_context(o->v.List.ctx); |
| 3586 | if (!value) goto failed; |
| 3587 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3588 | goto failed; |
| 3589 | Py_DECREF(value); |
| 3590 | break; |
| 3591 | case Tuple_kind: |
| 3592 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 3593 | if (!result) goto failed; |
| 3594 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 3595 | if (!value) goto failed; |
| 3596 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3597 | goto failed; |
| 3598 | Py_DECREF(value); |
| 3599 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 3600 | if (!value) goto failed; |
| 3601 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3602 | goto failed; |
| 3603 | Py_DECREF(value); |
| 3604 | break; |
| 3605 | } |
| 3606 | value = ast2obj_int(o->lineno); |
| 3607 | if (!value) goto failed; |
| 3608 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3609 | goto failed; |
| 3610 | Py_DECREF(value); |
| 3611 | value = ast2obj_int(o->col_offset); |
| 3612 | if (!value) goto failed; |
| 3613 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3614 | goto failed; |
| 3615 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3616 | value = ast2obj_int(o->end_lineno); |
| 3617 | if (!value) goto failed; |
| 3618 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3619 | goto failed; |
| 3620 | Py_DECREF(value); |
| 3621 | value = ast2obj_int(o->end_col_offset); |
| 3622 | if (!value) goto failed; |
| 3623 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3624 | goto failed; |
| 3625 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3626 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3627 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3628 | Py_XDECREF(value); |
| 3629 | Py_XDECREF(result); |
| 3630 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3631 | } |
| 3632 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3633 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3634 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3635 | switch(o) { |
| 3636 | case Load: |
| 3637 | Py_INCREF(Load_singleton); |
| 3638 | return Load_singleton; |
| 3639 | case Store: |
| 3640 | Py_INCREF(Store_singleton); |
| 3641 | return Store_singleton; |
| 3642 | case Del: |
| 3643 | Py_INCREF(Del_singleton); |
| 3644 | return Del_singleton; |
| 3645 | case AugLoad: |
| 3646 | Py_INCREF(AugLoad_singleton); |
| 3647 | return AugLoad_singleton; |
| 3648 | case AugStore: |
| 3649 | Py_INCREF(AugStore_singleton); |
| 3650 | return AugStore_singleton; |
| 3651 | case Param: |
| 3652 | Py_INCREF(Param_singleton); |
| 3653 | return Param_singleton; |
| 3654 | default: |
| 3655 | /* should never happen, but just in case ... */ |
| 3656 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 3657 | return NULL; |
| 3658 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3659 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3660 | PyObject* |
| 3661 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3662 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3663 | slice_ty o = (slice_ty)_o; |
| 3664 | PyObject *result = NULL, *value = NULL; |
| 3665 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3666 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3667 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3668 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3669 | switch (o->kind) { |
| 3670 | case Slice_kind: |
| 3671 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 3672 | if (!result) goto failed; |
| 3673 | value = ast2obj_expr(o->v.Slice.lower); |
| 3674 | if (!value) goto failed; |
| 3675 | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
| 3676 | goto failed; |
| 3677 | Py_DECREF(value); |
| 3678 | value = ast2obj_expr(o->v.Slice.upper); |
| 3679 | if (!value) goto failed; |
| 3680 | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
| 3681 | goto failed; |
| 3682 | Py_DECREF(value); |
| 3683 | value = ast2obj_expr(o->v.Slice.step); |
| 3684 | if (!value) goto failed; |
| 3685 | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
| 3686 | goto failed; |
| 3687 | Py_DECREF(value); |
| 3688 | break; |
| 3689 | case ExtSlice_kind: |
| 3690 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3691 | if (!result) goto failed; |
| 3692 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3693 | if (!value) goto failed; |
| 3694 | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
| 3695 | goto failed; |
| 3696 | Py_DECREF(value); |
| 3697 | break; |
| 3698 | case Index_kind: |
| 3699 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3700 | if (!result) goto failed; |
| 3701 | value = ast2obj_expr(o->v.Index.value); |
| 3702 | if (!value) goto failed; |
| 3703 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3704 | goto failed; |
| 3705 | Py_DECREF(value); |
| 3706 | break; |
| 3707 | } |
| 3708 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3709 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3710 | Py_XDECREF(value); |
| 3711 | Py_XDECREF(result); |
| 3712 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3713 | } |
| 3714 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3715 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3716 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3717 | switch(o) { |
| 3718 | case And: |
| 3719 | Py_INCREF(And_singleton); |
| 3720 | return And_singleton; |
| 3721 | case Or: |
| 3722 | Py_INCREF(Or_singleton); |
| 3723 | return Or_singleton; |
| 3724 | default: |
| 3725 | /* should never happen, but just in case ... */ |
| 3726 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3727 | return NULL; |
| 3728 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3729 | } |
| 3730 | PyObject* ast2obj_operator(operator_ty o) |
| 3731 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3732 | switch(o) { |
| 3733 | case Add: |
| 3734 | Py_INCREF(Add_singleton); |
| 3735 | return Add_singleton; |
| 3736 | case Sub: |
| 3737 | Py_INCREF(Sub_singleton); |
| 3738 | return Sub_singleton; |
| 3739 | case Mult: |
| 3740 | Py_INCREF(Mult_singleton); |
| 3741 | return Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 3742 | case MatMult: |
| 3743 | Py_INCREF(MatMult_singleton); |
| 3744 | return MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3745 | case Div: |
| 3746 | Py_INCREF(Div_singleton); |
| 3747 | return Div_singleton; |
| 3748 | case Mod: |
| 3749 | Py_INCREF(Mod_singleton); |
| 3750 | return Mod_singleton; |
| 3751 | case Pow: |
| 3752 | Py_INCREF(Pow_singleton); |
| 3753 | return Pow_singleton; |
| 3754 | case LShift: |
| 3755 | Py_INCREF(LShift_singleton); |
| 3756 | return LShift_singleton; |
| 3757 | case RShift: |
| 3758 | Py_INCREF(RShift_singleton); |
| 3759 | return RShift_singleton; |
| 3760 | case BitOr: |
| 3761 | Py_INCREF(BitOr_singleton); |
| 3762 | return BitOr_singleton; |
| 3763 | case BitXor: |
| 3764 | Py_INCREF(BitXor_singleton); |
| 3765 | return BitXor_singleton; |
| 3766 | case BitAnd: |
| 3767 | Py_INCREF(BitAnd_singleton); |
| 3768 | return BitAnd_singleton; |
| 3769 | case FloorDiv: |
| 3770 | Py_INCREF(FloorDiv_singleton); |
| 3771 | return FloorDiv_singleton; |
| 3772 | default: |
| 3773 | /* should never happen, but just in case ... */ |
| 3774 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3775 | return NULL; |
| 3776 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3777 | } |
| 3778 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3779 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3780 | switch(o) { |
| 3781 | case Invert: |
| 3782 | Py_INCREF(Invert_singleton); |
| 3783 | return Invert_singleton; |
| 3784 | case Not: |
| 3785 | Py_INCREF(Not_singleton); |
| 3786 | return Not_singleton; |
| 3787 | case UAdd: |
| 3788 | Py_INCREF(UAdd_singleton); |
| 3789 | return UAdd_singleton; |
| 3790 | case USub: |
| 3791 | Py_INCREF(USub_singleton); |
| 3792 | return USub_singleton; |
| 3793 | default: |
| 3794 | /* should never happen, but just in case ... */ |
| 3795 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3796 | return NULL; |
| 3797 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3798 | } |
| 3799 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3800 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3801 | switch(o) { |
| 3802 | case Eq: |
| 3803 | Py_INCREF(Eq_singleton); |
| 3804 | return Eq_singleton; |
| 3805 | case NotEq: |
| 3806 | Py_INCREF(NotEq_singleton); |
| 3807 | return NotEq_singleton; |
| 3808 | case Lt: |
| 3809 | Py_INCREF(Lt_singleton); |
| 3810 | return Lt_singleton; |
| 3811 | case LtE: |
| 3812 | Py_INCREF(LtE_singleton); |
| 3813 | return LtE_singleton; |
| 3814 | case Gt: |
| 3815 | Py_INCREF(Gt_singleton); |
| 3816 | return Gt_singleton; |
| 3817 | case GtE: |
| 3818 | Py_INCREF(GtE_singleton); |
| 3819 | return GtE_singleton; |
| 3820 | case Is: |
| 3821 | Py_INCREF(Is_singleton); |
| 3822 | return Is_singleton; |
| 3823 | case IsNot: |
| 3824 | Py_INCREF(IsNot_singleton); |
| 3825 | return IsNot_singleton; |
| 3826 | case In: |
| 3827 | Py_INCREF(In_singleton); |
| 3828 | return In_singleton; |
| 3829 | case NotIn: |
| 3830 | Py_INCREF(NotIn_singleton); |
| 3831 | return NotIn_singleton; |
| 3832 | default: |
| 3833 | /* should never happen, but just in case ... */ |
| 3834 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3835 | return NULL; |
| 3836 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3837 | } |
| 3838 | PyObject* |
| 3839 | ast2obj_comprehension(void* _o) |
| 3840 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3841 | comprehension_ty o = (comprehension_ty)_o; |
| 3842 | PyObject *result = NULL, *value = NULL; |
| 3843 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3844 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3845 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3846 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3847 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3848 | if (!result) return NULL; |
| 3849 | value = ast2obj_expr(o->target); |
| 3850 | if (!value) goto failed; |
| 3851 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 3852 | goto failed; |
| 3853 | Py_DECREF(value); |
| 3854 | value = ast2obj_expr(o->iter); |
| 3855 | if (!value) goto failed; |
| 3856 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 3857 | goto failed; |
| 3858 | Py_DECREF(value); |
| 3859 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3860 | if (!value) goto failed; |
| 3861 | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
| 3862 | goto failed; |
| 3863 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3864 | value = ast2obj_int(o->is_async); |
| 3865 | if (!value) goto failed; |
| 3866 | if (_PyObject_SetAttrId(result, &PyId_is_async, value) == -1) |
| 3867 | goto failed; |
| 3868 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3869 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3870 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3871 | Py_XDECREF(value); |
| 3872 | Py_XDECREF(result); |
| 3873 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3874 | } |
| 3875 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3876 | PyObject* |
| 3877 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3878 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3879 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3880 | PyObject *result = NULL, *value = NULL; |
| 3881 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3882 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3883 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3884 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3885 | switch (o->kind) { |
| 3886 | case ExceptHandler_kind: |
| 3887 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3888 | if (!result) goto failed; |
| 3889 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3890 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3891 | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
| 3892 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3893 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3894 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3895 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3896 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3897 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3898 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3899 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3900 | if (!value) goto failed; |
| 3901 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3902 | goto failed; |
| 3903 | Py_DECREF(value); |
| 3904 | break; |
| 3905 | } |
| 3906 | value = ast2obj_int(o->lineno); |
| 3907 | if (!value) goto failed; |
| 3908 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3909 | goto failed; |
| 3910 | Py_DECREF(value); |
| 3911 | value = ast2obj_int(o->col_offset); |
| 3912 | if (!value) goto failed; |
| 3913 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3914 | goto failed; |
| 3915 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3916 | value = ast2obj_int(o->end_lineno); |
| 3917 | if (!value) goto failed; |
| 3918 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3919 | goto failed; |
| 3920 | Py_DECREF(value); |
| 3921 | value = ast2obj_int(o->end_col_offset); |
| 3922 | if (!value) goto failed; |
| 3923 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3924 | goto failed; |
| 3925 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3926 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3927 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3928 | Py_XDECREF(value); |
| 3929 | Py_XDECREF(result); |
| 3930 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3931 | } |
| 3932 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3933 | PyObject* |
| 3934 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3935 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3936 | arguments_ty o = (arguments_ty)_o; |
| 3937 | PyObject *result = NULL, *value = NULL; |
| 3938 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3939 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3940 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3941 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3942 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3943 | if (!result) return NULL; |
| 3944 | value = ast2obj_list(o->args, ast2obj_arg); |
| 3945 | if (!value) goto failed; |
| 3946 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3947 | goto failed; |
| 3948 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3949 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3950 | if (!value) goto failed; |
| 3951 | if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) |
| 3952 | goto failed; |
| 3953 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3954 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 3955 | if (!value) goto failed; |
| 3956 | if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) |
| 3957 | goto failed; |
| 3958 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3959 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3960 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3961 | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3962 | goto failed; |
| 3963 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3964 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3965 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3966 | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3967 | goto failed; |
| 3968 | Py_DECREF(value); |
| 3969 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3970 | if (!value) goto failed; |
| 3971 | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
| 3972 | goto failed; |
| 3973 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3974 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3975 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3976 | Py_XDECREF(value); |
| 3977 | Py_XDECREF(result); |
| 3978 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3979 | } |
| 3980 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3981 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3982 | ast2obj_arg(void* _o) |
| 3983 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3984 | arg_ty o = (arg_ty)_o; |
| 3985 | PyObject *result = NULL, *value = NULL; |
| 3986 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3987 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3988 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3989 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3990 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3991 | if (!result) return NULL; |
| 3992 | value = ast2obj_identifier(o->arg); |
| 3993 | if (!value) goto failed; |
| 3994 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 3995 | goto failed; |
| 3996 | Py_DECREF(value); |
| 3997 | value = ast2obj_expr(o->annotation); |
| 3998 | if (!value) goto failed; |
| 3999 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 4000 | goto failed; |
| 4001 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4002 | value = ast2obj_string(o->type_comment); |
| 4003 | if (!value) goto failed; |
| 4004 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 4005 | goto failed; |
| 4006 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4007 | value = ast2obj_int(o->lineno); |
| 4008 | if (!value) goto failed; |
| 4009 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 4010 | goto failed; |
| 4011 | Py_DECREF(value); |
| 4012 | value = ast2obj_int(o->col_offset); |
| 4013 | if (!value) goto failed; |
| 4014 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 4015 | goto failed; |
| 4016 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4017 | value = ast2obj_int(o->end_lineno); |
| 4018 | if (!value) goto failed; |
| 4019 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 4020 | goto failed; |
| 4021 | Py_DECREF(value); |
| 4022 | value = ast2obj_int(o->end_col_offset); |
| 4023 | if (!value) goto failed; |
| 4024 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 4025 | goto failed; |
| 4026 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4027 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4028 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4029 | Py_XDECREF(value); |
| 4030 | Py_XDECREF(result); |
| 4031 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4035 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4036 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4037 | keyword_ty o = (keyword_ty)_o; |
| 4038 | PyObject *result = NULL, *value = NULL; |
| 4039 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4040 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4041 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4042 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4043 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 4044 | if (!result) return NULL; |
| 4045 | value = ast2obj_identifier(o->arg); |
| 4046 | if (!value) goto failed; |
| 4047 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 4048 | goto failed; |
| 4049 | Py_DECREF(value); |
| 4050 | value = ast2obj_expr(o->value); |
| 4051 | if (!value) goto failed; |
| 4052 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 4053 | goto failed; |
| 4054 | Py_DECREF(value); |
| 4055 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4056 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4057 | Py_XDECREF(value); |
| 4058 | Py_XDECREF(result); |
| 4059 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4060 | } |
| 4061 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4062 | PyObject* |
| 4063 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4064 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4065 | alias_ty o = (alias_ty)_o; |
| 4066 | PyObject *result = NULL, *value = NULL; |
| 4067 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4068 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4069 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4070 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4071 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 4072 | if (!result) return NULL; |
| 4073 | value = ast2obj_identifier(o->name); |
| 4074 | if (!value) goto failed; |
| 4075 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 4076 | goto failed; |
| 4077 | Py_DECREF(value); |
| 4078 | value = ast2obj_identifier(o->asname); |
| 4079 | if (!value) goto failed; |
| 4080 | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
| 4081 | goto failed; |
| 4082 | Py_DECREF(value); |
| 4083 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4084 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4085 | Py_XDECREF(value); |
| 4086 | Py_XDECREF(result); |
| 4087 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4088 | } |
| 4089 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4090 | PyObject* |
| 4091 | ast2obj_withitem(void* _o) |
| 4092 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4093 | withitem_ty o = (withitem_ty)_o; |
| 4094 | PyObject *result = NULL, *value = NULL; |
| 4095 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4096 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4097 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4098 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4099 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 4100 | if (!result) return NULL; |
| 4101 | value = ast2obj_expr(o->context_expr); |
| 4102 | if (!value) goto failed; |
| 4103 | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
| 4104 | goto failed; |
| 4105 | Py_DECREF(value); |
| 4106 | value = ast2obj_expr(o->optional_vars); |
| 4107 | if (!value) goto failed; |
| 4108 | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
| 4109 | goto failed; |
| 4110 | Py_DECREF(value); |
| 4111 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4112 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4113 | Py_XDECREF(value); |
| 4114 | Py_XDECREF(result); |
| 4115 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4116 | } |
| 4117 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4118 | PyObject* |
| 4119 | ast2obj_type_ignore(void* _o) |
| 4120 | { |
| 4121 | type_ignore_ty o = (type_ignore_ty)_o; |
| 4122 | PyObject *result = NULL, *value = NULL; |
| 4123 | if (!o) { |
| 4124 | Py_RETURN_NONE; |
| 4125 | } |
| 4126 | |
| 4127 | switch (o->kind) { |
| 4128 | case TypeIgnore_kind: |
| 4129 | result = PyType_GenericNew(TypeIgnore_type, NULL, NULL); |
| 4130 | if (!result) goto failed; |
| 4131 | value = ast2obj_int(o->v.TypeIgnore.lineno); |
| 4132 | if (!value) goto failed; |
| 4133 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) == -1) |
| 4134 | goto failed; |
| 4135 | Py_DECREF(value); |
| 4136 | break; |
| 4137 | } |
| 4138 | return result; |
| 4139 | failed: |
| 4140 | Py_XDECREF(value); |
| 4141 | Py_XDECREF(result); |
| 4142 | return NULL; |
| 4143 | } |
| 4144 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4145 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4146 | int |
| 4147 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 4148 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4149 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4150 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4151 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4152 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4153 | if (obj == Py_None) { |
| 4154 | *out = NULL; |
| 4155 | return 0; |
| 4156 | } |
| 4157 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 4158 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4159 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4160 | } |
| 4161 | if (isinstance) { |
| 4162 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4163 | asdl_seq* type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4164 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4165 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4166 | return 1; |
| 4167 | } |
| 4168 | if (tmp == NULL) { |
| 4169 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 4170 | return 1; |
| 4171 | } |
| 4172 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4173 | int res; |
| 4174 | Py_ssize_t len; |
| 4175 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4176 | if (!PyList_Check(tmp)) { |
| 4177 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4178 | goto failed; |
| 4179 | } |
| 4180 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4181 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4182 | if (body == NULL) goto failed; |
| 4183 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4184 | stmt_ty val; |
| 4185 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4186 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4187 | if (len != PyList_GET_SIZE(tmp)) { |
| 4188 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 4189 | goto failed; |
| 4190 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4191 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4192 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4193 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4194 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4195 | if (_PyObject_LookupAttrId(obj, &PyId_type_ignores, &tmp) < 0) { |
| 4196 | return 1; |
| 4197 | } |
| 4198 | if (tmp == NULL) { |
| 4199 | PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module"); |
| 4200 | return 1; |
| 4201 | } |
| 4202 | else { |
| 4203 | int res; |
| 4204 | Py_ssize_t len; |
| 4205 | Py_ssize_t i; |
| 4206 | if (!PyList_Check(tmp)) { |
| 4207 | PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4208 | goto failed; |
| 4209 | } |
| 4210 | len = PyList_GET_SIZE(tmp); |
| 4211 | type_ignores = _Py_asdl_seq_new(len, arena); |
| 4212 | if (type_ignores == NULL) goto failed; |
| 4213 | for (i = 0; i < len; i++) { |
| 4214 | type_ignore_ty val; |
| 4215 | res = obj2ast_type_ignore(PyList_GET_ITEM(tmp, i), &val, arena); |
| 4216 | if (res != 0) goto failed; |
| 4217 | if (len != PyList_GET_SIZE(tmp)) { |
| 4218 | PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration"); |
| 4219 | goto failed; |
| 4220 | } |
| 4221 | asdl_seq_SET(type_ignores, i, val); |
| 4222 | } |
| 4223 | Py_CLEAR(tmp); |
| 4224 | } |
| 4225 | *out = Module(body, type_ignores, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4226 | if (*out == NULL) goto failed; |
| 4227 | return 0; |
| 4228 | } |
| 4229 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 4230 | if (isinstance == -1) { |
| 4231 | return 1; |
| 4232 | } |
| 4233 | if (isinstance) { |
| 4234 | asdl_seq* body; |
| 4235 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4236 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4237 | return 1; |
| 4238 | } |
| 4239 | if (tmp == NULL) { |
| 4240 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 4241 | return 1; |
| 4242 | } |
| 4243 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4244 | int res; |
| 4245 | Py_ssize_t len; |
| 4246 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4247 | if (!PyList_Check(tmp)) { |
| 4248 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4249 | goto failed; |
| 4250 | } |
| 4251 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4252 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4253 | if (body == NULL) goto failed; |
| 4254 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4255 | stmt_ty val; |
| 4256 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4257 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4258 | if (len != PyList_GET_SIZE(tmp)) { |
| 4259 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 4260 | goto failed; |
| 4261 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4262 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4263 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4264 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4265 | } |
| 4266 | *out = Interactive(body, arena); |
| 4267 | if (*out == NULL) goto failed; |
| 4268 | return 0; |
| 4269 | } |
| 4270 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 4271 | if (isinstance == -1) { |
| 4272 | return 1; |
| 4273 | } |
| 4274 | if (isinstance) { |
| 4275 | expr_ty body; |
| 4276 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4277 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4278 | return 1; |
| 4279 | } |
| 4280 | if (tmp == NULL) { |
| 4281 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 4282 | return 1; |
| 4283 | } |
| 4284 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4285 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4286 | res = obj2ast_expr(tmp, &body, arena); |
| 4287 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4288 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4289 | } |
| 4290 | *out = Expression(body, arena); |
| 4291 | if (*out == NULL) goto failed; |
| 4292 | return 0; |
| 4293 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4294 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionType_type); |
| 4295 | if (isinstance == -1) { |
| 4296 | return 1; |
| 4297 | } |
| 4298 | if (isinstance) { |
| 4299 | asdl_seq* argtypes; |
| 4300 | expr_ty returns; |
| 4301 | |
| 4302 | if (_PyObject_LookupAttrId(obj, &PyId_argtypes, &tmp) < 0) { |
| 4303 | return 1; |
| 4304 | } |
| 4305 | if (tmp == NULL) { |
| 4306 | PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType"); |
| 4307 | return 1; |
| 4308 | } |
| 4309 | else { |
| 4310 | int res; |
| 4311 | Py_ssize_t len; |
| 4312 | Py_ssize_t i; |
| 4313 | if (!PyList_Check(tmp)) { |
| 4314 | PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4315 | goto failed; |
| 4316 | } |
| 4317 | len = PyList_GET_SIZE(tmp); |
| 4318 | argtypes = _Py_asdl_seq_new(len, arena); |
| 4319 | if (argtypes == NULL) goto failed; |
| 4320 | for (i = 0; i < len; i++) { |
| 4321 | expr_ty val; |
| 4322 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
| 4323 | if (res != 0) goto failed; |
| 4324 | if (len != PyList_GET_SIZE(tmp)) { |
| 4325 | PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration"); |
| 4326 | goto failed; |
| 4327 | } |
| 4328 | asdl_seq_SET(argtypes, i, val); |
| 4329 | } |
| 4330 | Py_CLEAR(tmp); |
| 4331 | } |
| 4332 | if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) { |
| 4333 | return 1; |
| 4334 | } |
| 4335 | if (tmp == NULL) { |
| 4336 | PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType"); |
| 4337 | return 1; |
| 4338 | } |
| 4339 | else { |
| 4340 | int res; |
| 4341 | res = obj2ast_expr(tmp, &returns, arena); |
| 4342 | if (res != 0) goto failed; |
| 4343 | Py_CLEAR(tmp); |
| 4344 | } |
| 4345 | *out = FunctionType(argtypes, returns, arena); |
| 4346 | if (*out == NULL) goto failed; |
| 4347 | return 0; |
| 4348 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4349 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 4350 | if (isinstance == -1) { |
| 4351 | return 1; |
| 4352 | } |
| 4353 | if (isinstance) { |
| 4354 | asdl_seq* body; |
| 4355 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4356 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4357 | return 1; |
| 4358 | } |
| 4359 | if (tmp == NULL) { |
| 4360 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 4361 | return 1; |
| 4362 | } |
| 4363 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4364 | int res; |
| 4365 | Py_ssize_t len; |
| 4366 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4367 | if (!PyList_Check(tmp)) { |
| 4368 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4369 | goto failed; |
| 4370 | } |
| 4371 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4372 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4373 | if (body == NULL) goto failed; |
| 4374 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4375 | stmt_ty val; |
| 4376 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4377 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4378 | if (len != PyList_GET_SIZE(tmp)) { |
| 4379 | PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration"); |
| 4380 | goto failed; |
| 4381 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4382 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4383 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4384 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4385 | } |
| 4386 | *out = Suite(body, arena); |
| 4387 | if (*out == NULL) goto failed; |
| 4388 | return 0; |
| 4389 | } |
| 4390 | |
| 4391 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 4392 | failed: |
| 4393 | Py_XDECREF(tmp); |
| 4394 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4395 | } |
| 4396 | |
| 4397 | int |
| 4398 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 4399 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4400 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4401 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4402 | PyObject *tmp = NULL; |
| 4403 | int lineno; |
| 4404 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4405 | int end_lineno; |
| 4406 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4407 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4408 | if (obj == Py_None) { |
| 4409 | *out = NULL; |
| 4410 | return 0; |
| 4411 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4412 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 4413 | return 1; |
| 4414 | } |
| 4415 | if (tmp == NULL) { |
| 4416 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 4417 | return 1; |
| 4418 | } |
| 4419 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4420 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4421 | res = obj2ast_int(tmp, &lineno, arena); |
| 4422 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4423 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4424 | } |
| 4425 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4426 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4427 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4428 | if (tmp == NULL) { |
| 4429 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 4430 | return 1; |
| 4431 | } |
| 4432 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4433 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4434 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4435 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4436 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4437 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4438 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 4439 | return 1; |
| 4440 | } |
| 4441 | if (tmp == NULL || tmp == Py_None) { |
| 4442 | Py_CLEAR(tmp); |
| 4443 | end_lineno = 0; |
| 4444 | } |
| 4445 | else { |
| 4446 | int res; |
| 4447 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 4448 | if (res != 0) goto failed; |
| 4449 | Py_CLEAR(tmp); |
| 4450 | } |
| 4451 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 4452 | return 1; |
| 4453 | } |
| 4454 | if (tmp == NULL || tmp == Py_None) { |
| 4455 | Py_CLEAR(tmp); |
| 4456 | end_col_offset = 0; |
| 4457 | } |
| 4458 | else { |
| 4459 | int res; |
| 4460 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 4461 | if (res != 0) goto failed; |
| 4462 | Py_CLEAR(tmp); |
| 4463 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4464 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 4465 | if (isinstance == -1) { |
| 4466 | return 1; |
| 4467 | } |
| 4468 | if (isinstance) { |
| 4469 | identifier name; |
| 4470 | arguments_ty args; |
| 4471 | asdl_seq* body; |
| 4472 | asdl_seq* decorator_list; |
| 4473 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4474 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4475 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4476 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4477 | return 1; |
| 4478 | } |
| 4479 | if (tmp == NULL) { |
| 4480 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 4481 | return 1; |
| 4482 | } |
| 4483 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4484 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4485 | res = obj2ast_identifier(tmp, &name, arena); |
| 4486 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4487 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4488 | } |
| 4489 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4490 | return 1; |
| 4491 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4492 | if (tmp == NULL) { |
| 4493 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 4494 | return 1; |
| 4495 | } |
| 4496 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4497 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4498 | res = obj2ast_arguments(tmp, &args, arena); |
| 4499 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4500 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4501 | } |
| 4502 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4503 | return 1; |
| 4504 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4505 | if (tmp == NULL) { |
| 4506 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 4507 | return 1; |
| 4508 | } |
| 4509 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4510 | int res; |
| 4511 | Py_ssize_t len; |
| 4512 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4513 | if (!PyList_Check(tmp)) { |
| 4514 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4515 | goto failed; |
| 4516 | } |
| 4517 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4518 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4519 | if (body == NULL) goto failed; |
| 4520 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4521 | stmt_ty val; |
| 4522 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4523 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4524 | if (len != PyList_GET_SIZE(tmp)) { |
| 4525 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 4526 | goto failed; |
| 4527 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4528 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4529 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4530 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4531 | } |
| 4532 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4533 | return 1; |
| 4534 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4535 | if (tmp == NULL) { |
| 4536 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 4537 | return 1; |
| 4538 | } |
| 4539 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4540 | int res; |
| 4541 | Py_ssize_t len; |
| 4542 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4543 | if (!PyList_Check(tmp)) { |
| 4544 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4545 | goto failed; |
| 4546 | } |
| 4547 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4548 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4549 | if (decorator_list == NULL) goto failed; |
| 4550 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4551 | expr_ty val; |
| 4552 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4553 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4554 | if (len != PyList_GET_SIZE(tmp)) { |
| 4555 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 4556 | goto failed; |
| 4557 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4558 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4559 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4560 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4561 | } |
| 4562 | if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4563 | return 1; |
| 4564 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4565 | if (tmp == NULL || tmp == Py_None) { |
| 4566 | Py_CLEAR(tmp); |
| 4567 | returns = NULL; |
| 4568 | } |
| 4569 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4570 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4571 | res = obj2ast_expr(tmp, &returns, arena); |
| 4572 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4573 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4574 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4575 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 4576 | return 1; |
| 4577 | } |
| 4578 | if (tmp == NULL || tmp == Py_None) { |
| 4579 | Py_CLEAR(tmp); |
| 4580 | type_comment = NULL; |
| 4581 | } |
| 4582 | else { |
| 4583 | int res; |
| 4584 | res = obj2ast_string(tmp, &type_comment, arena); |
| 4585 | if (res != 0) goto failed; |
| 4586 | Py_CLEAR(tmp); |
| 4587 | } |
| 4588 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 4589 | type_comment, lineno, col_offset, end_lineno, |
| 4590 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4591 | if (*out == NULL) goto failed; |
| 4592 | return 0; |
| 4593 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4594 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFunctionDef_type); |
| 4595 | if (isinstance == -1) { |
| 4596 | return 1; |
| 4597 | } |
| 4598 | if (isinstance) { |
| 4599 | identifier name; |
| 4600 | arguments_ty args; |
| 4601 | asdl_seq* body; |
| 4602 | asdl_seq* decorator_list; |
| 4603 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4604 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4605 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4606 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4607 | return 1; |
| 4608 | } |
| 4609 | if (tmp == NULL) { |
| 4610 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 4611 | return 1; |
| 4612 | } |
| 4613 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4614 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4615 | res = obj2ast_identifier(tmp, &name, arena); |
| 4616 | if (res != 0) goto failed; |
| 4617 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4618 | } |
| 4619 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4620 | return 1; |
| 4621 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4622 | if (tmp == NULL) { |
| 4623 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 4624 | return 1; |
| 4625 | } |
| 4626 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4627 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4628 | res = obj2ast_arguments(tmp, &args, arena); |
| 4629 | if (res != 0) goto failed; |
| 4630 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4631 | } |
| 4632 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4633 | return 1; |
| 4634 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4635 | if (tmp == NULL) { |
| 4636 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 4637 | return 1; |
| 4638 | } |
| 4639 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4640 | int res; |
| 4641 | Py_ssize_t len; |
| 4642 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4643 | if (!PyList_Check(tmp)) { |
| 4644 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4645 | goto failed; |
| 4646 | } |
| 4647 | len = PyList_GET_SIZE(tmp); |
| 4648 | body = _Py_asdl_seq_new(len, arena); |
| 4649 | if (body == NULL) goto failed; |
| 4650 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4651 | stmt_ty val; |
| 4652 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4653 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4654 | if (len != PyList_GET_SIZE(tmp)) { |
| 4655 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 4656 | goto failed; |
| 4657 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4658 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4659 | } |
| 4660 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4661 | } |
| 4662 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4663 | return 1; |
| 4664 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4665 | if (tmp == NULL) { |
| 4666 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 4667 | return 1; |
| 4668 | } |
| 4669 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4670 | int res; |
| 4671 | Py_ssize_t len; |
| 4672 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4673 | if (!PyList_Check(tmp)) { |
| 4674 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4675 | goto failed; |
| 4676 | } |
| 4677 | len = PyList_GET_SIZE(tmp); |
| 4678 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 4679 | if (decorator_list == NULL) goto failed; |
| 4680 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4681 | expr_ty val; |
| 4682 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4683 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4684 | if (len != PyList_GET_SIZE(tmp)) { |
| 4685 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 4686 | goto failed; |
| 4687 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4688 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4689 | } |
| 4690 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4691 | } |
| 4692 | if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4693 | return 1; |
| 4694 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4695 | if (tmp == NULL || tmp == Py_None) { |
| 4696 | Py_CLEAR(tmp); |
| 4697 | returns = NULL; |
| 4698 | } |
| 4699 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4700 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4701 | res = obj2ast_expr(tmp, &returns, arena); |
| 4702 | if (res != 0) goto failed; |
| 4703 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4704 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4705 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 4706 | return 1; |
| 4707 | } |
| 4708 | if (tmp == NULL || tmp == Py_None) { |
| 4709 | Py_CLEAR(tmp); |
| 4710 | type_comment = NULL; |
| 4711 | } |
| 4712 | else { |
| 4713 | int res; |
| 4714 | res = obj2ast_string(tmp, &type_comment, arena); |
| 4715 | if (res != 0) goto failed; |
| 4716 | Py_CLEAR(tmp); |
| 4717 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4718 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4719 | type_comment, lineno, col_offset, end_lineno, |
| 4720 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4721 | if (*out == NULL) goto failed; |
| 4722 | return 0; |
| 4723 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4724 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 4725 | if (isinstance == -1) { |
| 4726 | return 1; |
| 4727 | } |
| 4728 | if (isinstance) { |
| 4729 | identifier name; |
| 4730 | asdl_seq* bases; |
| 4731 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4732 | asdl_seq* body; |
| 4733 | asdl_seq* decorator_list; |
| 4734 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4735 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4736 | return 1; |
| 4737 | } |
| 4738 | if (tmp == NULL) { |
| 4739 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 4740 | return 1; |
| 4741 | } |
| 4742 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4743 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4744 | res = obj2ast_identifier(tmp, &name, arena); |
| 4745 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4746 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4747 | } |
| 4748 | if (_PyObject_LookupAttrId(obj, &PyId_bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4749 | return 1; |
| 4750 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4751 | if (tmp == NULL) { |
| 4752 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 4753 | return 1; |
| 4754 | } |
| 4755 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4756 | int res; |
| 4757 | Py_ssize_t len; |
| 4758 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4759 | if (!PyList_Check(tmp)) { |
| 4760 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4761 | goto failed; |
| 4762 | } |
| 4763 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4764 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4765 | if (bases == NULL) goto failed; |
| 4766 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4767 | expr_ty val; |
| 4768 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4769 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4770 | if (len != PyList_GET_SIZE(tmp)) { |
| 4771 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 4772 | goto failed; |
| 4773 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4774 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4775 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4776 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4777 | } |
| 4778 | if (_PyObject_LookupAttrId(obj, &PyId_keywords, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4779 | return 1; |
| 4780 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4781 | if (tmp == NULL) { |
| 4782 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 4783 | return 1; |
| 4784 | } |
| 4785 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4786 | int res; |
| 4787 | Py_ssize_t len; |
| 4788 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4789 | if (!PyList_Check(tmp)) { |
| 4790 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4791 | goto failed; |
| 4792 | } |
| 4793 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4794 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4795 | if (keywords == NULL) goto failed; |
| 4796 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4797 | keyword_ty val; |
| 4798 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4799 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4800 | if (len != PyList_GET_SIZE(tmp)) { |
| 4801 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 4802 | goto failed; |
| 4803 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4804 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4805 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4806 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4807 | } |
| 4808 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4809 | return 1; |
| 4810 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4811 | if (tmp == NULL) { |
| 4812 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 4813 | return 1; |
| 4814 | } |
| 4815 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4816 | int res; |
| 4817 | Py_ssize_t len; |
| 4818 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4819 | if (!PyList_Check(tmp)) { |
| 4820 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4821 | goto failed; |
| 4822 | } |
| 4823 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4824 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4825 | if (body == NULL) goto failed; |
| 4826 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4827 | stmt_ty val; |
| 4828 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4829 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4830 | if (len != PyList_GET_SIZE(tmp)) { |
| 4831 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 4832 | goto failed; |
| 4833 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4834 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4835 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4836 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4837 | } |
| 4838 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4839 | return 1; |
| 4840 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4841 | if (tmp == NULL) { |
| 4842 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 4843 | return 1; |
| 4844 | } |
| 4845 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4846 | int res; |
| 4847 | Py_ssize_t len; |
| 4848 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4849 | if (!PyList_Check(tmp)) { |
| 4850 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4851 | goto failed; |
| 4852 | } |
| 4853 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4854 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4855 | if (decorator_list == NULL) goto failed; |
| 4856 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4857 | expr_ty val; |
| 4858 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4859 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4860 | if (len != PyList_GET_SIZE(tmp)) { |
| 4861 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
| 4862 | goto failed; |
| 4863 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4864 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4865 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4866 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4867 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 4868 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4869 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4870 | if (*out == NULL) goto failed; |
| 4871 | return 0; |
| 4872 | } |
| 4873 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 4874 | if (isinstance == -1) { |
| 4875 | return 1; |
| 4876 | } |
| 4877 | if (isinstance) { |
| 4878 | expr_ty value; |
| 4879 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4880 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 4881 | return 1; |
| 4882 | } |
| 4883 | if (tmp == NULL || tmp == Py_None) { |
| 4884 | Py_CLEAR(tmp); |
| 4885 | value = NULL; |
| 4886 | } |
| 4887 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4888 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4889 | res = obj2ast_expr(tmp, &value, arena); |
| 4890 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4891 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4892 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4893 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 4894 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4895 | if (*out == NULL) goto failed; |
| 4896 | return 0; |
| 4897 | } |
| 4898 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 4899 | if (isinstance == -1) { |
| 4900 | return 1; |
| 4901 | } |
| 4902 | if (isinstance) { |
| 4903 | asdl_seq* targets; |
| 4904 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4905 | if (_PyObject_LookupAttrId(obj, &PyId_targets, &tmp) < 0) { |
| 4906 | return 1; |
| 4907 | } |
| 4908 | if (tmp == NULL) { |
| 4909 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 4910 | return 1; |
| 4911 | } |
| 4912 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4913 | int res; |
| 4914 | Py_ssize_t len; |
| 4915 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4916 | if (!PyList_Check(tmp)) { |
| 4917 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4918 | goto failed; |
| 4919 | } |
| 4920 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4921 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4922 | if (targets == NULL) goto failed; |
| 4923 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4924 | expr_ty val; |
| 4925 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4926 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4927 | if (len != PyList_GET_SIZE(tmp)) { |
| 4928 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 4929 | goto failed; |
| 4930 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4931 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4932 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4933 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4934 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4935 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 4936 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4937 | if (*out == NULL) goto failed; |
| 4938 | return 0; |
| 4939 | } |
| 4940 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 4941 | if (isinstance == -1) { |
| 4942 | return 1; |
| 4943 | } |
| 4944 | if (isinstance) { |
| 4945 | asdl_seq* targets; |
| 4946 | expr_ty value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4947 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4948 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4949 | if (_PyObject_LookupAttrId(obj, &PyId_targets, &tmp) < 0) { |
| 4950 | return 1; |
| 4951 | } |
| 4952 | if (tmp == NULL) { |
| 4953 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 4954 | return 1; |
| 4955 | } |
| 4956 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4957 | int res; |
| 4958 | Py_ssize_t len; |
| 4959 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4960 | if (!PyList_Check(tmp)) { |
| 4961 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4962 | goto failed; |
| 4963 | } |
| 4964 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4965 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4966 | if (targets == NULL) goto failed; |
| 4967 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4968 | expr_ty val; |
| 4969 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [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, "Assign field \"targets\" 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(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4976 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4977 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4978 | } |
| 4979 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4980 | return 1; |
| 4981 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4982 | if (tmp == NULL) { |
| 4983 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 4984 | return 1; |
| 4985 | } |
| 4986 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4987 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4988 | res = obj2ast_expr(tmp, &value, arena); |
| 4989 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4990 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4991 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4992 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 4993 | return 1; |
| 4994 | } |
| 4995 | if (tmp == NULL || tmp == Py_None) { |
| 4996 | Py_CLEAR(tmp); |
| 4997 | type_comment = NULL; |
| 4998 | } |
| 4999 | else { |
| 5000 | int res; |
| 5001 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5002 | if (res != 0) goto failed; |
| 5003 | Py_CLEAR(tmp); |
| 5004 | } |
| 5005 | *out = Assign(targets, value, type_comment, lineno, col_offset, |
| 5006 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5007 | if (*out == NULL) goto failed; |
| 5008 | return 0; |
| 5009 | } |
| 5010 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 5011 | if (isinstance == -1) { |
| 5012 | return 1; |
| 5013 | } |
| 5014 | if (isinstance) { |
| 5015 | expr_ty target; |
| 5016 | operator_ty op; |
| 5017 | expr_ty value; |
| 5018 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5019 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5020 | return 1; |
| 5021 | } |
| 5022 | if (tmp == NULL) { |
| 5023 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 5024 | return 1; |
| 5025 | } |
| 5026 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5027 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5028 | res = obj2ast_expr(tmp, &target, arena); |
| 5029 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5030 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5031 | } |
| 5032 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5033 | return 1; |
| 5034 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5035 | if (tmp == NULL) { |
| 5036 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 5037 | return 1; |
| 5038 | } |
| 5039 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5040 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5041 | res = obj2ast_operator(tmp, &op, arena); |
| 5042 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5043 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5044 | } |
| 5045 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5046 | return 1; |
| 5047 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5048 | if (tmp == NULL) { |
| 5049 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 5050 | return 1; |
| 5051 | } |
| 5052 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5053 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5054 | res = obj2ast_expr(tmp, &value, arena); |
| 5055 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5056 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5057 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5058 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 5059 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5060 | if (*out == NULL) goto failed; |
| 5061 | return 0; |
| 5062 | } |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5063 | isinstance = PyObject_IsInstance(obj, (PyObject*)AnnAssign_type); |
| 5064 | if (isinstance == -1) { |
| 5065 | return 1; |
| 5066 | } |
| 5067 | if (isinstance) { |
| 5068 | expr_ty target; |
| 5069 | expr_ty annotation; |
| 5070 | expr_ty value; |
| 5071 | int simple; |
| 5072 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5073 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5074 | return 1; |
| 5075 | } |
| 5076 | if (tmp == NULL) { |
| 5077 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 5078 | return 1; |
| 5079 | } |
| 5080 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5081 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5082 | res = obj2ast_expr(tmp, &target, arena); |
| 5083 | if (res != 0) goto failed; |
| 5084 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5085 | } |
| 5086 | if (_PyObject_LookupAttrId(obj, &PyId_annotation, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5087 | return 1; |
| 5088 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5089 | if (tmp == NULL) { |
| 5090 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 5091 | return 1; |
| 5092 | } |
| 5093 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5094 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5095 | res = obj2ast_expr(tmp, &annotation, arena); |
| 5096 | if (res != 0) goto failed; |
| 5097 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5098 | } |
| 5099 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5100 | return 1; |
| 5101 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5102 | if (tmp == NULL || tmp == Py_None) { |
| 5103 | Py_CLEAR(tmp); |
| 5104 | value = NULL; |
| 5105 | } |
| 5106 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5107 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5108 | res = obj2ast_expr(tmp, &value, arena); |
| 5109 | if (res != 0) goto failed; |
| 5110 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5111 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5112 | if (_PyObject_LookupAttrId(obj, &PyId_simple, &tmp) < 0) { |
| 5113 | return 1; |
| 5114 | } |
| 5115 | if (tmp == NULL) { |
| 5116 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 5117 | return 1; |
| 5118 | } |
| 5119 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5120 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5121 | res = obj2ast_int(tmp, &simple, arena); |
| 5122 | if (res != 0) goto failed; |
| 5123 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5124 | } |
| 5125 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5126 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5127 | if (*out == NULL) goto failed; |
| 5128 | return 0; |
| 5129 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5130 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 5131 | if (isinstance == -1) { |
| 5132 | return 1; |
| 5133 | } |
| 5134 | if (isinstance) { |
| 5135 | expr_ty target; |
| 5136 | expr_ty iter; |
| 5137 | asdl_seq* body; |
| 5138 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5139 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5140 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5141 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5142 | return 1; |
| 5143 | } |
| 5144 | if (tmp == NULL) { |
| 5145 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 5146 | return 1; |
| 5147 | } |
| 5148 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5149 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5150 | res = obj2ast_expr(tmp, &target, arena); |
| 5151 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5152 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5153 | } |
| 5154 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5155 | return 1; |
| 5156 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5157 | if (tmp == NULL) { |
| 5158 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 5159 | return 1; |
| 5160 | } |
| 5161 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5162 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5163 | res = obj2ast_expr(tmp, &iter, arena); |
| 5164 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5165 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5166 | } |
| 5167 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5168 | return 1; |
| 5169 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5170 | if (tmp == NULL) { |
| 5171 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 5172 | return 1; |
| 5173 | } |
| 5174 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5175 | int res; |
| 5176 | Py_ssize_t len; |
| 5177 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5178 | if (!PyList_Check(tmp)) { |
| 5179 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5180 | goto failed; |
| 5181 | } |
| 5182 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5183 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5184 | if (body == NULL) goto failed; |
| 5185 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5186 | stmt_ty val; |
| 5187 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5188 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5189 | if (len != PyList_GET_SIZE(tmp)) { |
| 5190 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 5191 | goto failed; |
| 5192 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5193 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5194 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5195 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5196 | } |
| 5197 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5198 | return 1; |
| 5199 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5200 | if (tmp == NULL) { |
| 5201 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 5202 | return 1; |
| 5203 | } |
| 5204 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5205 | int res; |
| 5206 | Py_ssize_t len; |
| 5207 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5208 | if (!PyList_Check(tmp)) { |
| 5209 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5210 | goto failed; |
| 5211 | } |
| 5212 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5213 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5214 | if (orelse == NULL) goto failed; |
| 5215 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5216 | stmt_ty val; |
| 5217 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5218 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5219 | if (len != PyList_GET_SIZE(tmp)) { |
| 5220 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 5221 | goto failed; |
| 5222 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5223 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5224 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5225 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5226 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5227 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5228 | return 1; |
| 5229 | } |
| 5230 | if (tmp == NULL || tmp == Py_None) { |
| 5231 | Py_CLEAR(tmp); |
| 5232 | type_comment = NULL; |
| 5233 | } |
| 5234 | else { |
| 5235 | int res; |
| 5236 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5237 | if (res != 0) goto failed; |
| 5238 | Py_CLEAR(tmp); |
| 5239 | } |
| 5240 | *out = For(target, iter, body, orelse, type_comment, lineno, |
| 5241 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5242 | if (*out == NULL) goto failed; |
| 5243 | return 0; |
| 5244 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5245 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFor_type); |
| 5246 | if (isinstance == -1) { |
| 5247 | return 1; |
| 5248 | } |
| 5249 | if (isinstance) { |
| 5250 | expr_ty target; |
| 5251 | expr_ty iter; |
| 5252 | asdl_seq* body; |
| 5253 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5254 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5255 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5256 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5257 | return 1; |
| 5258 | } |
| 5259 | if (tmp == NULL) { |
| 5260 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 5261 | return 1; |
| 5262 | } |
| 5263 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5264 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5265 | res = obj2ast_expr(tmp, &target, arena); |
| 5266 | if (res != 0) goto failed; |
| 5267 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5268 | } |
| 5269 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &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 \"iter\" missing from AsyncFor"); |
| 5274 | return 1; |
| 5275 | } |
| 5276 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5277 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5278 | res = obj2ast_expr(tmp, &iter, arena); |
| 5279 | if (res != 0) goto failed; |
| 5280 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5281 | } |
| 5282 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5283 | return 1; |
| 5284 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5285 | if (tmp == NULL) { |
| 5286 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 5287 | return 1; |
| 5288 | } |
| 5289 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5290 | int res; |
| 5291 | Py_ssize_t len; |
| 5292 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5293 | if (!PyList_Check(tmp)) { |
| 5294 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5295 | goto failed; |
| 5296 | } |
| 5297 | len = PyList_GET_SIZE(tmp); |
| 5298 | body = _Py_asdl_seq_new(len, arena); |
| 5299 | if (body == NULL) goto failed; |
| 5300 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5301 | stmt_ty val; |
| 5302 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5303 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5304 | if (len != PyList_GET_SIZE(tmp)) { |
| 5305 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 5306 | goto failed; |
| 5307 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5308 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5309 | } |
| 5310 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5311 | } |
| 5312 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5313 | return 1; |
| 5314 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5315 | if (tmp == NULL) { |
| 5316 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 5317 | return 1; |
| 5318 | } |
| 5319 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5320 | int res; |
| 5321 | Py_ssize_t len; |
| 5322 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5323 | if (!PyList_Check(tmp)) { |
| 5324 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5325 | goto failed; |
| 5326 | } |
| 5327 | len = PyList_GET_SIZE(tmp); |
| 5328 | orelse = _Py_asdl_seq_new(len, arena); |
| 5329 | if (orelse == NULL) goto failed; |
| 5330 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5331 | stmt_ty val; |
| 5332 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5333 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5334 | if (len != PyList_GET_SIZE(tmp)) { |
| 5335 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 5336 | goto failed; |
| 5337 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5338 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5339 | } |
| 5340 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5341 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5342 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5343 | return 1; |
| 5344 | } |
| 5345 | if (tmp == NULL || tmp == Py_None) { |
| 5346 | Py_CLEAR(tmp); |
| 5347 | type_comment = NULL; |
| 5348 | } |
| 5349 | else { |
| 5350 | int res; |
| 5351 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5352 | if (res != 0) goto failed; |
| 5353 | Py_CLEAR(tmp); |
| 5354 | } |
| 5355 | *out = AsyncFor(target, iter, body, orelse, type_comment, lineno, |
| 5356 | col_offset, end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5357 | if (*out == NULL) goto failed; |
| 5358 | return 0; |
| 5359 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5360 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 5361 | if (isinstance == -1) { |
| 5362 | return 1; |
| 5363 | } |
| 5364 | if (isinstance) { |
| 5365 | expr_ty test; |
| 5366 | asdl_seq* body; |
| 5367 | asdl_seq* orelse; |
| 5368 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5369 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 5370 | return 1; |
| 5371 | } |
| 5372 | if (tmp == NULL) { |
| 5373 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 5374 | return 1; |
| 5375 | } |
| 5376 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5377 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5378 | res = obj2ast_expr(tmp, &test, arena); |
| 5379 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5380 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5381 | } |
| 5382 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5383 | return 1; |
| 5384 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5385 | if (tmp == NULL) { |
| 5386 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 5387 | return 1; |
| 5388 | } |
| 5389 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5390 | int res; |
| 5391 | Py_ssize_t len; |
| 5392 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5393 | if (!PyList_Check(tmp)) { |
| 5394 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5395 | goto failed; |
| 5396 | } |
| 5397 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5398 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5399 | if (body == NULL) goto failed; |
| 5400 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5401 | stmt_ty val; |
| 5402 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5403 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5404 | if (len != PyList_GET_SIZE(tmp)) { |
| 5405 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 5406 | goto failed; |
| 5407 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5408 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5409 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5410 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5411 | } |
| 5412 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5413 | return 1; |
| 5414 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5415 | if (tmp == NULL) { |
| 5416 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 5417 | return 1; |
| 5418 | } |
| 5419 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5420 | int res; |
| 5421 | Py_ssize_t len; |
| 5422 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5423 | if (!PyList_Check(tmp)) { |
| 5424 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5425 | goto failed; |
| 5426 | } |
| 5427 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5428 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5429 | if (orelse == NULL) goto failed; |
| 5430 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5431 | stmt_ty val; |
| 5432 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5433 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5434 | if (len != PyList_GET_SIZE(tmp)) { |
| 5435 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 5436 | goto failed; |
| 5437 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5438 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5439 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5440 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5441 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5442 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 5443 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5444 | if (*out == NULL) goto failed; |
| 5445 | return 0; |
| 5446 | } |
| 5447 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 5448 | if (isinstance == -1) { |
| 5449 | return 1; |
| 5450 | } |
| 5451 | if (isinstance) { |
| 5452 | expr_ty test; |
| 5453 | asdl_seq* body; |
| 5454 | asdl_seq* orelse; |
| 5455 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5456 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 5457 | return 1; |
| 5458 | } |
| 5459 | if (tmp == NULL) { |
| 5460 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 5461 | return 1; |
| 5462 | } |
| 5463 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5464 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5465 | res = obj2ast_expr(tmp, &test, arena); |
| 5466 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5467 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5468 | } |
| 5469 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5470 | return 1; |
| 5471 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5472 | if (tmp == NULL) { |
| 5473 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 5474 | return 1; |
| 5475 | } |
| 5476 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5477 | int res; |
| 5478 | Py_ssize_t len; |
| 5479 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5480 | if (!PyList_Check(tmp)) { |
| 5481 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5482 | goto failed; |
| 5483 | } |
| 5484 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5485 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5486 | if (body == NULL) goto failed; |
| 5487 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5488 | stmt_ty val; |
| 5489 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5490 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5491 | if (len != PyList_GET_SIZE(tmp)) { |
| 5492 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 5493 | goto failed; |
| 5494 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5495 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5496 | } |
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_orelse, &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) { |
| 5503 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 5504 | return 1; |
| 5505 | } |
| 5506 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5507 | int res; |
| 5508 | Py_ssize_t len; |
| 5509 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5510 | if (!PyList_Check(tmp)) { |
| 5511 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5512 | goto failed; |
| 5513 | } |
| 5514 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5515 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5516 | if (orelse == NULL) goto failed; |
| 5517 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5518 | stmt_ty val; |
| 5519 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5520 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5521 | if (len != PyList_GET_SIZE(tmp)) { |
| 5522 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 5523 | goto failed; |
| 5524 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5525 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5526 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5527 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5528 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5529 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 5530 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5531 | if (*out == NULL) goto failed; |
| 5532 | return 0; |
| 5533 | } |
| 5534 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 5535 | if (isinstance == -1) { |
| 5536 | return 1; |
| 5537 | } |
| 5538 | if (isinstance) { |
| 5539 | asdl_seq* items; |
| 5540 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5541 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5542 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5543 | if (_PyObject_LookupAttrId(obj, &PyId_items, &tmp) < 0) { |
| 5544 | return 1; |
| 5545 | } |
| 5546 | if (tmp == NULL) { |
| 5547 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 5548 | return 1; |
| 5549 | } |
| 5550 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5551 | int res; |
| 5552 | Py_ssize_t len; |
| 5553 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5554 | if (!PyList_Check(tmp)) { |
| 5555 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5556 | goto failed; |
| 5557 | } |
| 5558 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5559 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5560 | if (items == NULL) goto failed; |
| 5561 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5562 | withitem_ty val; |
| 5563 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5564 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5565 | if (len != PyList_GET_SIZE(tmp)) { |
| 5566 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 5567 | goto failed; |
| 5568 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5569 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5570 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5571 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5572 | } |
| 5573 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5574 | return 1; |
| 5575 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5576 | if (tmp == NULL) { |
| 5577 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 5578 | return 1; |
| 5579 | } |
| 5580 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5581 | int res; |
| 5582 | Py_ssize_t len; |
| 5583 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5584 | if (!PyList_Check(tmp)) { |
| 5585 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5586 | goto failed; |
| 5587 | } |
| 5588 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5589 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5590 | if (body == NULL) goto failed; |
| 5591 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5592 | stmt_ty val; |
| 5593 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5594 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5595 | if (len != PyList_GET_SIZE(tmp)) { |
| 5596 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 5597 | goto failed; |
| 5598 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5599 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5600 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5601 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5602 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5603 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5604 | return 1; |
| 5605 | } |
| 5606 | if (tmp == NULL || tmp == Py_None) { |
| 5607 | Py_CLEAR(tmp); |
| 5608 | type_comment = NULL; |
| 5609 | } |
| 5610 | else { |
| 5611 | int res; |
| 5612 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5613 | if (res != 0) goto failed; |
| 5614 | Py_CLEAR(tmp); |
| 5615 | } |
| 5616 | *out = With(items, body, type_comment, lineno, col_offset, end_lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5617 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5618 | if (*out == NULL) goto failed; |
| 5619 | return 0; |
| 5620 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5621 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncWith_type); |
| 5622 | if (isinstance == -1) { |
| 5623 | return 1; |
| 5624 | } |
| 5625 | if (isinstance) { |
| 5626 | asdl_seq* items; |
| 5627 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5628 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5629 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5630 | if (_PyObject_LookupAttrId(obj, &PyId_items, &tmp) < 0) { |
| 5631 | return 1; |
| 5632 | } |
| 5633 | if (tmp == NULL) { |
| 5634 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 5635 | return 1; |
| 5636 | } |
| 5637 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5638 | int res; |
| 5639 | Py_ssize_t len; |
| 5640 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5641 | if (!PyList_Check(tmp)) { |
| 5642 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5643 | goto failed; |
| 5644 | } |
| 5645 | len = PyList_GET_SIZE(tmp); |
| 5646 | items = _Py_asdl_seq_new(len, arena); |
| 5647 | if (items == NULL) goto failed; |
| 5648 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5649 | withitem_ty val; |
| 5650 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5651 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5652 | if (len != PyList_GET_SIZE(tmp)) { |
| 5653 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 5654 | goto failed; |
| 5655 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5656 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5657 | } |
| 5658 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5659 | } |
| 5660 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5661 | return 1; |
| 5662 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5663 | if (tmp == NULL) { |
| 5664 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 5665 | return 1; |
| 5666 | } |
| 5667 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5668 | int res; |
| 5669 | Py_ssize_t len; |
| 5670 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5671 | if (!PyList_Check(tmp)) { |
| 5672 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5673 | goto failed; |
| 5674 | } |
| 5675 | len = PyList_GET_SIZE(tmp); |
| 5676 | body = _Py_asdl_seq_new(len, arena); |
| 5677 | if (body == NULL) goto failed; |
| 5678 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5679 | stmt_ty val; |
| 5680 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5681 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5682 | if (len != PyList_GET_SIZE(tmp)) { |
| 5683 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 5684 | goto failed; |
| 5685 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5686 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5687 | } |
| 5688 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5689 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5690 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5691 | return 1; |
| 5692 | } |
| 5693 | if (tmp == NULL || tmp == Py_None) { |
| 5694 | Py_CLEAR(tmp); |
| 5695 | type_comment = NULL; |
| 5696 | } |
| 5697 | else { |
| 5698 | int res; |
| 5699 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5700 | if (res != 0) goto failed; |
| 5701 | Py_CLEAR(tmp); |
| 5702 | } |
| 5703 | *out = AsyncWith(items, body, type_comment, lineno, col_offset, |
| 5704 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5705 | if (*out == NULL) goto failed; |
| 5706 | return 0; |
| 5707 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5708 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 5709 | if (isinstance == -1) { |
| 5710 | return 1; |
| 5711 | } |
| 5712 | if (isinstance) { |
| 5713 | expr_ty exc; |
| 5714 | expr_ty cause; |
| 5715 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5716 | if (_PyObject_LookupAttrId(obj, &PyId_exc, &tmp) < 0) { |
| 5717 | return 1; |
| 5718 | } |
| 5719 | if (tmp == NULL || tmp == Py_None) { |
| 5720 | Py_CLEAR(tmp); |
| 5721 | exc = NULL; |
| 5722 | } |
| 5723 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5724 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5725 | res = obj2ast_expr(tmp, &exc, arena); |
| 5726 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5727 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5728 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5729 | if (_PyObject_LookupAttrId(obj, &PyId_cause, &tmp) < 0) { |
| 5730 | return 1; |
| 5731 | } |
| 5732 | if (tmp == NULL || tmp == Py_None) { |
| 5733 | Py_CLEAR(tmp); |
| 5734 | cause = NULL; |
| 5735 | } |
| 5736 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5737 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5738 | res = obj2ast_expr(tmp, &cause, arena); |
| 5739 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5740 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5741 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5742 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 5743 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5744 | if (*out == NULL) goto failed; |
| 5745 | return 0; |
| 5746 | } |
| 5747 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
| 5748 | if (isinstance == -1) { |
| 5749 | return 1; |
| 5750 | } |
| 5751 | if (isinstance) { |
| 5752 | asdl_seq* body; |
| 5753 | asdl_seq* handlers; |
| 5754 | asdl_seq* orelse; |
| 5755 | asdl_seq* finalbody; |
| 5756 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5757 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 5758 | return 1; |
| 5759 | } |
| 5760 | if (tmp == NULL) { |
| 5761 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 5762 | return 1; |
| 5763 | } |
| 5764 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5765 | int res; |
| 5766 | Py_ssize_t len; |
| 5767 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5768 | if (!PyList_Check(tmp)) { |
| 5769 | PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5770 | goto failed; |
| 5771 | } |
| 5772 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5773 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5774 | if (body == NULL) goto failed; |
| 5775 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5776 | stmt_ty val; |
| 5777 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5778 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5779 | if (len != PyList_GET_SIZE(tmp)) { |
| 5780 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 5781 | goto failed; |
| 5782 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5783 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5784 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5785 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5786 | } |
| 5787 | if (_PyObject_LookupAttrId(obj, &PyId_handlers, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5788 | return 1; |
| 5789 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5790 | if (tmp == NULL) { |
| 5791 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 5792 | return 1; |
| 5793 | } |
| 5794 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5795 | int res; |
| 5796 | Py_ssize_t len; |
| 5797 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5798 | if (!PyList_Check(tmp)) { |
| 5799 | PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5800 | goto failed; |
| 5801 | } |
| 5802 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5803 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5804 | if (handlers == NULL) goto failed; |
| 5805 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5806 | excepthandler_ty val; |
| 5807 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5808 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5809 | if (len != PyList_GET_SIZE(tmp)) { |
| 5810 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 5811 | goto failed; |
| 5812 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5813 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5814 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5815 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5816 | } |
| 5817 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5818 | return 1; |
| 5819 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5820 | if (tmp == NULL) { |
| 5821 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 5822 | return 1; |
| 5823 | } |
| 5824 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5825 | int res; |
| 5826 | Py_ssize_t len; |
| 5827 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5828 | if (!PyList_Check(tmp)) { |
| 5829 | PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5830 | goto failed; |
| 5831 | } |
| 5832 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5833 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5834 | if (orelse == NULL) goto failed; |
| 5835 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5836 | stmt_ty val; |
| 5837 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5838 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5839 | if (len != PyList_GET_SIZE(tmp)) { |
| 5840 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 5841 | goto failed; |
| 5842 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5843 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5844 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5845 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5846 | } |
| 5847 | if (_PyObject_LookupAttrId(obj, &PyId_finalbody, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5848 | return 1; |
| 5849 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5850 | if (tmp == NULL) { |
| 5851 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 5852 | return 1; |
| 5853 | } |
| 5854 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5855 | int res; |
| 5856 | Py_ssize_t len; |
| 5857 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5858 | if (!PyList_Check(tmp)) { |
| 5859 | PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5860 | goto failed; |
| 5861 | } |
| 5862 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5863 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5864 | if (finalbody == NULL) goto failed; |
| 5865 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5866 | stmt_ty val; |
| 5867 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5868 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5869 | if (len != PyList_GET_SIZE(tmp)) { |
| 5870 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 5871 | goto failed; |
| 5872 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5873 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5874 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5875 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5876 | } |
| 5877 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5878 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5879 | if (*out == NULL) goto failed; |
| 5880 | return 0; |
| 5881 | } |
| 5882 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 5883 | if (isinstance == -1) { |
| 5884 | return 1; |
| 5885 | } |
| 5886 | if (isinstance) { |
| 5887 | expr_ty test; |
| 5888 | expr_ty msg; |
| 5889 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5890 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 5891 | return 1; |
| 5892 | } |
| 5893 | if (tmp == NULL) { |
| 5894 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 5895 | return 1; |
| 5896 | } |
| 5897 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5898 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5899 | res = obj2ast_expr(tmp, &test, arena); |
| 5900 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5901 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5902 | } |
| 5903 | if (_PyObject_LookupAttrId(obj, &PyId_msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5904 | return 1; |
| 5905 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5906 | if (tmp == NULL || tmp == Py_None) { |
| 5907 | Py_CLEAR(tmp); |
| 5908 | msg = NULL; |
| 5909 | } |
| 5910 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5911 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5912 | res = obj2ast_expr(tmp, &msg, arena); |
| 5913 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5914 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5915 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5916 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 5917 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5918 | if (*out == NULL) goto failed; |
| 5919 | return 0; |
| 5920 | } |
| 5921 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 5922 | if (isinstance == -1) { |
| 5923 | return 1; |
| 5924 | } |
| 5925 | if (isinstance) { |
| 5926 | asdl_seq* names; |
| 5927 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5928 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 5929 | return 1; |
| 5930 | } |
| 5931 | if (tmp == NULL) { |
| 5932 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 5933 | return 1; |
| 5934 | } |
| 5935 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5936 | int res; |
| 5937 | Py_ssize_t len; |
| 5938 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5939 | if (!PyList_Check(tmp)) { |
| 5940 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5941 | goto failed; |
| 5942 | } |
| 5943 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5944 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5945 | if (names == NULL) goto failed; |
| 5946 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5947 | alias_ty val; |
| 5948 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5949 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5950 | if (len != PyList_GET_SIZE(tmp)) { |
| 5951 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 5952 | goto failed; |
| 5953 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5954 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5955 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5956 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5957 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5958 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 5959 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5960 | if (*out == NULL) goto failed; |
| 5961 | return 0; |
| 5962 | } |
| 5963 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 5964 | if (isinstance == -1) { |
| 5965 | return 1; |
| 5966 | } |
| 5967 | if (isinstance) { |
| 5968 | identifier module; |
| 5969 | asdl_seq* names; |
| 5970 | int level; |
| 5971 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5972 | if (_PyObject_LookupAttrId(obj, &PyId_module, &tmp) < 0) { |
| 5973 | return 1; |
| 5974 | } |
| 5975 | if (tmp == NULL || tmp == Py_None) { |
| 5976 | Py_CLEAR(tmp); |
| 5977 | module = NULL; |
| 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_identifier(tmp, &module, 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 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5985 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 5986 | return 1; |
| 5987 | } |
| 5988 | if (tmp == NULL) { |
| 5989 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 5990 | return 1; |
| 5991 | } |
| 5992 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5993 | int res; |
| 5994 | Py_ssize_t len; |
| 5995 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5996 | if (!PyList_Check(tmp)) { |
| 5997 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5998 | goto failed; |
| 5999 | } |
| 6000 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6001 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6002 | if (names == NULL) goto failed; |
| 6003 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6004 | alias_ty val; |
| 6005 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6006 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6007 | if (len != PyList_GET_SIZE(tmp)) { |
| 6008 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 6009 | goto failed; |
| 6010 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6011 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6012 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6013 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6014 | } |
| 6015 | if (_PyObject_LookupAttrId(obj, &PyId_level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6016 | return 1; |
| 6017 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6018 | if (tmp == NULL || tmp == Py_None) { |
| 6019 | Py_CLEAR(tmp); |
| 6020 | level = 0; |
| 6021 | } |
| 6022 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6023 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6024 | res = obj2ast_int(tmp, &level, arena); |
| 6025 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6026 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6027 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6028 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 6029 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6030 | if (*out == NULL) goto failed; |
| 6031 | return 0; |
| 6032 | } |
| 6033 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 6034 | if (isinstance == -1) { |
| 6035 | return 1; |
| 6036 | } |
| 6037 | if (isinstance) { |
| 6038 | asdl_seq* names; |
| 6039 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6040 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 6041 | return 1; |
| 6042 | } |
| 6043 | if (tmp == NULL) { |
| 6044 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 6045 | return 1; |
| 6046 | } |
| 6047 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6048 | int res; |
| 6049 | Py_ssize_t len; |
| 6050 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6051 | if (!PyList_Check(tmp)) { |
| 6052 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6053 | goto failed; |
| 6054 | } |
| 6055 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6056 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6057 | if (names == NULL) goto failed; |
| 6058 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6059 | identifier val; |
| 6060 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6061 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6062 | if (len != PyList_GET_SIZE(tmp)) { |
| 6063 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 6064 | goto failed; |
| 6065 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6066 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6067 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6068 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6069 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6070 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6071 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6072 | if (*out == NULL) goto failed; |
| 6073 | return 0; |
| 6074 | } |
| 6075 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 6076 | if (isinstance == -1) { |
| 6077 | return 1; |
| 6078 | } |
| 6079 | if (isinstance) { |
| 6080 | asdl_seq* names; |
| 6081 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6082 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 6083 | return 1; |
| 6084 | } |
| 6085 | if (tmp == NULL) { |
| 6086 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 6087 | return 1; |
| 6088 | } |
| 6089 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6090 | int res; |
| 6091 | Py_ssize_t len; |
| 6092 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6093 | if (!PyList_Check(tmp)) { |
| 6094 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6095 | goto failed; |
| 6096 | } |
| 6097 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6098 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6099 | if (names == NULL) goto failed; |
| 6100 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6101 | identifier val; |
| 6102 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6103 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6104 | if (len != PyList_GET_SIZE(tmp)) { |
| 6105 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 6106 | goto failed; |
| 6107 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6108 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6109 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6110 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6111 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6112 | *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6113 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6114 | if (*out == NULL) goto failed; |
| 6115 | return 0; |
| 6116 | } |
| 6117 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 6118 | if (isinstance == -1) { |
| 6119 | return 1; |
| 6120 | } |
| 6121 | if (isinstance) { |
| 6122 | expr_ty value; |
| 6123 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6124 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6125 | return 1; |
| 6126 | } |
| 6127 | if (tmp == NULL) { |
| 6128 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 6129 | return 1; |
| 6130 | } |
| 6131 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6132 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6133 | res = obj2ast_expr(tmp, &value, arena); |
| 6134 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6135 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6136 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6137 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6138 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6139 | if (*out == NULL) goto failed; |
| 6140 | return 0; |
| 6141 | } |
| 6142 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 6143 | if (isinstance == -1) { |
| 6144 | return 1; |
| 6145 | } |
| 6146 | if (isinstance) { |
| 6147 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6148 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6149 | if (*out == NULL) goto failed; |
| 6150 | return 0; |
| 6151 | } |
| 6152 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 6153 | if (isinstance == -1) { |
| 6154 | return 1; |
| 6155 | } |
| 6156 | if (isinstance) { |
| 6157 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6158 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6159 | if (*out == NULL) goto failed; |
| 6160 | return 0; |
| 6161 | } |
| 6162 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 6163 | if (isinstance == -1) { |
| 6164 | return 1; |
| 6165 | } |
| 6166 | if (isinstance) { |
| 6167 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6168 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6169 | if (*out == NULL) goto failed; |
| 6170 | return 0; |
| 6171 | } |
| 6172 | |
| 6173 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 6174 | failed: |
| 6175 | Py_XDECREF(tmp); |
| 6176 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6177 | } |
| 6178 | |
| 6179 | int |
| 6180 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 6181 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6182 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6183 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6184 | PyObject *tmp = NULL; |
| 6185 | int lineno; |
| 6186 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6187 | int end_lineno; |
| 6188 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6189 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6190 | if (obj == Py_None) { |
| 6191 | *out = NULL; |
| 6192 | return 0; |
| 6193 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6194 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 6195 | return 1; |
| 6196 | } |
| 6197 | if (tmp == NULL) { |
| 6198 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 6199 | return 1; |
| 6200 | } |
| 6201 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6202 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6203 | res = obj2ast_int(tmp, &lineno, arena); |
| 6204 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6205 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6206 | } |
| 6207 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6208 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6209 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6210 | if (tmp == NULL) { |
| 6211 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 6212 | return 1; |
| 6213 | } |
| 6214 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6215 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6216 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6217 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6218 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6219 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6220 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 6221 | return 1; |
| 6222 | } |
| 6223 | if (tmp == NULL || tmp == Py_None) { |
| 6224 | Py_CLEAR(tmp); |
| 6225 | end_lineno = 0; |
| 6226 | } |
| 6227 | else { |
| 6228 | int res; |
| 6229 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 6230 | if (res != 0) goto failed; |
| 6231 | Py_CLEAR(tmp); |
| 6232 | } |
| 6233 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 6234 | return 1; |
| 6235 | } |
| 6236 | if (tmp == NULL || tmp == Py_None) { |
| 6237 | Py_CLEAR(tmp); |
| 6238 | end_col_offset = 0; |
| 6239 | } |
| 6240 | else { |
| 6241 | int res; |
| 6242 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 6243 | if (res != 0) goto failed; |
| 6244 | Py_CLEAR(tmp); |
| 6245 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6246 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 6247 | if (isinstance == -1) { |
| 6248 | return 1; |
| 6249 | } |
| 6250 | if (isinstance) { |
| 6251 | boolop_ty op; |
| 6252 | asdl_seq* values; |
| 6253 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6254 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
| 6255 | return 1; |
| 6256 | } |
| 6257 | if (tmp == NULL) { |
| 6258 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 6259 | return 1; |
| 6260 | } |
| 6261 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6262 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6263 | res = obj2ast_boolop(tmp, &op, arena); |
| 6264 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6265 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6266 | } |
| 6267 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6268 | return 1; |
| 6269 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6270 | if (tmp == NULL) { |
| 6271 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 6272 | return 1; |
| 6273 | } |
| 6274 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6275 | int res; |
| 6276 | Py_ssize_t len; |
| 6277 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6278 | if (!PyList_Check(tmp)) { |
| 6279 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6280 | goto failed; |
| 6281 | } |
| 6282 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6283 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6284 | if (values == NULL) goto failed; |
| 6285 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6286 | expr_ty val; |
| 6287 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6288 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6289 | if (len != PyList_GET_SIZE(tmp)) { |
| 6290 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 6291 | goto failed; |
| 6292 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6293 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6294 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6295 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6296 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6297 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 6298 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6299 | if (*out == NULL) goto failed; |
| 6300 | return 0; |
| 6301 | } |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 6302 | isinstance = PyObject_IsInstance(obj, (PyObject*)NamedExpr_type); |
| 6303 | if (isinstance == -1) { |
| 6304 | return 1; |
| 6305 | } |
| 6306 | if (isinstance) { |
| 6307 | expr_ty target; |
| 6308 | expr_ty value; |
| 6309 | |
| 6310 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 6311 | return 1; |
| 6312 | } |
| 6313 | if (tmp == NULL) { |
| 6314 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); |
| 6315 | return 1; |
| 6316 | } |
| 6317 | else { |
| 6318 | int res; |
| 6319 | res = obj2ast_expr(tmp, &target, arena); |
| 6320 | if (res != 0) goto failed; |
| 6321 | Py_CLEAR(tmp); |
| 6322 | } |
| 6323 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6324 | return 1; |
| 6325 | } |
| 6326 | if (tmp == NULL) { |
| 6327 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); |
| 6328 | return 1; |
| 6329 | } |
| 6330 | else { |
| 6331 | int res; |
| 6332 | res = obj2ast_expr(tmp, &value, arena); |
| 6333 | if (res != 0) goto failed; |
| 6334 | Py_CLEAR(tmp); |
| 6335 | } |
| 6336 | *out = NamedExpr(target, value, lineno, col_offset, end_lineno, |
| 6337 | end_col_offset, arena); |
| 6338 | if (*out == NULL) goto failed; |
| 6339 | return 0; |
| 6340 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6341 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 6342 | if (isinstance == -1) { |
| 6343 | return 1; |
| 6344 | } |
| 6345 | if (isinstance) { |
| 6346 | expr_ty left; |
| 6347 | operator_ty op; |
| 6348 | expr_ty right; |
| 6349 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6350 | if (_PyObject_LookupAttrId(obj, &PyId_left, &tmp) < 0) { |
| 6351 | return 1; |
| 6352 | } |
| 6353 | if (tmp == NULL) { |
| 6354 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 6355 | return 1; |
| 6356 | } |
| 6357 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6358 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6359 | res = obj2ast_expr(tmp, &left, arena); |
| 6360 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6361 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6362 | } |
| 6363 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6364 | return 1; |
| 6365 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6366 | if (tmp == NULL) { |
| 6367 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 6368 | return 1; |
| 6369 | } |
| 6370 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6371 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6372 | res = obj2ast_operator(tmp, &op, arena); |
| 6373 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6374 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6375 | } |
| 6376 | if (_PyObject_LookupAttrId(obj, &PyId_right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6377 | return 1; |
| 6378 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6379 | if (tmp == NULL) { |
| 6380 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 6381 | return 1; |
| 6382 | } |
| 6383 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6384 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6385 | res = obj2ast_expr(tmp, &right, arena); |
| 6386 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6387 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6388 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6389 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 6390 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6391 | if (*out == NULL) goto failed; |
| 6392 | return 0; |
| 6393 | } |
| 6394 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 6395 | if (isinstance == -1) { |
| 6396 | return 1; |
| 6397 | } |
| 6398 | if (isinstance) { |
| 6399 | unaryop_ty op; |
| 6400 | expr_ty operand; |
| 6401 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6402 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
| 6403 | return 1; |
| 6404 | } |
| 6405 | if (tmp == NULL) { |
| 6406 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 6407 | return 1; |
| 6408 | } |
| 6409 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6410 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6411 | res = obj2ast_unaryop(tmp, &op, arena); |
| 6412 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6413 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6414 | } |
| 6415 | if (_PyObject_LookupAttrId(obj, &PyId_operand, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6416 | return 1; |
| 6417 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6418 | if (tmp == NULL) { |
| 6419 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 6420 | return 1; |
| 6421 | } |
| 6422 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6423 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6424 | res = obj2ast_expr(tmp, &operand, arena); |
| 6425 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6426 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6427 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6428 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 6429 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6430 | if (*out == NULL) goto failed; |
| 6431 | return 0; |
| 6432 | } |
| 6433 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 6434 | if (isinstance == -1) { |
| 6435 | return 1; |
| 6436 | } |
| 6437 | if (isinstance) { |
| 6438 | arguments_ty args; |
| 6439 | expr_ty body; |
| 6440 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6441 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
| 6442 | return 1; |
| 6443 | } |
| 6444 | if (tmp == NULL) { |
| 6445 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 6446 | return 1; |
| 6447 | } |
| 6448 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6449 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6450 | res = obj2ast_arguments(tmp, &args, arena); |
| 6451 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6452 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6453 | } |
| 6454 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6455 | return 1; |
| 6456 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6457 | if (tmp == NULL) { |
| 6458 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 6459 | return 1; |
| 6460 | } |
| 6461 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6462 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6463 | res = obj2ast_expr(tmp, &body, arena); |
| 6464 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6465 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6466 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6467 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 6468 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6469 | if (*out == NULL) goto failed; |
| 6470 | return 0; |
| 6471 | } |
| 6472 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 6473 | if (isinstance == -1) { |
| 6474 | return 1; |
| 6475 | } |
| 6476 | if (isinstance) { |
| 6477 | expr_ty test; |
| 6478 | expr_ty body; |
| 6479 | expr_ty orelse; |
| 6480 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6481 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 6482 | return 1; |
| 6483 | } |
| 6484 | if (tmp == NULL) { |
| 6485 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 6486 | return 1; |
| 6487 | } |
| 6488 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6489 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6490 | res = obj2ast_expr(tmp, &test, arena); |
| 6491 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6492 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6493 | } |
| 6494 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6495 | return 1; |
| 6496 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6497 | if (tmp == NULL) { |
| 6498 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 6499 | return 1; |
| 6500 | } |
| 6501 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6502 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6503 | res = obj2ast_expr(tmp, &body, arena); |
| 6504 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6505 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6506 | } |
| 6507 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6508 | return 1; |
| 6509 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6510 | if (tmp == NULL) { |
| 6511 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 6512 | return 1; |
| 6513 | } |
| 6514 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6515 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6516 | res = obj2ast_expr(tmp, &orelse, arena); |
| 6517 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6518 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6519 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6520 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 6521 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6522 | if (*out == NULL) goto failed; |
| 6523 | return 0; |
| 6524 | } |
| 6525 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 6526 | if (isinstance == -1) { |
| 6527 | return 1; |
| 6528 | } |
| 6529 | if (isinstance) { |
| 6530 | asdl_seq* keys; |
| 6531 | asdl_seq* values; |
| 6532 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6533 | if (_PyObject_LookupAttrId(obj, &PyId_keys, &tmp) < 0) { |
| 6534 | return 1; |
| 6535 | } |
| 6536 | if (tmp == NULL) { |
| 6537 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 6538 | return 1; |
| 6539 | } |
| 6540 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6541 | int res; |
| 6542 | Py_ssize_t len; |
| 6543 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6544 | if (!PyList_Check(tmp)) { |
| 6545 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6546 | goto failed; |
| 6547 | } |
| 6548 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6549 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6550 | if (keys == NULL) goto failed; |
| 6551 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6552 | expr_ty val; |
| 6553 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6554 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6555 | if (len != PyList_GET_SIZE(tmp)) { |
| 6556 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 6557 | goto failed; |
| 6558 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6559 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6560 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6561 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6562 | } |
| 6563 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6564 | return 1; |
| 6565 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6566 | if (tmp == NULL) { |
| 6567 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 6568 | return 1; |
| 6569 | } |
| 6570 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6571 | int res; |
| 6572 | Py_ssize_t len; |
| 6573 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6574 | if (!PyList_Check(tmp)) { |
| 6575 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6576 | goto failed; |
| 6577 | } |
| 6578 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6579 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6580 | if (values == NULL) goto failed; |
| 6581 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6582 | expr_ty val; |
| 6583 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6584 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6585 | if (len != PyList_GET_SIZE(tmp)) { |
| 6586 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 6587 | goto failed; |
| 6588 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6589 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6590 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6591 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6592 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6593 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 6594 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6595 | if (*out == NULL) goto failed; |
| 6596 | return 0; |
| 6597 | } |
| 6598 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 6599 | if (isinstance == -1) { |
| 6600 | return 1; |
| 6601 | } |
| 6602 | if (isinstance) { |
| 6603 | asdl_seq* elts; |
| 6604 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6605 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 6606 | return 1; |
| 6607 | } |
| 6608 | if (tmp == NULL) { |
| 6609 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 6610 | return 1; |
| 6611 | } |
| 6612 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6613 | int res; |
| 6614 | Py_ssize_t len; |
| 6615 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6616 | if (!PyList_Check(tmp)) { |
| 6617 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6618 | goto failed; |
| 6619 | } |
| 6620 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6621 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6622 | if (elts == NULL) goto failed; |
| 6623 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6624 | expr_ty val; |
| 6625 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6626 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6627 | if (len != PyList_GET_SIZE(tmp)) { |
| 6628 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 6629 | goto failed; |
| 6630 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6631 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6632 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6633 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6634 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6635 | *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6636 | if (*out == NULL) goto failed; |
| 6637 | return 0; |
| 6638 | } |
| 6639 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 6640 | if (isinstance == -1) { |
| 6641 | return 1; |
| 6642 | } |
| 6643 | if (isinstance) { |
| 6644 | expr_ty elt; |
| 6645 | asdl_seq* generators; |
| 6646 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6647 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6648 | return 1; |
| 6649 | } |
| 6650 | if (tmp == NULL) { |
| 6651 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 6652 | return 1; |
| 6653 | } |
| 6654 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6655 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6656 | res = obj2ast_expr(tmp, &elt, arena); |
| 6657 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6658 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6659 | } |
| 6660 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6661 | return 1; |
| 6662 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6663 | if (tmp == NULL) { |
| 6664 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 6665 | return 1; |
| 6666 | } |
| 6667 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6668 | int res; |
| 6669 | Py_ssize_t len; |
| 6670 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6671 | if (!PyList_Check(tmp)) { |
| 6672 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6673 | goto failed; |
| 6674 | } |
| 6675 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6676 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6677 | if (generators == NULL) goto failed; |
| 6678 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6679 | comprehension_ty val; |
| 6680 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6681 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6682 | if (len != PyList_GET_SIZE(tmp)) { |
| 6683 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 6684 | goto failed; |
| 6685 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6686 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6687 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6688 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6689 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6690 | *out = ListComp(elt, generators, lineno, col_offset, end_lineno, |
| 6691 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6692 | if (*out == NULL) goto failed; |
| 6693 | return 0; |
| 6694 | } |
| 6695 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 6696 | if (isinstance == -1) { |
| 6697 | return 1; |
| 6698 | } |
| 6699 | if (isinstance) { |
| 6700 | expr_ty elt; |
| 6701 | asdl_seq* generators; |
| 6702 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6703 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6704 | return 1; |
| 6705 | } |
| 6706 | if (tmp == NULL) { |
| 6707 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 6708 | return 1; |
| 6709 | } |
| 6710 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6711 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6712 | res = obj2ast_expr(tmp, &elt, arena); |
| 6713 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6714 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6715 | } |
| 6716 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6717 | return 1; |
| 6718 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6719 | if (tmp == NULL) { |
| 6720 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 6721 | return 1; |
| 6722 | } |
| 6723 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6724 | int res; |
| 6725 | Py_ssize_t len; |
| 6726 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6727 | if (!PyList_Check(tmp)) { |
| 6728 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6729 | goto failed; |
| 6730 | } |
| 6731 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6732 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6733 | if (generators == NULL) goto failed; |
| 6734 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6735 | comprehension_ty val; |
| 6736 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6737 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6738 | if (len != PyList_GET_SIZE(tmp)) { |
| 6739 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 6740 | goto failed; |
| 6741 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6742 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6743 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6744 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6745 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6746 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 6747 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6748 | if (*out == NULL) goto failed; |
| 6749 | return 0; |
| 6750 | } |
| 6751 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 6752 | if (isinstance == -1) { |
| 6753 | return 1; |
| 6754 | } |
| 6755 | if (isinstance) { |
| 6756 | expr_ty key; |
| 6757 | expr_ty value; |
| 6758 | asdl_seq* generators; |
| 6759 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6760 | if (_PyObject_LookupAttrId(obj, &PyId_key, &tmp) < 0) { |
| 6761 | return 1; |
| 6762 | } |
| 6763 | if (tmp == NULL) { |
| 6764 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 6765 | return 1; |
| 6766 | } |
| 6767 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6768 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6769 | res = obj2ast_expr(tmp, &key, arena); |
| 6770 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6771 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6772 | } |
| 6773 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6774 | return 1; |
| 6775 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6776 | if (tmp == NULL) { |
| 6777 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 6778 | return 1; |
| 6779 | } |
| 6780 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6781 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6782 | res = obj2ast_expr(tmp, &value, arena); |
| 6783 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6784 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6785 | } |
| 6786 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6787 | return 1; |
| 6788 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6789 | if (tmp == NULL) { |
| 6790 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 6791 | return 1; |
| 6792 | } |
| 6793 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6794 | int res; |
| 6795 | Py_ssize_t len; |
| 6796 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6797 | if (!PyList_Check(tmp)) { |
| 6798 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6799 | goto failed; |
| 6800 | } |
| 6801 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6802 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6803 | if (generators == NULL) goto failed; |
| 6804 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6805 | comprehension_ty val; |
| 6806 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6807 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6808 | if (len != PyList_GET_SIZE(tmp)) { |
| 6809 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 6810 | goto failed; |
| 6811 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6812 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6813 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6814 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6815 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6816 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 6817 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6818 | if (*out == NULL) goto failed; |
| 6819 | return 0; |
| 6820 | } |
| 6821 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 6822 | if (isinstance == -1) { |
| 6823 | return 1; |
| 6824 | } |
| 6825 | if (isinstance) { |
| 6826 | expr_ty elt; |
| 6827 | asdl_seq* generators; |
| 6828 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6829 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6830 | return 1; |
| 6831 | } |
| 6832 | if (tmp == NULL) { |
| 6833 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 6834 | return 1; |
| 6835 | } |
| 6836 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6837 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6838 | res = obj2ast_expr(tmp, &elt, arena); |
| 6839 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6840 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6841 | } |
| 6842 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6843 | return 1; |
| 6844 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6845 | if (tmp == NULL) { |
| 6846 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 6847 | return 1; |
| 6848 | } |
| 6849 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6850 | int res; |
| 6851 | Py_ssize_t len; |
| 6852 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6853 | if (!PyList_Check(tmp)) { |
| 6854 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6855 | goto failed; |
| 6856 | } |
| 6857 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6858 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6859 | if (generators == NULL) goto failed; |
| 6860 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6861 | comprehension_ty val; |
| 6862 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6863 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6864 | if (len != PyList_GET_SIZE(tmp)) { |
| 6865 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 6866 | goto failed; |
| 6867 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6868 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6869 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6870 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6871 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6872 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 6873 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6874 | if (*out == NULL) goto failed; |
| 6875 | return 0; |
| 6876 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6877 | isinstance = PyObject_IsInstance(obj, (PyObject*)Await_type); |
| 6878 | if (isinstance == -1) { |
| 6879 | return 1; |
| 6880 | } |
| 6881 | if (isinstance) { |
| 6882 | expr_ty value; |
| 6883 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6884 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6885 | return 1; |
| 6886 | } |
| 6887 | if (tmp == NULL) { |
| 6888 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 6889 | return 1; |
| 6890 | } |
| 6891 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6892 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6893 | res = obj2ast_expr(tmp, &value, arena); |
| 6894 | if (res != 0) goto failed; |
| 6895 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6896 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6897 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6898 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6899 | if (*out == NULL) goto failed; |
| 6900 | return 0; |
| 6901 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6902 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 6903 | if (isinstance == -1) { |
| 6904 | return 1; |
| 6905 | } |
| 6906 | if (isinstance) { |
| 6907 | expr_ty value; |
| 6908 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6909 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6910 | return 1; |
| 6911 | } |
| 6912 | if (tmp == NULL || tmp == Py_None) { |
| 6913 | Py_CLEAR(tmp); |
| 6914 | value = NULL; |
| 6915 | } |
| 6916 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6917 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6918 | res = obj2ast_expr(tmp, &value, arena); |
| 6919 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6920 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6921 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6922 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6923 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6924 | if (*out == NULL) goto failed; |
| 6925 | return 0; |
| 6926 | } |
| 6927 | isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); |
| 6928 | if (isinstance == -1) { |
| 6929 | return 1; |
| 6930 | } |
| 6931 | if (isinstance) { |
| 6932 | expr_ty value; |
| 6933 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6934 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6935 | return 1; |
| 6936 | } |
| 6937 | if (tmp == NULL) { |
| 6938 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 6939 | return 1; |
| 6940 | } |
| 6941 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6942 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6943 | res = obj2ast_expr(tmp, &value, arena); |
| 6944 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6945 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6946 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6947 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6948 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6949 | if (*out == NULL) goto failed; |
| 6950 | return 0; |
| 6951 | } |
| 6952 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 6953 | if (isinstance == -1) { |
| 6954 | return 1; |
| 6955 | } |
| 6956 | if (isinstance) { |
| 6957 | expr_ty left; |
| 6958 | asdl_int_seq* ops; |
| 6959 | asdl_seq* comparators; |
| 6960 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6961 | if (_PyObject_LookupAttrId(obj, &PyId_left, &tmp) < 0) { |
| 6962 | return 1; |
| 6963 | } |
| 6964 | if (tmp == NULL) { |
| 6965 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 6966 | return 1; |
| 6967 | } |
| 6968 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6969 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6970 | res = obj2ast_expr(tmp, &left, arena); |
| 6971 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6972 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6973 | } |
| 6974 | if (_PyObject_LookupAttrId(obj, &PyId_ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6975 | return 1; |
| 6976 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6977 | if (tmp == NULL) { |
| 6978 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 6979 | return 1; |
| 6980 | } |
| 6981 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6982 | int res; |
| 6983 | Py_ssize_t len; |
| 6984 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6985 | if (!PyList_Check(tmp)) { |
| 6986 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6987 | goto failed; |
| 6988 | } |
| 6989 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6990 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6991 | if (ops == NULL) goto failed; |
| 6992 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6993 | cmpop_ty val; |
| 6994 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6995 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6996 | if (len != PyList_GET_SIZE(tmp)) { |
| 6997 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 6998 | goto failed; |
| 6999 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7000 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7001 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7002 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7003 | } |
| 7004 | if (_PyObject_LookupAttrId(obj, &PyId_comparators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7005 | return 1; |
| 7006 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7007 | if (tmp == NULL) { |
| 7008 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 7009 | return 1; |
| 7010 | } |
| 7011 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7012 | int res; |
| 7013 | Py_ssize_t len; |
| 7014 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7015 | if (!PyList_Check(tmp)) { |
| 7016 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7017 | goto failed; |
| 7018 | } |
| 7019 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7020 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7021 | if (comparators == NULL) goto failed; |
| 7022 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7023 | expr_ty val; |
| 7024 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7025 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7026 | if (len != PyList_GET_SIZE(tmp)) { |
| 7027 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 7028 | goto failed; |
| 7029 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7030 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7031 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7032 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7033 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7034 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 7035 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7036 | if (*out == NULL) goto failed; |
| 7037 | return 0; |
| 7038 | } |
| 7039 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 7040 | if (isinstance == -1) { |
| 7041 | return 1; |
| 7042 | } |
| 7043 | if (isinstance) { |
| 7044 | expr_ty func; |
| 7045 | asdl_seq* args; |
| 7046 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7047 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7048 | if (_PyObject_LookupAttrId(obj, &PyId_func, &tmp) < 0) { |
| 7049 | return 1; |
| 7050 | } |
| 7051 | if (tmp == NULL) { |
| 7052 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 7053 | return 1; |
| 7054 | } |
| 7055 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7056 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7057 | res = obj2ast_expr(tmp, &func, arena); |
| 7058 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7059 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7060 | } |
| 7061 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7062 | return 1; |
| 7063 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7064 | if (tmp == NULL) { |
| 7065 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 7066 | return 1; |
| 7067 | } |
| 7068 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7069 | int res; |
| 7070 | Py_ssize_t len; |
| 7071 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7072 | if (!PyList_Check(tmp)) { |
| 7073 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7074 | goto failed; |
| 7075 | } |
| 7076 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7077 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7078 | if (args == NULL) goto failed; |
| 7079 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7080 | expr_ty val; |
| 7081 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7082 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7083 | if (len != PyList_GET_SIZE(tmp)) { |
| 7084 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 7085 | goto failed; |
| 7086 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7087 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7088 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7089 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7090 | } |
| 7091 | if (_PyObject_LookupAttrId(obj, &PyId_keywords, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7092 | return 1; |
| 7093 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7094 | if (tmp == NULL) { |
| 7095 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 7096 | return 1; |
| 7097 | } |
| 7098 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7099 | int res; |
| 7100 | Py_ssize_t len; |
| 7101 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7102 | if (!PyList_Check(tmp)) { |
| 7103 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7104 | goto failed; |
| 7105 | } |
| 7106 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7107 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7108 | if (keywords == NULL) goto failed; |
| 7109 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7110 | keyword_ty val; |
| 7111 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7112 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7113 | if (len != PyList_GET_SIZE(tmp)) { |
| 7114 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 7115 | goto failed; |
| 7116 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7117 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7118 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7119 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7120 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7121 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 7122 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7123 | if (*out == NULL) goto failed; |
| 7124 | return 0; |
| 7125 | } |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7126 | isinstance = PyObject_IsInstance(obj, (PyObject*)FormattedValue_type); |
| 7127 | if (isinstance == -1) { |
| 7128 | return 1; |
| 7129 | } |
| 7130 | if (isinstance) { |
| 7131 | expr_ty value; |
| 7132 | int conversion; |
| 7133 | expr_ty format_spec; |
| 7134 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7135 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7136 | return 1; |
| 7137 | } |
| 7138 | if (tmp == NULL) { |
| 7139 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 7140 | return 1; |
| 7141 | } |
| 7142 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7143 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7144 | res = obj2ast_expr(tmp, &value, arena); |
| 7145 | if (res != 0) goto failed; |
| 7146 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7147 | } |
| 7148 | if (_PyObject_LookupAttrId(obj, &PyId_conversion, &tmp) < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7149 | return 1; |
| 7150 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7151 | if (tmp == NULL || tmp == Py_None) { |
| 7152 | Py_CLEAR(tmp); |
| 7153 | conversion = 0; |
| 7154 | } |
| 7155 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7156 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7157 | res = obj2ast_int(tmp, &conversion, arena); |
| 7158 | if (res != 0) goto failed; |
| 7159 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7160 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7161 | if (_PyObject_LookupAttrId(obj, &PyId_format_spec, &tmp) < 0) { |
| 7162 | return 1; |
| 7163 | } |
| 7164 | if (tmp == NULL || tmp == Py_None) { |
| 7165 | Py_CLEAR(tmp); |
| 7166 | format_spec = NULL; |
| 7167 | } |
| 7168 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7169 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7170 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 7171 | if (res != 0) goto failed; |
| 7172 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7173 | } |
| 7174 | *out = FormattedValue(value, conversion, format_spec, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7175 | col_offset, end_lineno, end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7176 | if (*out == NULL) goto failed; |
| 7177 | return 0; |
| 7178 | } |
| 7179 | isinstance = PyObject_IsInstance(obj, (PyObject*)JoinedStr_type); |
| 7180 | if (isinstance == -1) { |
| 7181 | return 1; |
| 7182 | } |
| 7183 | if (isinstance) { |
| 7184 | asdl_seq* values; |
| 7185 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7186 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
| 7187 | return 1; |
| 7188 | } |
| 7189 | if (tmp == NULL) { |
| 7190 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 7191 | return 1; |
| 7192 | } |
| 7193 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7194 | int res; |
| 7195 | Py_ssize_t len; |
| 7196 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7197 | if (!PyList_Check(tmp)) { |
| 7198 | PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7199 | goto failed; |
| 7200 | } |
| 7201 | len = PyList_GET_SIZE(tmp); |
| 7202 | values = _Py_asdl_seq_new(len, arena); |
| 7203 | if (values == NULL) goto failed; |
| 7204 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7205 | expr_ty val; |
| 7206 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7207 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 7208 | if (len != PyList_GET_SIZE(tmp)) { |
| 7209 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 7210 | goto failed; |
| 7211 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7212 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7213 | } |
| 7214 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7215 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7216 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 7217 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7218 | if (*out == NULL) goto failed; |
| 7219 | return 0; |
| 7220 | } |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7221 | isinstance = PyObject_IsInstance(obj, (PyObject*)Constant_type); |
| 7222 | if (isinstance == -1) { |
| 7223 | return 1; |
| 7224 | } |
| 7225 | if (isinstance) { |
| 7226 | constant value; |
| 7227 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7228 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7229 | return 1; |
| 7230 | } |
| 7231 | if (tmp == NULL) { |
| 7232 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 7233 | return 1; |
| 7234 | } |
| 7235 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7236 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7237 | res = obj2ast_constant(tmp, &value, arena); |
| 7238 | if (res != 0) goto failed; |
| 7239 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7240 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7241 | *out = Constant(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7242 | arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7243 | if (*out == NULL) goto failed; |
| 7244 | return 0; |
| 7245 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7246 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 7247 | if (isinstance == -1) { |
| 7248 | return 1; |
| 7249 | } |
| 7250 | if (isinstance) { |
| 7251 | expr_ty value; |
| 7252 | identifier attr; |
| 7253 | expr_context_ty ctx; |
| 7254 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7255 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7256 | return 1; |
| 7257 | } |
| 7258 | if (tmp == NULL) { |
| 7259 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 7260 | return 1; |
| 7261 | } |
| 7262 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7263 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7264 | res = obj2ast_expr(tmp, &value, arena); |
| 7265 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7266 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7267 | } |
| 7268 | if (_PyObject_LookupAttrId(obj, &PyId_attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7269 | return 1; |
| 7270 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7271 | if (tmp == NULL) { |
| 7272 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 7273 | return 1; |
| 7274 | } |
| 7275 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7276 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7277 | res = obj2ast_identifier(tmp, &attr, arena); |
| 7278 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7279 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7280 | } |
| 7281 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7282 | return 1; |
| 7283 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7284 | if (tmp == NULL) { |
| 7285 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 7286 | return 1; |
| 7287 | } |
| 7288 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7289 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7290 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7291 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7292 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7293 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7294 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 7295 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7296 | if (*out == NULL) goto failed; |
| 7297 | return 0; |
| 7298 | } |
| 7299 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 7300 | if (isinstance == -1) { |
| 7301 | return 1; |
| 7302 | } |
| 7303 | if (isinstance) { |
| 7304 | expr_ty value; |
| 7305 | slice_ty slice; |
| 7306 | expr_context_ty ctx; |
| 7307 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7308 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7309 | return 1; |
| 7310 | } |
| 7311 | if (tmp == NULL) { |
| 7312 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 7313 | return 1; |
| 7314 | } |
| 7315 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7316 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7317 | res = obj2ast_expr(tmp, &value, arena); |
| 7318 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7319 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7320 | } |
| 7321 | if (_PyObject_LookupAttrId(obj, &PyId_slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7322 | return 1; |
| 7323 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7324 | if (tmp == NULL) { |
| 7325 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 7326 | return 1; |
| 7327 | } |
| 7328 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7329 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7330 | res = obj2ast_slice(tmp, &slice, arena); |
| 7331 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7332 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7333 | } |
| 7334 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7335 | return 1; |
| 7336 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7337 | if (tmp == NULL) { |
| 7338 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 7339 | return 1; |
| 7340 | } |
| 7341 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7342 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7343 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7344 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7345 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7346 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7347 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 7348 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7349 | if (*out == NULL) goto failed; |
| 7350 | return 0; |
| 7351 | } |
| 7352 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 7353 | if (isinstance == -1) { |
| 7354 | return 1; |
| 7355 | } |
| 7356 | if (isinstance) { |
| 7357 | expr_ty value; |
| 7358 | expr_context_ty ctx; |
| 7359 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7360 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7361 | return 1; |
| 7362 | } |
| 7363 | if (tmp == NULL) { |
| 7364 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 7365 | return 1; |
| 7366 | } |
| 7367 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7368 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7369 | res = obj2ast_expr(tmp, &value, arena); |
| 7370 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7371 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7372 | } |
| 7373 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7374 | return 1; |
| 7375 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7376 | if (tmp == NULL) { |
| 7377 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 7378 | return 1; |
| 7379 | } |
| 7380 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7381 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7382 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7383 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7384 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7385 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7386 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 7387 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7388 | if (*out == NULL) goto failed; |
| 7389 | return 0; |
| 7390 | } |
| 7391 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 7392 | if (isinstance == -1) { |
| 7393 | return 1; |
| 7394 | } |
| 7395 | if (isinstance) { |
| 7396 | identifier id; |
| 7397 | expr_context_ty ctx; |
| 7398 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7399 | if (_PyObject_LookupAttrId(obj, &PyId_id, &tmp) < 0) { |
| 7400 | return 1; |
| 7401 | } |
| 7402 | if (tmp == NULL) { |
| 7403 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 7404 | return 1; |
| 7405 | } |
| 7406 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7407 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7408 | res = obj2ast_identifier(tmp, &id, arena); |
| 7409 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7410 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7411 | } |
| 7412 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7413 | return 1; |
| 7414 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7415 | if (tmp == NULL) { |
| 7416 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 7417 | return 1; |
| 7418 | } |
| 7419 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7420 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7421 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7422 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7423 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7424 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7425 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7426 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7427 | if (*out == NULL) goto failed; |
| 7428 | return 0; |
| 7429 | } |
| 7430 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 7431 | if (isinstance == -1) { |
| 7432 | return 1; |
| 7433 | } |
| 7434 | if (isinstance) { |
| 7435 | asdl_seq* elts; |
| 7436 | expr_context_ty ctx; |
| 7437 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7438 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 7439 | return 1; |
| 7440 | } |
| 7441 | if (tmp == NULL) { |
| 7442 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 7443 | return 1; |
| 7444 | } |
| 7445 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7446 | int res; |
| 7447 | Py_ssize_t len; |
| 7448 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7449 | if (!PyList_Check(tmp)) { |
| 7450 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7451 | goto failed; |
| 7452 | } |
| 7453 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7454 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7455 | if (elts == NULL) goto failed; |
| 7456 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7457 | expr_ty val; |
| 7458 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7459 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7460 | if (len != PyList_GET_SIZE(tmp)) { |
| 7461 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 7462 | goto failed; |
| 7463 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7464 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7465 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7466 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7467 | } |
| 7468 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7469 | return 1; |
| 7470 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7471 | if (tmp == NULL) { |
| 7472 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 7473 | return 1; |
| 7474 | } |
| 7475 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7476 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7477 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7478 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7479 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7480 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7481 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7482 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7483 | if (*out == NULL) goto failed; |
| 7484 | return 0; |
| 7485 | } |
| 7486 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 7487 | if (isinstance == -1) { |
| 7488 | return 1; |
| 7489 | } |
| 7490 | if (isinstance) { |
| 7491 | asdl_seq* elts; |
| 7492 | expr_context_ty ctx; |
| 7493 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7494 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 7495 | return 1; |
| 7496 | } |
| 7497 | if (tmp == NULL) { |
| 7498 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 7499 | return 1; |
| 7500 | } |
| 7501 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7502 | int res; |
| 7503 | Py_ssize_t len; |
| 7504 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7505 | if (!PyList_Check(tmp)) { |
| 7506 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7507 | goto failed; |
| 7508 | } |
| 7509 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7510 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7511 | if (elts == NULL) goto failed; |
| 7512 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7513 | expr_ty val; |
| 7514 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7515 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7516 | if (len != PyList_GET_SIZE(tmp)) { |
| 7517 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 7518 | goto failed; |
| 7519 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7520 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7521 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7522 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7523 | } |
| 7524 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7525 | return 1; |
| 7526 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7527 | if (tmp == NULL) { |
| 7528 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 7529 | return 1; |
| 7530 | } |
| 7531 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7532 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7533 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7534 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7535 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7536 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7537 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7538 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7539 | if (*out == NULL) goto failed; |
| 7540 | return 0; |
| 7541 | } |
| 7542 | |
| 7543 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 7544 | failed: |
| 7545 | Py_XDECREF(tmp); |
| 7546 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7547 | } |
| 7548 | |
| 7549 | int |
| 7550 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 7551 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7552 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7553 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7554 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 7555 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7556 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7557 | } |
| 7558 | if (isinstance) { |
| 7559 | *out = Load; |
| 7560 | return 0; |
| 7561 | } |
| 7562 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 7563 | if (isinstance == -1) { |
| 7564 | return 1; |
| 7565 | } |
| 7566 | if (isinstance) { |
| 7567 | *out = Store; |
| 7568 | return 0; |
| 7569 | } |
| 7570 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 7571 | if (isinstance == -1) { |
| 7572 | return 1; |
| 7573 | } |
| 7574 | if (isinstance) { |
| 7575 | *out = Del; |
| 7576 | return 0; |
| 7577 | } |
| 7578 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 7579 | if (isinstance == -1) { |
| 7580 | return 1; |
| 7581 | } |
| 7582 | if (isinstance) { |
| 7583 | *out = AugLoad; |
| 7584 | return 0; |
| 7585 | } |
| 7586 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 7587 | if (isinstance == -1) { |
| 7588 | return 1; |
| 7589 | } |
| 7590 | if (isinstance) { |
| 7591 | *out = AugStore; |
| 7592 | return 0; |
| 7593 | } |
| 7594 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 7595 | if (isinstance == -1) { |
| 7596 | return 1; |
| 7597 | } |
| 7598 | if (isinstance) { |
| 7599 | *out = Param; |
| 7600 | return 0; |
| 7601 | } |
| 7602 | |
| 7603 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 7604 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7605 | } |
| 7606 | |
| 7607 | int |
| 7608 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 7609 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7610 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7611 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7612 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7613 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7614 | if (obj == Py_None) { |
| 7615 | *out = NULL; |
| 7616 | return 0; |
| 7617 | } |
| 7618 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 7619 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7620 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7621 | } |
| 7622 | if (isinstance) { |
| 7623 | expr_ty lower; |
| 7624 | expr_ty upper; |
| 7625 | expr_ty step; |
| 7626 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7627 | if (_PyObject_LookupAttrId(obj, &PyId_lower, &tmp) < 0) { |
| 7628 | return 1; |
| 7629 | } |
| 7630 | if (tmp == NULL || tmp == Py_None) { |
| 7631 | Py_CLEAR(tmp); |
| 7632 | lower = NULL; |
| 7633 | } |
| 7634 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7635 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7636 | res = obj2ast_expr(tmp, &lower, arena); |
| 7637 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7638 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7639 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7640 | if (_PyObject_LookupAttrId(obj, &PyId_upper, &tmp) < 0) { |
| 7641 | return 1; |
| 7642 | } |
| 7643 | if (tmp == NULL || tmp == Py_None) { |
| 7644 | Py_CLEAR(tmp); |
| 7645 | upper = NULL; |
| 7646 | } |
| 7647 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7648 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7649 | res = obj2ast_expr(tmp, &upper, arena); |
| 7650 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7651 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7652 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7653 | if (_PyObject_LookupAttrId(obj, &PyId_step, &tmp) < 0) { |
| 7654 | return 1; |
| 7655 | } |
| 7656 | if (tmp == NULL || tmp == Py_None) { |
| 7657 | Py_CLEAR(tmp); |
| 7658 | step = NULL; |
| 7659 | } |
| 7660 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7661 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7662 | res = obj2ast_expr(tmp, &step, arena); |
| 7663 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7664 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7665 | } |
| 7666 | *out = Slice(lower, upper, step, arena); |
| 7667 | if (*out == NULL) goto failed; |
| 7668 | return 0; |
| 7669 | } |
| 7670 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 7671 | if (isinstance == -1) { |
| 7672 | return 1; |
| 7673 | } |
| 7674 | if (isinstance) { |
| 7675 | asdl_seq* dims; |
| 7676 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7677 | if (_PyObject_LookupAttrId(obj, &PyId_dims, &tmp) < 0) { |
| 7678 | return 1; |
| 7679 | } |
| 7680 | if (tmp == NULL) { |
| 7681 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 7682 | return 1; |
| 7683 | } |
| 7684 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7685 | int res; |
| 7686 | Py_ssize_t len; |
| 7687 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7688 | if (!PyList_Check(tmp)) { |
| 7689 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7690 | goto failed; |
| 7691 | } |
| 7692 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7693 | dims = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7694 | if (dims == NULL) goto failed; |
| 7695 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7696 | slice_ty val; |
| 7697 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7698 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7699 | if (len != PyList_GET_SIZE(tmp)) { |
| 7700 | PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration"); |
| 7701 | goto failed; |
| 7702 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7703 | asdl_seq_SET(dims, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7704 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7705 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7706 | } |
| 7707 | *out = ExtSlice(dims, arena); |
| 7708 | if (*out == NULL) goto failed; |
| 7709 | return 0; |
| 7710 | } |
| 7711 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 7712 | if (isinstance == -1) { |
| 7713 | return 1; |
| 7714 | } |
| 7715 | if (isinstance) { |
| 7716 | expr_ty value; |
| 7717 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7718 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7719 | return 1; |
| 7720 | } |
| 7721 | if (tmp == NULL) { |
| 7722 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 7723 | return 1; |
| 7724 | } |
| 7725 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7726 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7727 | res = obj2ast_expr(tmp, &value, arena); |
| 7728 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7729 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7730 | } |
| 7731 | *out = Index(value, arena); |
| 7732 | if (*out == NULL) goto failed; |
| 7733 | return 0; |
| 7734 | } |
| 7735 | |
| 7736 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 7737 | failed: |
| 7738 | Py_XDECREF(tmp); |
| 7739 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7740 | } |
| 7741 | |
| 7742 | int |
| 7743 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 7744 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7745 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7746 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7747 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 7748 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7749 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7750 | } |
| 7751 | if (isinstance) { |
| 7752 | *out = And; |
| 7753 | return 0; |
| 7754 | } |
| 7755 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 7756 | if (isinstance == -1) { |
| 7757 | return 1; |
| 7758 | } |
| 7759 | if (isinstance) { |
| 7760 | *out = Or; |
| 7761 | return 0; |
| 7762 | } |
| 7763 | |
| 7764 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 7765 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7766 | } |
| 7767 | |
| 7768 | int |
| 7769 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 7770 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7771 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7772 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7773 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 7774 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7775 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7776 | } |
| 7777 | if (isinstance) { |
| 7778 | *out = Add; |
| 7779 | return 0; |
| 7780 | } |
| 7781 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 7782 | if (isinstance == -1) { |
| 7783 | return 1; |
| 7784 | } |
| 7785 | if (isinstance) { |
| 7786 | *out = Sub; |
| 7787 | return 0; |
| 7788 | } |
| 7789 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 7790 | if (isinstance == -1) { |
| 7791 | return 1; |
| 7792 | } |
| 7793 | if (isinstance) { |
| 7794 | *out = Mult; |
| 7795 | return 0; |
| 7796 | } |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 7797 | isinstance = PyObject_IsInstance(obj, (PyObject *)MatMult_type); |
| 7798 | if (isinstance == -1) { |
| 7799 | return 1; |
| 7800 | } |
| 7801 | if (isinstance) { |
| 7802 | *out = MatMult; |
| 7803 | return 0; |
| 7804 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7805 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 7806 | if (isinstance == -1) { |
| 7807 | return 1; |
| 7808 | } |
| 7809 | if (isinstance) { |
| 7810 | *out = Div; |
| 7811 | return 0; |
| 7812 | } |
| 7813 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 7814 | if (isinstance == -1) { |
| 7815 | return 1; |
| 7816 | } |
| 7817 | if (isinstance) { |
| 7818 | *out = Mod; |
| 7819 | return 0; |
| 7820 | } |
| 7821 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 7822 | if (isinstance == -1) { |
| 7823 | return 1; |
| 7824 | } |
| 7825 | if (isinstance) { |
| 7826 | *out = Pow; |
| 7827 | return 0; |
| 7828 | } |
| 7829 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 7830 | if (isinstance == -1) { |
| 7831 | return 1; |
| 7832 | } |
| 7833 | if (isinstance) { |
| 7834 | *out = LShift; |
| 7835 | return 0; |
| 7836 | } |
| 7837 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 7838 | if (isinstance == -1) { |
| 7839 | return 1; |
| 7840 | } |
| 7841 | if (isinstance) { |
| 7842 | *out = RShift; |
| 7843 | return 0; |
| 7844 | } |
| 7845 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 7846 | if (isinstance == -1) { |
| 7847 | return 1; |
| 7848 | } |
| 7849 | if (isinstance) { |
| 7850 | *out = BitOr; |
| 7851 | return 0; |
| 7852 | } |
| 7853 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 7854 | if (isinstance == -1) { |
| 7855 | return 1; |
| 7856 | } |
| 7857 | if (isinstance) { |
| 7858 | *out = BitXor; |
| 7859 | return 0; |
| 7860 | } |
| 7861 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 7862 | if (isinstance == -1) { |
| 7863 | return 1; |
| 7864 | } |
| 7865 | if (isinstance) { |
| 7866 | *out = BitAnd; |
| 7867 | return 0; |
| 7868 | } |
| 7869 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 7870 | if (isinstance == -1) { |
| 7871 | return 1; |
| 7872 | } |
| 7873 | if (isinstance) { |
| 7874 | *out = FloorDiv; |
| 7875 | return 0; |
| 7876 | } |
| 7877 | |
| 7878 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 7879 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7880 | } |
| 7881 | |
| 7882 | int |
| 7883 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 7884 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7885 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7886 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7887 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 7888 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7889 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7890 | } |
| 7891 | if (isinstance) { |
| 7892 | *out = Invert; |
| 7893 | return 0; |
| 7894 | } |
| 7895 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 7896 | if (isinstance == -1) { |
| 7897 | return 1; |
| 7898 | } |
| 7899 | if (isinstance) { |
| 7900 | *out = Not; |
| 7901 | return 0; |
| 7902 | } |
| 7903 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 7904 | if (isinstance == -1) { |
| 7905 | return 1; |
| 7906 | } |
| 7907 | if (isinstance) { |
| 7908 | *out = UAdd; |
| 7909 | return 0; |
| 7910 | } |
| 7911 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 7912 | if (isinstance == -1) { |
| 7913 | return 1; |
| 7914 | } |
| 7915 | if (isinstance) { |
| 7916 | *out = USub; |
| 7917 | return 0; |
| 7918 | } |
| 7919 | |
| 7920 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 7921 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7922 | } |
| 7923 | |
| 7924 | int |
| 7925 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 7926 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7927 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7928 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7929 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 7930 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7931 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7932 | } |
| 7933 | if (isinstance) { |
| 7934 | *out = Eq; |
| 7935 | return 0; |
| 7936 | } |
| 7937 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 7938 | if (isinstance == -1) { |
| 7939 | return 1; |
| 7940 | } |
| 7941 | if (isinstance) { |
| 7942 | *out = NotEq; |
| 7943 | return 0; |
| 7944 | } |
| 7945 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 7946 | if (isinstance == -1) { |
| 7947 | return 1; |
| 7948 | } |
| 7949 | if (isinstance) { |
| 7950 | *out = Lt; |
| 7951 | return 0; |
| 7952 | } |
| 7953 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 7954 | if (isinstance == -1) { |
| 7955 | return 1; |
| 7956 | } |
| 7957 | if (isinstance) { |
| 7958 | *out = LtE; |
| 7959 | return 0; |
| 7960 | } |
| 7961 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 7962 | if (isinstance == -1) { |
| 7963 | return 1; |
| 7964 | } |
| 7965 | if (isinstance) { |
| 7966 | *out = Gt; |
| 7967 | return 0; |
| 7968 | } |
| 7969 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 7970 | if (isinstance == -1) { |
| 7971 | return 1; |
| 7972 | } |
| 7973 | if (isinstance) { |
| 7974 | *out = GtE; |
| 7975 | return 0; |
| 7976 | } |
| 7977 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 7978 | if (isinstance == -1) { |
| 7979 | return 1; |
| 7980 | } |
| 7981 | if (isinstance) { |
| 7982 | *out = Is; |
| 7983 | return 0; |
| 7984 | } |
| 7985 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 7986 | if (isinstance == -1) { |
| 7987 | return 1; |
| 7988 | } |
| 7989 | if (isinstance) { |
| 7990 | *out = IsNot; |
| 7991 | return 0; |
| 7992 | } |
| 7993 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 7994 | if (isinstance == -1) { |
| 7995 | return 1; |
| 7996 | } |
| 7997 | if (isinstance) { |
| 7998 | *out = In; |
| 7999 | return 0; |
| 8000 | } |
| 8001 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 8002 | if (isinstance == -1) { |
| 8003 | return 1; |
| 8004 | } |
| 8005 | if (isinstance) { |
| 8006 | *out = NotIn; |
| 8007 | return 0; |
| 8008 | } |
| 8009 | |
| 8010 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 8011 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8012 | } |
| 8013 | |
| 8014 | int |
| 8015 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 8016 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8017 | PyObject* tmp = NULL; |
| 8018 | expr_ty target; |
| 8019 | expr_ty iter; |
| 8020 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8021 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8022 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8023 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 8024 | return 1; |
| 8025 | } |
| 8026 | if (tmp == NULL) { |
| 8027 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 8028 | return 1; |
| 8029 | } |
| 8030 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8031 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8032 | res = obj2ast_expr(tmp, &target, arena); |
| 8033 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8034 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8035 | } |
| 8036 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8037 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8038 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8039 | if (tmp == NULL) { |
| 8040 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 8041 | return 1; |
| 8042 | } |
| 8043 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8044 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8045 | res = obj2ast_expr(tmp, &iter, arena); |
| 8046 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8047 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8048 | } |
| 8049 | if (_PyObject_LookupAttrId(obj, &PyId_ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8050 | return 1; |
| 8051 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8052 | if (tmp == NULL) { |
| 8053 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 8054 | return 1; |
| 8055 | } |
| 8056 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8057 | int res; |
| 8058 | Py_ssize_t len; |
| 8059 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8060 | if (!PyList_Check(tmp)) { |
| 8061 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8062 | goto failed; |
| 8063 | } |
| 8064 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8065 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8066 | if (ifs == NULL) goto failed; |
| 8067 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8068 | expr_ty val; |
| 8069 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8070 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8071 | if (len != PyList_GET_SIZE(tmp)) { |
| 8072 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 8073 | goto failed; |
| 8074 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8075 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8076 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8077 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8078 | } |
| 8079 | if (_PyObject_LookupAttrId(obj, &PyId_is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8080 | return 1; |
| 8081 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8082 | if (tmp == NULL) { |
| 8083 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 8084 | return 1; |
| 8085 | } |
| 8086 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8087 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8088 | res = obj2ast_int(tmp, &is_async, arena); |
| 8089 | if (res != 0) goto failed; |
| 8090 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8091 | } |
| 8092 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8093 | return 0; |
| 8094 | failed: |
| 8095 | Py_XDECREF(tmp); |
| 8096 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8097 | } |
| 8098 | |
| 8099 | int |
| 8100 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 8101 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8102 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 8103 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8104 | PyObject *tmp = NULL; |
| 8105 | int lineno; |
| 8106 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8107 | int end_lineno; |
| 8108 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8109 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8110 | if (obj == Py_None) { |
| 8111 | *out = NULL; |
| 8112 | return 0; |
| 8113 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8114 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 8115 | return 1; |
| 8116 | } |
| 8117 | if (tmp == NULL) { |
| 8118 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 8119 | return 1; |
| 8120 | } |
| 8121 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8122 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8123 | res = obj2ast_int(tmp, &lineno, arena); |
| 8124 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8125 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8126 | } |
| 8127 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8128 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8129 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8130 | if (tmp == NULL) { |
| 8131 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 8132 | return 1; |
| 8133 | } |
| 8134 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8135 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8136 | res = obj2ast_int(tmp, &col_offset, arena); |
| 8137 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8138 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8139 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8140 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 8141 | return 1; |
| 8142 | } |
| 8143 | if (tmp == NULL || tmp == Py_None) { |
| 8144 | Py_CLEAR(tmp); |
| 8145 | end_lineno = 0; |
| 8146 | } |
| 8147 | else { |
| 8148 | int res; |
| 8149 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 8150 | if (res != 0) goto failed; |
| 8151 | Py_CLEAR(tmp); |
| 8152 | } |
| 8153 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 8154 | return 1; |
| 8155 | } |
| 8156 | if (tmp == NULL || tmp == Py_None) { |
| 8157 | Py_CLEAR(tmp); |
| 8158 | end_col_offset = 0; |
| 8159 | } |
| 8160 | else { |
| 8161 | int res; |
| 8162 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 8163 | if (res != 0) goto failed; |
| 8164 | Py_CLEAR(tmp); |
| 8165 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8166 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 8167 | if (isinstance == -1) { |
| 8168 | return 1; |
| 8169 | } |
| 8170 | if (isinstance) { |
| 8171 | expr_ty type; |
| 8172 | identifier name; |
| 8173 | asdl_seq* body; |
| 8174 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8175 | if (_PyObject_LookupAttrId(obj, &PyId_type, &tmp) < 0) { |
| 8176 | return 1; |
| 8177 | } |
| 8178 | if (tmp == NULL || tmp == Py_None) { |
| 8179 | Py_CLEAR(tmp); |
| 8180 | type = NULL; |
| 8181 | } |
| 8182 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8183 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8184 | res = obj2ast_expr(tmp, &type, arena); |
| 8185 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8186 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8187 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8188 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 8189 | return 1; |
| 8190 | } |
| 8191 | if (tmp == NULL || tmp == Py_None) { |
| 8192 | Py_CLEAR(tmp); |
| 8193 | name = NULL; |
| 8194 | } |
| 8195 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8196 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8197 | res = obj2ast_identifier(tmp, &name, arena); |
| 8198 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8199 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8200 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8201 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 8202 | return 1; |
| 8203 | } |
| 8204 | if (tmp == NULL) { |
| 8205 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 8206 | return 1; |
| 8207 | } |
| 8208 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8209 | int res; |
| 8210 | Py_ssize_t len; |
| 8211 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8212 | if (!PyList_Check(tmp)) { |
| 8213 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8214 | goto failed; |
| 8215 | } |
| 8216 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8217 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8218 | if (body == NULL) goto failed; |
| 8219 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8220 | stmt_ty val; |
| 8221 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8222 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8223 | if (len != PyList_GET_SIZE(tmp)) { |
| 8224 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 8225 | goto failed; |
| 8226 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8227 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8228 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8229 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8230 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8231 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 8232 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8233 | if (*out == NULL) goto failed; |
| 8234 | return 0; |
| 8235 | } |
| 8236 | |
| 8237 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 8238 | failed: |
| 8239 | Py_XDECREF(tmp); |
| 8240 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8241 | } |
| 8242 | |
| 8243 | int |
| 8244 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 8245 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8246 | PyObject* tmp = NULL; |
| 8247 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8248 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8249 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8250 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8251 | arg_ty kwarg; |
| 8252 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8253 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8254 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
| 8255 | return 1; |
| 8256 | } |
| 8257 | if (tmp == NULL) { |
| 8258 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 8259 | return 1; |
| 8260 | } |
| 8261 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8262 | int res; |
| 8263 | Py_ssize_t len; |
| 8264 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8265 | if (!PyList_Check(tmp)) { |
| 8266 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8267 | goto failed; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8268 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8269 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8270 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8271 | if (args == NULL) goto failed; |
| 8272 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8273 | arg_ty val; |
| 8274 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8275 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8276 | if (len != PyList_GET_SIZE(tmp)) { |
| 8277 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 8278 | goto failed; |
| 8279 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8280 | asdl_seq_SET(args, i, val); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8281 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8282 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8283 | } |
| 8284 | if (_PyObject_LookupAttrId(obj, &PyId_vararg, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8285 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8286 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8287 | if (tmp == NULL || tmp == Py_None) { |
| 8288 | Py_CLEAR(tmp); |
| 8289 | vararg = NULL; |
| 8290 | } |
| 8291 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8292 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8293 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8294 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8295 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8296 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8297 | if (_PyObject_LookupAttrId(obj, &PyId_kwonlyargs, &tmp) < 0) { |
| 8298 | return 1; |
| 8299 | } |
| 8300 | if (tmp == NULL) { |
| 8301 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 8302 | return 1; |
| 8303 | } |
| 8304 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8305 | int res; |
| 8306 | Py_ssize_t len; |
| 8307 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8308 | if (!PyList_Check(tmp)) { |
| 8309 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8310 | goto failed; |
| 8311 | } |
| 8312 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8313 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8314 | if (kwonlyargs == NULL) goto failed; |
| 8315 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8316 | arg_ty val; |
| 8317 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8318 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8319 | if (len != PyList_GET_SIZE(tmp)) { |
| 8320 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 8321 | goto failed; |
| 8322 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8323 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8324 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8325 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8326 | } |
| 8327 | if (_PyObject_LookupAttrId(obj, &PyId_kw_defaults, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8328 | return 1; |
| 8329 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8330 | if (tmp == NULL) { |
| 8331 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 8332 | return 1; |
| 8333 | } |
| 8334 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8335 | int res; |
| 8336 | Py_ssize_t len; |
| 8337 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8338 | if (!PyList_Check(tmp)) { |
| 8339 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8340 | goto failed; |
| 8341 | } |
| 8342 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8343 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8344 | if (kw_defaults == NULL) goto failed; |
| 8345 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8346 | expr_ty val; |
| 8347 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8348 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8349 | if (len != PyList_GET_SIZE(tmp)) { |
| 8350 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 8351 | goto failed; |
| 8352 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8353 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8354 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8355 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8356 | } |
| 8357 | if (_PyObject_LookupAttrId(obj, &PyId_kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8358 | return 1; |
| 8359 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8360 | if (tmp == NULL || tmp == Py_None) { |
| 8361 | Py_CLEAR(tmp); |
| 8362 | kwarg = NULL; |
| 8363 | } |
| 8364 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8365 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8366 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 8367 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 8368 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8369 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8370 | if (_PyObject_LookupAttrId(obj, &PyId_defaults, &tmp) < 0) { |
| 8371 | return 1; |
| 8372 | } |
| 8373 | if (tmp == NULL) { |
| 8374 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 8375 | return 1; |
| 8376 | } |
| 8377 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8378 | int res; |
| 8379 | Py_ssize_t len; |
| 8380 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8381 | if (!PyList_Check(tmp)) { |
| 8382 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8383 | goto failed; |
| 8384 | } |
| 8385 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8386 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8387 | if (defaults == NULL) goto failed; |
| 8388 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8389 | expr_ty val; |
| 8390 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8391 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8392 | if (len != PyList_GET_SIZE(tmp)) { |
| 8393 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 8394 | goto failed; |
| 8395 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8396 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8397 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 8398 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8399 | } |
| 8400 | *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg, defaults, |
| 8401 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8402 | return 0; |
| 8403 | failed: |
| 8404 | Py_XDECREF(tmp); |
| 8405 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8406 | } |
| 8407 | |
| 8408 | int |
| 8409 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 8410 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8411 | PyObject* tmp = NULL; |
| 8412 | identifier arg; |
| 8413 | expr_ty annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8414 | string type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8415 | int lineno; |
| 8416 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8417 | int end_lineno; |
| 8418 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8419 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8420 | if (_PyObject_LookupAttrId(obj, &PyId_arg, &tmp) < 0) { |
| 8421 | return 1; |
| 8422 | } |
| 8423 | if (tmp == NULL) { |
| 8424 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 8425 | return 1; |
| 8426 | } |
| 8427 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8428 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8429 | res = obj2ast_identifier(tmp, &arg, arena); |
| 8430 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8431 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8432 | } |
| 8433 | if (_PyObject_LookupAttrId(obj, &PyId_annotation, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8434 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8435 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8436 | if (tmp == NULL || tmp == Py_None) { |
| 8437 | Py_CLEAR(tmp); |
| 8438 | annotation = NULL; |
| 8439 | } |
| 8440 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8441 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8442 | res = obj2ast_expr(tmp, &annotation, arena); |
| 8443 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8444 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8445 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8446 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 8447 | return 1; |
| 8448 | } |
| 8449 | if (tmp == NULL || tmp == Py_None) { |
| 8450 | Py_CLEAR(tmp); |
| 8451 | type_comment = NULL; |
| 8452 | } |
| 8453 | else { |
| 8454 | int res; |
| 8455 | res = obj2ast_string(tmp, &type_comment, arena); |
| 8456 | if (res != 0) goto failed; |
| 8457 | Py_CLEAR(tmp); |
| 8458 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8459 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 8460 | return 1; |
| 8461 | } |
| 8462 | if (tmp == NULL) { |
| 8463 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 8464 | return 1; |
| 8465 | } |
| 8466 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8467 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8468 | res = obj2ast_int(tmp, &lineno, arena); |
| 8469 | if (res != 0) goto failed; |
| 8470 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8471 | } |
| 8472 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8473 | return 1; |
| 8474 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8475 | if (tmp == NULL) { |
| 8476 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 8477 | return 1; |
| 8478 | } |
| 8479 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8480 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8481 | res = obj2ast_int(tmp, &col_offset, arena); |
| 8482 | if (res != 0) goto failed; |
| 8483 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8484 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8485 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 8486 | return 1; |
| 8487 | } |
| 8488 | if (tmp == NULL || tmp == Py_None) { |
| 8489 | Py_CLEAR(tmp); |
| 8490 | end_lineno = 0; |
| 8491 | } |
| 8492 | else { |
| 8493 | int res; |
| 8494 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 8495 | if (res != 0) goto failed; |
| 8496 | Py_CLEAR(tmp); |
| 8497 | } |
| 8498 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 8499 | return 1; |
| 8500 | } |
| 8501 | if (tmp == NULL || tmp == Py_None) { |
| 8502 | Py_CLEAR(tmp); |
| 8503 | end_col_offset = 0; |
| 8504 | } |
| 8505 | else { |
| 8506 | int res; |
| 8507 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 8508 | if (res != 0) goto failed; |
| 8509 | Py_CLEAR(tmp); |
| 8510 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8511 | *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno, |
| 8512 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8513 | return 0; |
| 8514 | failed: |
| 8515 | Py_XDECREF(tmp); |
| 8516 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8517 | } |
| 8518 | |
| 8519 | int |
| 8520 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 8521 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8522 | PyObject* tmp = NULL; |
| 8523 | identifier arg; |
| 8524 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8525 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8526 | if (_PyObject_LookupAttrId(obj, &PyId_arg, &tmp) < 0) { |
| 8527 | return 1; |
| 8528 | } |
| 8529 | if (tmp == NULL || tmp == Py_None) { |
| 8530 | Py_CLEAR(tmp); |
| 8531 | arg = NULL; |
| 8532 | } |
| 8533 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8534 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8535 | res = obj2ast_identifier(tmp, &arg, arena); |
| 8536 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8537 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8538 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8539 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 8540 | return 1; |
| 8541 | } |
| 8542 | if (tmp == NULL) { |
| 8543 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 8544 | return 1; |
| 8545 | } |
| 8546 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8547 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8548 | res = obj2ast_expr(tmp, &value, arena); |
| 8549 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8550 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8551 | } |
| 8552 | *out = keyword(arg, value, arena); |
| 8553 | return 0; |
| 8554 | failed: |
| 8555 | Py_XDECREF(tmp); |
| 8556 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8557 | } |
| 8558 | |
| 8559 | int |
| 8560 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 8561 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8562 | PyObject* tmp = NULL; |
| 8563 | identifier name; |
| 8564 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8565 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8566 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 8567 | return 1; |
| 8568 | } |
| 8569 | if (tmp == NULL) { |
| 8570 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 8571 | return 1; |
| 8572 | } |
| 8573 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8574 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8575 | res = obj2ast_identifier(tmp, &name, arena); |
| 8576 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8577 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8578 | } |
| 8579 | if (_PyObject_LookupAttrId(obj, &PyId_asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8580 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8581 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8582 | if (tmp == NULL || tmp == Py_None) { |
| 8583 | Py_CLEAR(tmp); |
| 8584 | asname = NULL; |
| 8585 | } |
| 8586 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8587 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8588 | res = obj2ast_identifier(tmp, &asname, arena); |
| 8589 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8590 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8591 | } |
| 8592 | *out = alias(name, asname, arena); |
| 8593 | return 0; |
| 8594 | failed: |
| 8595 | Py_XDECREF(tmp); |
| 8596 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8597 | } |
| 8598 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8599 | int |
| 8600 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 8601 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8602 | PyObject* tmp = NULL; |
| 8603 | expr_ty context_expr; |
| 8604 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8605 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8606 | if (_PyObject_LookupAttrId(obj, &PyId_context_expr, &tmp) < 0) { |
| 8607 | return 1; |
| 8608 | } |
| 8609 | if (tmp == NULL) { |
| 8610 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 8611 | return 1; |
| 8612 | } |
| 8613 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8614 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8615 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 8616 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8617 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8618 | } |
| 8619 | if (_PyObject_LookupAttrId(obj, &PyId_optional_vars, &tmp) < 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8620 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8621 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8622 | if (tmp == NULL || tmp == Py_None) { |
| 8623 | Py_CLEAR(tmp); |
| 8624 | optional_vars = NULL; |
| 8625 | } |
| 8626 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8627 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8628 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 8629 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8630 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8631 | } |
| 8632 | *out = withitem(context_expr, optional_vars, arena); |
| 8633 | return 0; |
| 8634 | failed: |
| 8635 | Py_XDECREF(tmp); |
| 8636 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8637 | } |
| 8638 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8639 | int |
| 8640 | obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) |
| 8641 | { |
| 8642 | int isinstance; |
| 8643 | |
| 8644 | PyObject *tmp = NULL; |
| 8645 | |
| 8646 | if (obj == Py_None) { |
| 8647 | *out = NULL; |
| 8648 | return 0; |
| 8649 | } |
| 8650 | isinstance = PyObject_IsInstance(obj, (PyObject*)TypeIgnore_type); |
| 8651 | if (isinstance == -1) { |
| 8652 | return 1; |
| 8653 | } |
| 8654 | if (isinstance) { |
| 8655 | int lineno; |
| 8656 | |
| 8657 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 8658 | return 1; |
| 8659 | } |
| 8660 | if (tmp == NULL) { |
| 8661 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore"); |
| 8662 | return 1; |
| 8663 | } |
| 8664 | else { |
| 8665 | int res; |
| 8666 | res = obj2ast_int(tmp, &lineno, arena); |
| 8667 | if (res != 0) goto failed; |
| 8668 | Py_CLEAR(tmp); |
| 8669 | } |
| 8670 | *out = TypeIgnore(lineno, arena); |
| 8671 | if (*out == NULL) goto failed; |
| 8672 | return 0; |
| 8673 | } |
| 8674 | |
| 8675 | PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj); |
| 8676 | failed: |
| 8677 | Py_XDECREF(tmp); |
| 8678 | return 1; |
| 8679 | } |
| 8680 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8681 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 8682 | static struct PyModuleDef _astmodule = { |
| 8683 | PyModuleDef_HEAD_INIT, "_ast" |
| 8684 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8685 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 8686 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8687 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8688 | PyObject *m, *d; |
| 8689 | if (!init_types()) return NULL; |
| 8690 | m = PyModule_Create(&_astmodule); |
| 8691 | if (!m) return NULL; |
| 8692 | d = PyModule_GetDict(m); |
| 8693 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8694 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8695 | return NULL; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8696 | if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) |
| 8697 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8698 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; |
| 8699 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return |
| 8700 | NULL; |
| 8701 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) < |
| 8702 | 0) return NULL; |
| 8703 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0) |
| 8704 | return NULL; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8705 | if (PyDict_SetItemString(d, "FunctionType", (PyObject*)FunctionType_type) < |
| 8706 | 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8707 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 8708 | NULL; |
| 8709 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL; |
| 8710 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) < |
| 8711 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8712 | if (PyDict_SetItemString(d, "AsyncFunctionDef", |
| 8713 | (PyObject*)AsyncFunctionDef_type) < 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8714 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 8715 | return NULL; |
| 8716 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return |
| 8717 | NULL; |
| 8718 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return |
| 8719 | NULL; |
| 8720 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return |
| 8721 | NULL; |
| 8722 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0) |
| 8723 | return NULL; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 8724 | if (PyDict_SetItemString(d, "AnnAssign", (PyObject*)AnnAssign_type) < 0) |
| 8725 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8726 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8727 | if (PyDict_SetItemString(d, "AsyncFor", (PyObject*)AsyncFor_type) < 0) |
| 8728 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8729 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 8730 | NULL; |
| 8731 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 8732 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8733 | if (PyDict_SetItemString(d, "AsyncWith", (PyObject*)AsyncWith_type) < 0) |
| 8734 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8735 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 8736 | NULL; |
| 8737 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL; |
| 8738 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return |
| 8739 | NULL; |
| 8740 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return |
| 8741 | NULL; |
| 8742 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0) |
| 8743 | return NULL; |
| 8744 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return |
| 8745 | NULL; |
| 8746 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
| 8747 | return NULL; |
| 8748 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL; |
| 8749 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL; |
| 8750 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 8751 | NULL; |
| 8752 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 8753 | return NULL; |
| 8754 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL; |
| 8755 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return |
| 8756 | NULL; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 8757 | if (PyDict_SetItemString(d, "NamedExpr", (PyObject*)NamedExpr_type) < 0) |
| 8758 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8759 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 8760 | NULL; |
| 8761 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return |
| 8762 | NULL; |
| 8763 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return |
| 8764 | NULL; |
| 8765 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 8766 | NULL; |
| 8767 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL; |
| 8768 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL; |
| 8769 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 8770 | return NULL; |
| 8771 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return |
| 8772 | NULL; |
| 8773 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
| 8774 | return NULL; |
| 8775 | if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) < |
| 8776 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8777 | if (PyDict_SetItemString(d, "Await", (PyObject*)Await_type) < 0) return |
| 8778 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8779 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 8780 | NULL; |
| 8781 | if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0) |
| 8782 | return NULL; |
| 8783 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return |
| 8784 | NULL; |
| 8785 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8786 | if (PyDict_SetItemString(d, "FormattedValue", |
| 8787 | (PyObject*)FormattedValue_type) < 0) return NULL; |
| 8788 | if (PyDict_SetItemString(d, "JoinedStr", (PyObject*)JoinedStr_type) < 0) |
| 8789 | return NULL; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8790 | if (PyDict_SetItemString(d, "Constant", (PyObject*)Constant_type) < 0) |
| 8791 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8792 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0) |
| 8793 | return NULL; |
| 8794 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0) |
| 8795 | return NULL; |
| 8796 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return |
| 8797 | NULL; |
| 8798 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL; |
| 8799 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL; |
| 8800 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 8801 | NULL; |
| 8802 | if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) < |
| 8803 | 0) return NULL; |
| 8804 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL; |
| 8805 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 8806 | NULL; |
| 8807 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL; |
| 8808 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return |
| 8809 | NULL; |
| 8810 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 8811 | return NULL; |
| 8812 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 8813 | NULL; |
| 8814 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 8815 | NULL; |
| 8816 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 8817 | NULL; |
| 8818 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 8819 | return NULL; |
| 8820 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 8821 | NULL; |
| 8822 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return |
| 8823 | NULL; |
| 8824 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL; |
| 8825 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
| 8826 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 8827 | return NULL; |
| 8828 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL; |
| 8829 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL; |
| 8830 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8831 | if (PyDict_SetItemString(d, "MatMult", (PyObject*)MatMult_type) < 0) return |
| 8832 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8833 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL; |
| 8834 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL; |
| 8835 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL; |
| 8836 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return |
| 8837 | NULL; |
| 8838 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return |
| 8839 | NULL; |
| 8840 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 8841 | NULL; |
| 8842 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return |
| 8843 | NULL; |
| 8844 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return |
| 8845 | NULL; |
| 8846 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 8847 | return NULL; |
| 8848 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return |
| 8849 | NULL; |
| 8850 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return |
| 8851 | NULL; |
| 8852 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL; |
| 8853 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL; |
| 8854 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL; |
| 8855 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 8856 | NULL; |
| 8857 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 8858 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 8859 | NULL; |
| 8860 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 8861 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL; |
| 8862 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 8863 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL; |
| 8864 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 8865 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 8866 | NULL; |
| 8867 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 8868 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 8869 | NULL; |
| 8870 | if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type) |
| 8871 | < 0) return NULL; |
| 8872 | if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type) |
| 8873 | < 0) return NULL; |
| 8874 | if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type) |
| 8875 | < 0) return NULL; |
| 8876 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0) |
| 8877 | return NULL; |
| 8878 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL; |
| 8879 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return |
| 8880 | NULL; |
| 8881 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 8882 | NULL; |
| 8883 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 8884 | return NULL; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8885 | if (PyDict_SetItemString(d, "type_ignore", (PyObject*)type_ignore_type) < |
| 8886 | 0) return NULL; |
| 8887 | if (PyDict_SetItemString(d, "TypeIgnore", (PyObject*)TypeIgnore_type) < 0) |
| 8888 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8889 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8890 | } |
| 8891 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8892 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 8893 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8894 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 8895 | if (!init_types()) |
| 8896 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 8897 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8898 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 8899 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8900 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 8901 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8902 | { |
Guido van Rossum | 495da29 | 2019-03-07 12:38:08 -0800 | [diff] [blame] | 8903 | return PyAST_obj2mod_ex(ast, arena, mode, PY_MINOR_VERSION); |
| 8904 | } |
| 8905 | |
| 8906 | mod_ty PyAST_obj2mod_ex(PyObject* ast, PyArena* arena, int mode, int feature_version) |
| 8907 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8908 | mod_ty res; |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 8909 | PyObject *req_type[3]; |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 8910 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 8911 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 8912 | |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 8913 | req_type[0] = (PyObject*)Module_type; |
| 8914 | req_type[1] = (PyObject*)Expression_type; |
| 8915 | req_type[2] = (PyObject*)Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 8916 | |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 8917 | assert(0 <= mode && mode <= 2); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8918 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 8919 | if (!init_types()) |
| 8920 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8921 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 8922 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 8923 | if (isinstance == -1) |
| 8924 | return NULL; |
| 8925 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8926 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 8927 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8928 | return NULL; |
| 8929 | } |
| 8930 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 8931 | return NULL; |
| 8932 | else |
| 8933 | return res; |
| 8934 | } |
| 8935 | |
| 8936 | int PyAST_Check(PyObject* obj) |
| 8937 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 8938 | if (!init_types()) |
| 8939 | return -1; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 8940 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8941 | } |
| 8942 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 8943 | |