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, |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 368 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton, |
| 369 | *NamedStore_singleton; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 370 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 371 | static PyTypeObject *Load_type; |
| 372 | static PyTypeObject *Store_type; |
| 373 | static PyTypeObject *Del_type; |
| 374 | static PyTypeObject *AugLoad_type; |
| 375 | static PyTypeObject *AugStore_type; |
| 376 | static PyTypeObject *Param_type; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 377 | static PyTypeObject *NamedStore_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 378 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 379 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 380 | static PyTypeObject *Slice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 381 | _Py_IDENTIFIER(lower); |
| 382 | _Py_IDENTIFIER(upper); |
| 383 | _Py_IDENTIFIER(step); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 384 | static char *Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 385 | "lower", |
| 386 | "upper", |
| 387 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 388 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 389 | static PyTypeObject *ExtSlice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 390 | _Py_IDENTIFIER(dims); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 391 | static char *ExtSlice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 392 | "dims", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 393 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 394 | static PyTypeObject *Index_type; |
| 395 | static char *Index_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 396 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 397 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 398 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 399 | static PyObject *And_singleton, *Or_singleton; |
| 400 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 401 | static PyTypeObject *And_type; |
| 402 | static PyTypeObject *Or_type; |
| 403 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 404 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 405 | *MatMult_singleton, *Div_singleton, *Mod_singleton, *Pow_singleton, |
| 406 | *LShift_singleton, *RShift_singleton, *BitOr_singleton, *BitXor_singleton, |
| 407 | *BitAnd_singleton, *FloorDiv_singleton; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 408 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 409 | static PyTypeObject *Add_type; |
| 410 | static PyTypeObject *Sub_type; |
| 411 | static PyTypeObject *Mult_type; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 412 | static PyTypeObject *MatMult_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 413 | static PyTypeObject *Div_type; |
| 414 | static PyTypeObject *Mod_type; |
| 415 | static PyTypeObject *Pow_type; |
| 416 | static PyTypeObject *LShift_type; |
| 417 | static PyTypeObject *RShift_type; |
| 418 | static PyTypeObject *BitOr_type; |
| 419 | static PyTypeObject *BitXor_type; |
| 420 | static PyTypeObject *BitAnd_type; |
| 421 | static PyTypeObject *FloorDiv_type; |
| 422 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 423 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 424 | *USub_singleton; |
| 425 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 426 | static PyTypeObject *Invert_type; |
| 427 | static PyTypeObject *Not_type; |
| 428 | static PyTypeObject *UAdd_type; |
| 429 | static PyTypeObject *USub_type; |
| 430 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 431 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 432 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 433 | *NotIn_singleton; |
| 434 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 435 | static PyTypeObject *Eq_type; |
| 436 | static PyTypeObject *NotEq_type; |
| 437 | static PyTypeObject *Lt_type; |
| 438 | static PyTypeObject *LtE_type; |
| 439 | static PyTypeObject *Gt_type; |
| 440 | static PyTypeObject *GtE_type; |
| 441 | static PyTypeObject *Is_type; |
| 442 | static PyTypeObject *IsNot_type; |
| 443 | static PyTypeObject *In_type; |
| 444 | static PyTypeObject *NotIn_type; |
| 445 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 446 | static PyObject* ast2obj_comprehension(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 447 | _Py_IDENTIFIER(ifs); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 448 | _Py_IDENTIFIER(is_async); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 449 | static char *comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 450 | "target", |
| 451 | "iter", |
| 452 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 453 | "is_async", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 454 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 455 | static PyTypeObject *excepthandler_type; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 456 | static char *excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 457 | "lineno", |
| 458 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 459 | "end_lineno", |
| 460 | "end_col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 461 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 462 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 463 | static PyTypeObject *ExceptHandler_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 464 | _Py_IDENTIFIER(type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 465 | static char *ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 466 | "type", |
| 467 | "name", |
| 468 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 469 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 470 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 471 | static PyObject* ast2obj_arguments(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 472 | _Py_IDENTIFIER(vararg); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 473 | _Py_IDENTIFIER(kwonlyargs); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 474 | _Py_IDENTIFIER(kw_defaults); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 475 | _Py_IDENTIFIER(kwarg); |
| 476 | _Py_IDENTIFIER(defaults); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 477 | static char *arguments_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 478 | "args", |
| 479 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 480 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 481 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 482 | "kwarg", |
| 483 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 484 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 485 | static PyTypeObject *arg_type; |
| 486 | static PyObject* ast2obj_arg(void*); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 487 | static char *arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 488 | "lineno", |
| 489 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 490 | "end_lineno", |
| 491 | "end_col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 492 | }; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 493 | _Py_IDENTIFIER(arg); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 494 | static char *arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 495 | "arg", |
| 496 | "annotation", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 497 | "type_comment", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 498 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 499 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 500 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 501 | static char *keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 502 | "arg", |
| 503 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 504 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 505 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 506 | static PyObject* ast2obj_alias(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 507 | _Py_IDENTIFIER(asname); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 508 | static char *alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 509 | "name", |
| 510 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 511 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 512 | static PyTypeObject *withitem_type; |
| 513 | static PyObject* ast2obj_withitem(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 514 | _Py_IDENTIFIER(context_expr); |
| 515 | _Py_IDENTIFIER(optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 516 | static char *withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 517 | "context_expr", |
| 518 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 519 | }; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 520 | static PyTypeObject *type_ignore_type; |
| 521 | static PyObject* ast2obj_type_ignore(void*); |
| 522 | static PyTypeObject *TypeIgnore_type; |
| 523 | static char *TypeIgnore_fields[]={ |
| 524 | "lineno", |
| 525 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 526 | |
| 527 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 528 | _Py_IDENTIFIER(_fields); |
| 529 | _Py_IDENTIFIER(_attributes); |
| 530 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 531 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 532 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 533 | PyObject *dict; |
| 534 | } AST_object; |
| 535 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 536 | static void |
| 537 | ast_dealloc(AST_object *self) |
| 538 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 539 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
| 540 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 541 | Py_CLEAR(self->dict); |
Antoine Pitrou | 5075074 | 2012-07-08 12:43:32 +0200 | [diff] [blame] | 542 | Py_TYPE(self)->tp_free(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 543 | } |
| 544 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 545 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 546 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 547 | { |
| 548 | Py_VISIT(self->dict); |
| 549 | return 0; |
| 550 | } |
| 551 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 552 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 553 | ast_clear(AST_object *self) |
| 554 | { |
| 555 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 556 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 560 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 561 | { |
| 562 | Py_ssize_t i, numfields = 0; |
| 563 | int res = -1; |
| 564 | PyObject *key, *value, *fields; |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 565 | if (_PyObject_LookupAttrId((PyObject*)Py_TYPE(self), &PyId__fields, &fields) < 0) { |
| 566 | goto cleanup; |
| 567 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 568 | if (fields) { |
| 569 | numfields = PySequence_Size(fields); |
| 570 | if (numfields == -1) |
| 571 | goto cleanup; |
| 572 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 573 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 574 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 575 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 576 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 577 | "%zd positional argument%s", |
| 578 | Py_TYPE(self)->tp_name, |
| 579 | numfields, numfields == 1 ? "" : "s"); |
| 580 | res = -1; |
| 581 | goto cleanup; |
| 582 | } |
| 583 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 584 | /* cannot be reached when fields is NULL */ |
| 585 | PyObject *name = PySequence_GetItem(fields, i); |
| 586 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 587 | res = -1; |
| 588 | goto cleanup; |
| 589 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 590 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 591 | Py_DECREF(name); |
| 592 | if (res < 0) |
| 593 | goto cleanup; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 594 | } |
| 595 | if (kw) { |
| 596 | i = 0; /* needed by PyDict_Next */ |
| 597 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 598 | res = PyObject_SetAttr(self, key, value); |
| 599 | if (res < 0) |
| 600 | goto cleanup; |
| 601 | } |
| 602 | } |
| 603 | cleanup: |
| 604 | Py_XDECREF(fields); |
| 605 | return res; |
| 606 | } |
| 607 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 608 | /* Pickling support */ |
| 609 | static PyObject * |
| 610 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 611 | { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 612 | _Py_IDENTIFIER(__dict__); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 613 | PyObject *dict; |
| 614 | if (_PyObject_LookupAttrId(self, &PyId___dict__, &dict) < 0) { |
| 615 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 616 | } |
| 617 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 618 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 619 | } |
| 620 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 621 | } |
| 622 | |
| 623 | static PyMethodDef ast_type_methods[] = { |
| 624 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 625 | {NULL} |
| 626 | }; |
| 627 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 628 | static PyGetSetDef ast_type_getsets[] = { |
| 629 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 630 | {NULL} |
| 631 | }; |
| 632 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 633 | static PyTypeObject AST_type = { |
| 634 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 635 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 636 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 637 | 0, |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 638 | (destructor)ast_dealloc, /* tp_dealloc */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 639 | 0, /* tp_print */ |
| 640 | 0, /* tp_getattr */ |
| 641 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 642 | 0, /* tp_reserved */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 643 | 0, /* tp_repr */ |
| 644 | 0, /* tp_as_number */ |
| 645 | 0, /* tp_as_sequence */ |
| 646 | 0, /* tp_as_mapping */ |
| 647 | 0, /* tp_hash */ |
| 648 | 0, /* tp_call */ |
| 649 | 0, /* tp_str */ |
| 650 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 651 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 652 | 0, /* tp_as_buffer */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 653 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 654 | 0, /* tp_doc */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 655 | (traverseproc)ast_traverse, /* tp_traverse */ |
| 656 | (inquiry)ast_clear, /* tp_clear */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 657 | 0, /* tp_richcompare */ |
| 658 | 0, /* tp_weaklistoffset */ |
| 659 | 0, /* tp_iter */ |
| 660 | 0, /* tp_iternext */ |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 661 | ast_type_methods, /* tp_methods */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 662 | 0, /* tp_members */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 663 | ast_type_getsets, /* tp_getset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 664 | 0, /* tp_base */ |
| 665 | 0, /* tp_dict */ |
| 666 | 0, /* tp_descr_get */ |
| 667 | 0, /* tp_descr_set */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 668 | offsetof(AST_object, dict),/* tp_dictoffset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 669 | (initproc)ast_type_init, /* tp_init */ |
| 670 | PyType_GenericAlloc, /* tp_alloc */ |
| 671 | PyType_GenericNew, /* tp_new */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 672 | PyObject_GC_Del, /* tp_free */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 673 | }; |
| 674 | |
| 675 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 676 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 677 | { |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 678 | _Py_IDENTIFIER(__module__); |
| 679 | _Py_IDENTIFIER(_ast); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 680 | PyObject *fnames, *result; |
| 681 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 682 | fnames = PyTuple_New(num_fields); |
| 683 | if (!fnames) return NULL; |
| 684 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 685 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 686 | if (!field) { |
| 687 | Py_DECREF(fnames); |
| 688 | return NULL; |
| 689 | } |
| 690 | PyTuple_SET_ITEM(fnames, i, field); |
| 691 | } |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 692 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}", |
| 693 | type, base, |
| 694 | _PyUnicode_FromId(&PyId__fields), fnames, |
| 695 | _PyUnicode_FromId(&PyId___module__), |
| 696 | _PyUnicode_FromId(&PyId__ast)); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 697 | Py_DECREF(fnames); |
| 698 | return (PyTypeObject*)result; |
| 699 | } |
| 700 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 701 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 702 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 703 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 704 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 705 | if (!l) |
| 706 | return 0; |
| 707 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 708 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 709 | if (!s) { |
| 710 | Py_DECREF(l); |
| 711 | return 0; |
| 712 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 713 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 714 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 715 | result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 716 | Py_DECREF(l); |
| 717 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 718 | } |
| 719 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 720 | /* Conversion AST -> Python */ |
| 721 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 722 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 723 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 724 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 725 | PyObject *result = PyList_New(n); |
| 726 | PyObject *value; |
| 727 | if (!result) |
| 728 | return NULL; |
| 729 | for (i = 0; i < n; i++) { |
| 730 | value = func(asdl_seq_GET(seq, i)); |
| 731 | if (!value) { |
| 732 | Py_DECREF(result); |
| 733 | return NULL; |
| 734 | } |
| 735 | PyList_SET_ITEM(result, i, value); |
| 736 | } |
| 737 | return result; |
| 738 | } |
| 739 | |
| 740 | static PyObject* ast2obj_object(void *o) |
| 741 | { |
| 742 | if (!o) |
| 743 | o = Py_None; |
| 744 | Py_INCREF((PyObject*)o); |
| 745 | return (PyObject*)o; |
| 746 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 747 | #define ast2obj_singleton ast2obj_object |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 748 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 749 | #define ast2obj_identifier ast2obj_object |
| 750 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 751 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 752 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 753 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 754 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 755 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 756 | } |
| 757 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 758 | /* Conversion Python -> AST */ |
| 759 | |
| 760 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 761 | { |
| 762 | if (obj == Py_None) |
| 763 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 764 | if (obj) { |
| 765 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 766 | *out = NULL; |
| 767 | return -1; |
| 768 | } |
| 769 | Py_INCREF(obj); |
| 770 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 771 | *out = obj; |
| 772 | return 0; |
| 773 | } |
| 774 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 775 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 776 | { |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 777 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 778 | *out = NULL; |
| 779 | return -1; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 780 | } |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 781 | Py_INCREF(obj); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 782 | *out = obj; |
| 783 | return 0; |
| 784 | } |
| 785 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 786 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 787 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 788 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 789 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 790 | return 1; |
| 791 | } |
| 792 | return obj2ast_object(obj, out, arena); |
| 793 | } |
| 794 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 795 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 796 | { |
| 797 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
| 798 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 799 | return 1; |
| 800 | } |
| 801 | return obj2ast_object(obj, out, arena); |
| 802 | } |
| 803 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 804 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 805 | { |
| 806 | int i; |
| 807 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 808 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 809 | return 1; |
| 810 | } |
| 811 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 812 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 813 | if (i == -1 && PyErr_Occurred()) |
| 814 | return 1; |
| 815 | *out = i; |
| 816 | return 0; |
| 817 | } |
| 818 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 819 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 820 | { |
| 821 | PyObject *empty_tuple, *d; |
| 822 | if (PyType_Ready(&AST_type) < 0) |
| 823 | return -1; |
| 824 | d = AST_type.tp_dict; |
| 825 | empty_tuple = PyTuple_New(0); |
| 826 | if (!empty_tuple || |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 827 | _PyDict_SetItemId(d, &PyId__fields, empty_tuple) < 0 || |
| 828 | _PyDict_SetItemId(d, &PyId__attributes, empty_tuple) < 0) { |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 829 | Py_XDECREF(empty_tuple); |
| 830 | return -1; |
| 831 | } |
| 832 | Py_DECREF(empty_tuple); |
| 833 | return 0; |
| 834 | } |
| 835 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 836 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 837 | static int init_types(void) |
| 838 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 839 | static int initialized; |
| 840 | if (initialized) return 1; |
| 841 | if (add_ast_fields() < 0) return 0; |
| 842 | mod_type = make_type("mod", &AST_type, NULL, 0); |
| 843 | if (!mod_type) return 0; |
| 844 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 845 | Module_type = make_type("Module", mod_type, Module_fields, 2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 846 | if (!Module_type) return 0; |
| 847 | Interactive_type = make_type("Interactive", mod_type, Interactive_fields, |
| 848 | 1); |
| 849 | if (!Interactive_type) return 0; |
| 850 | Expression_type = make_type("Expression", mod_type, Expression_fields, 1); |
| 851 | if (!Expression_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 852 | FunctionType_type = make_type("FunctionType", mod_type, |
| 853 | FunctionType_fields, 2); |
| 854 | if (!FunctionType_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 855 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
| 856 | if (!Suite_type) return 0; |
| 857 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
| 858 | if (!stmt_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 859 | if (!add_attributes(stmt_type, stmt_attributes, 4)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 860 | FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 861 | 6); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 862 | if (!FunctionDef_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 863 | AsyncFunctionDef_type = make_type("AsyncFunctionDef", stmt_type, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 864 | AsyncFunctionDef_fields, 6); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 865 | if (!AsyncFunctionDef_type) return 0; |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 866 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 5); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 867 | if (!ClassDef_type) return 0; |
| 868 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
| 869 | if (!Return_type) return 0; |
| 870 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
| 871 | if (!Delete_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 872 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 873 | if (!Assign_type) return 0; |
| 874 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
| 875 | if (!AugAssign_type) return 0; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 876 | AnnAssign_type = make_type("AnnAssign", stmt_type, AnnAssign_fields, 4); |
| 877 | if (!AnnAssign_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 878 | For_type = make_type("For", stmt_type, For_fields, 5); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 879 | if (!For_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 880 | AsyncFor_type = make_type("AsyncFor", stmt_type, AsyncFor_fields, 5); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 881 | if (!AsyncFor_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 882 | While_type = make_type("While", stmt_type, While_fields, 3); |
| 883 | if (!While_type) return 0; |
| 884 | If_type = make_type("If", stmt_type, If_fields, 3); |
| 885 | if (!If_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 886 | With_type = make_type("With", stmt_type, With_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 887 | if (!With_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 888 | AsyncWith_type = make_type("AsyncWith", stmt_type, AsyncWith_fields, 3); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 889 | if (!AsyncWith_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 890 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
| 891 | if (!Raise_type) return 0; |
| 892 | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
| 893 | if (!Try_type) return 0; |
| 894 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
| 895 | if (!Assert_type) return 0; |
| 896 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
| 897 | if (!Import_type) return 0; |
| 898 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, 3); |
| 899 | if (!ImportFrom_type) return 0; |
| 900 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
| 901 | if (!Global_type) return 0; |
| 902 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 903 | if (!Nonlocal_type) return 0; |
| 904 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
| 905 | if (!Expr_type) return 0; |
| 906 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
| 907 | if (!Pass_type) return 0; |
| 908 | Break_type = make_type("Break", stmt_type, NULL, 0); |
| 909 | if (!Break_type) return 0; |
| 910 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
| 911 | if (!Continue_type) return 0; |
| 912 | expr_type = make_type("expr", &AST_type, NULL, 0); |
| 913 | if (!expr_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 914 | if (!add_attributes(expr_type, expr_attributes, 4)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 915 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
| 916 | if (!BoolOp_type) return 0; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 917 | NamedExpr_type = make_type("NamedExpr", expr_type, NamedExpr_fields, 2); |
| 918 | if (!NamedExpr_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 919 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
| 920 | if (!BinOp_type) return 0; |
| 921 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
| 922 | if (!UnaryOp_type) return 0; |
| 923 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
| 924 | if (!Lambda_type) return 0; |
| 925 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
| 926 | if (!IfExp_type) return 0; |
| 927 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
| 928 | if (!Dict_type) return 0; |
| 929 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 930 | if (!Set_type) return 0; |
| 931 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
| 932 | if (!ListComp_type) return 0; |
| 933 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 934 | if (!SetComp_type) return 0; |
| 935 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 936 | if (!DictComp_type) return 0; |
| 937 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 938 | GeneratorExp_fields, 2); |
| 939 | if (!GeneratorExp_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 940 | Await_type = make_type("Await", expr_type, Await_fields, 1); |
| 941 | if (!Await_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 942 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
| 943 | if (!Yield_type) return 0; |
| 944 | YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); |
| 945 | if (!YieldFrom_type) return 0; |
| 946 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
| 947 | if (!Compare_type) return 0; |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 948 | Call_type = make_type("Call", expr_type, Call_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 949 | if (!Call_type) return 0; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 950 | FormattedValue_type = make_type("FormattedValue", expr_type, |
| 951 | FormattedValue_fields, 3); |
| 952 | if (!FormattedValue_type) return 0; |
| 953 | JoinedStr_type = make_type("JoinedStr", expr_type, JoinedStr_fields, 1); |
| 954 | if (!JoinedStr_type) return 0; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 955 | Constant_type = make_type("Constant", expr_type, Constant_fields, 1); |
| 956 | if (!Constant_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 957 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
| 958 | if (!Attribute_type) return 0; |
| 959 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
| 960 | if (!Subscript_type) return 0; |
| 961 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 962 | if (!Starred_type) return 0; |
| 963 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
| 964 | if (!Name_type) return 0; |
| 965 | List_type = make_type("List", expr_type, List_fields, 2); |
| 966 | if (!List_type) return 0; |
| 967 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
| 968 | if (!Tuple_type) return 0; |
| 969 | expr_context_type = make_type("expr_context", &AST_type, NULL, 0); |
| 970 | if (!expr_context_type) return 0; |
| 971 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
| 972 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
| 973 | if (!Load_type) return 0; |
| 974 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
| 975 | if (!Load_singleton) return 0; |
| 976 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
| 977 | if (!Store_type) return 0; |
| 978 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
| 979 | if (!Store_singleton) return 0; |
| 980 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
| 981 | if (!Del_type) return 0; |
| 982 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
| 983 | if (!Del_singleton) return 0; |
| 984 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
| 985 | if (!AugLoad_type) return 0; |
| 986 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
| 987 | if (!AugLoad_singleton) return 0; |
| 988 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
| 989 | if (!AugStore_type) return 0; |
| 990 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
| 991 | if (!AugStore_singleton) return 0; |
| 992 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
| 993 | if (!Param_type) return 0; |
| 994 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
| 995 | if (!Param_singleton) return 0; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 996 | NamedStore_type = make_type("NamedStore", expr_context_type, NULL, 0); |
| 997 | if (!NamedStore_type) return 0; |
| 998 | NamedStore_singleton = PyType_GenericNew(NamedStore_type, NULL, NULL); |
| 999 | if (!NamedStore_singleton) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1000 | slice_type = make_type("slice", &AST_type, NULL, 0); |
| 1001 | if (!slice_type) return 0; |
| 1002 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
| 1003 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
| 1004 | if (!Slice_type) return 0; |
| 1005 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
| 1006 | if (!ExtSlice_type) return 0; |
| 1007 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
| 1008 | if (!Index_type) return 0; |
| 1009 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
| 1010 | if (!boolop_type) return 0; |
| 1011 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
| 1012 | And_type = make_type("And", boolop_type, NULL, 0); |
| 1013 | if (!And_type) return 0; |
| 1014 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
| 1015 | if (!And_singleton) return 0; |
| 1016 | Or_type = make_type("Or", boolop_type, NULL, 0); |
| 1017 | if (!Or_type) return 0; |
| 1018 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
| 1019 | if (!Or_singleton) return 0; |
| 1020 | operator_type = make_type("operator", &AST_type, NULL, 0); |
| 1021 | if (!operator_type) return 0; |
| 1022 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
| 1023 | Add_type = make_type("Add", operator_type, NULL, 0); |
| 1024 | if (!Add_type) return 0; |
| 1025 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
| 1026 | if (!Add_singleton) return 0; |
| 1027 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
| 1028 | if (!Sub_type) return 0; |
| 1029 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
| 1030 | if (!Sub_singleton) return 0; |
| 1031 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
| 1032 | if (!Mult_type) return 0; |
| 1033 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
| 1034 | if (!Mult_singleton) return 0; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 1035 | MatMult_type = make_type("MatMult", operator_type, NULL, 0); |
| 1036 | if (!MatMult_type) return 0; |
| 1037 | MatMult_singleton = PyType_GenericNew(MatMult_type, NULL, NULL); |
| 1038 | if (!MatMult_singleton) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1039 | Div_type = make_type("Div", operator_type, NULL, 0); |
| 1040 | if (!Div_type) return 0; |
| 1041 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
| 1042 | if (!Div_singleton) return 0; |
| 1043 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
| 1044 | if (!Mod_type) return 0; |
| 1045 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
| 1046 | if (!Mod_singleton) return 0; |
| 1047 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
| 1048 | if (!Pow_type) return 0; |
| 1049 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
| 1050 | if (!Pow_singleton) return 0; |
| 1051 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
| 1052 | if (!LShift_type) return 0; |
| 1053 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
| 1054 | if (!LShift_singleton) return 0; |
| 1055 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
| 1056 | if (!RShift_type) return 0; |
| 1057 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
| 1058 | if (!RShift_singleton) return 0; |
| 1059 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
| 1060 | if (!BitOr_type) return 0; |
| 1061 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
| 1062 | if (!BitOr_singleton) return 0; |
| 1063 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
| 1064 | if (!BitXor_type) return 0; |
| 1065 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
| 1066 | if (!BitXor_singleton) return 0; |
| 1067 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
| 1068 | if (!BitAnd_type) return 0; |
| 1069 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
| 1070 | if (!BitAnd_singleton) return 0; |
| 1071 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
| 1072 | if (!FloorDiv_type) return 0; |
| 1073 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
| 1074 | if (!FloorDiv_singleton) return 0; |
| 1075 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
| 1076 | if (!unaryop_type) return 0; |
| 1077 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
| 1078 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
| 1079 | if (!Invert_type) return 0; |
| 1080 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
| 1081 | if (!Invert_singleton) return 0; |
| 1082 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
| 1083 | if (!Not_type) return 0; |
| 1084 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
| 1085 | if (!Not_singleton) return 0; |
| 1086 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
| 1087 | if (!UAdd_type) return 0; |
| 1088 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
| 1089 | if (!UAdd_singleton) return 0; |
| 1090 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
| 1091 | if (!USub_type) return 0; |
| 1092 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
| 1093 | if (!USub_singleton) return 0; |
| 1094 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
| 1095 | if (!cmpop_type) return 0; |
| 1096 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
| 1097 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
| 1098 | if (!Eq_type) return 0; |
| 1099 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
| 1100 | if (!Eq_singleton) return 0; |
| 1101 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
| 1102 | if (!NotEq_type) return 0; |
| 1103 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
| 1104 | if (!NotEq_singleton) return 0; |
| 1105 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
| 1106 | if (!Lt_type) return 0; |
| 1107 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
| 1108 | if (!Lt_singleton) return 0; |
| 1109 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
| 1110 | if (!LtE_type) return 0; |
| 1111 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
| 1112 | if (!LtE_singleton) return 0; |
| 1113 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
| 1114 | if (!Gt_type) return 0; |
| 1115 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
| 1116 | if (!Gt_singleton) return 0; |
| 1117 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
| 1118 | if (!GtE_type) return 0; |
| 1119 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
| 1120 | if (!GtE_singleton) return 0; |
| 1121 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
| 1122 | if (!Is_type) return 0; |
| 1123 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
| 1124 | if (!Is_singleton) return 0; |
| 1125 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
| 1126 | if (!IsNot_type) return 0; |
| 1127 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
| 1128 | if (!IsNot_singleton) return 0; |
| 1129 | In_type = make_type("In", cmpop_type, NULL, 0); |
| 1130 | if (!In_type) return 0; |
| 1131 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
| 1132 | if (!In_singleton) return 0; |
| 1133 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
| 1134 | if (!NotIn_type) return 0; |
| 1135 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
| 1136 | if (!NotIn_singleton) return 0; |
| 1137 | comprehension_type = make_type("comprehension", &AST_type, |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 1138 | comprehension_fields, 4); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1139 | if (!comprehension_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1140 | if (!add_attributes(comprehension_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1141 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
| 1142 | if (!excepthandler_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1143 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 4)) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1144 | return 0; |
| 1145 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 1146 | ExceptHandler_fields, 3); |
| 1147 | if (!ExceptHandler_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1148 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 6); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1149 | if (!arguments_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1150 | if (!add_attributes(arguments_type, NULL, 0)) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1151 | arg_type = make_type("arg", &AST_type, arg_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1152 | if (!arg_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1153 | if (!add_attributes(arg_type, arg_attributes, 4)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1154 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
| 1155 | if (!keyword_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1156 | if (!add_attributes(keyword_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1157 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
| 1158 | if (!alias_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1159 | if (!add_attributes(alias_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1160 | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
| 1161 | if (!withitem_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1162 | if (!add_attributes(withitem_type, NULL, 0)) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1163 | type_ignore_type = make_type("type_ignore", &AST_type, NULL, 0); |
| 1164 | if (!type_ignore_type) return 0; |
| 1165 | if (!add_attributes(type_ignore_type, NULL, 0)) return 0; |
| 1166 | TypeIgnore_type = make_type("TypeIgnore", type_ignore_type, |
| 1167 | TypeIgnore_fields, 1); |
| 1168 | if (!TypeIgnore_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1169 | initialized = 1; |
| 1170 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1171 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1172 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1173 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1174 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1175 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1176 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1177 | arena); |
| 1178 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1179 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1180 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1181 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1182 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1183 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1184 | arena); |
| 1185 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1186 | arena); |
| 1187 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1188 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1189 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1190 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1191 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1192 | static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* |
| 1193 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1194 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1195 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1196 | Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1197 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1198 | mod_ty p; |
| 1199 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1200 | if (!p) |
| 1201 | return NULL; |
| 1202 | p->kind = Module_kind; |
| 1203 | p->v.Module.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1204 | p->v.Module.type_ignores = type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1205 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1209 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1210 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1211 | mod_ty p; |
| 1212 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1213 | if (!p) |
| 1214 | return NULL; |
| 1215 | p->kind = Interactive_kind; |
| 1216 | p->v.Interactive.body = body; |
| 1217 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1221 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1222 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1223 | mod_ty p; |
| 1224 | if (!body) { |
| 1225 | PyErr_SetString(PyExc_ValueError, |
| 1226 | "field body is required for Expression"); |
| 1227 | return NULL; |
| 1228 | } |
| 1229 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1230 | if (!p) |
| 1231 | return NULL; |
| 1232 | p->kind = Expression_kind; |
| 1233 | p->v.Expression.body = body; |
| 1234 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1238 | FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena) |
| 1239 | { |
| 1240 | mod_ty p; |
| 1241 | if (!returns) { |
| 1242 | PyErr_SetString(PyExc_ValueError, |
| 1243 | "field returns is required for FunctionType"); |
| 1244 | return NULL; |
| 1245 | } |
| 1246 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1247 | if (!p) |
| 1248 | return NULL; |
| 1249 | p->kind = FunctionType_kind; |
| 1250 | p->v.FunctionType.argtypes = argtypes; |
| 1251 | p->v.FunctionType.returns = returns; |
| 1252 | return p; |
| 1253 | } |
| 1254 | |
| 1255 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1256 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1257 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1258 | mod_ty p; |
| 1259 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1260 | if (!p) |
| 1261 | return NULL; |
| 1262 | p->kind = Suite_kind; |
| 1263 | p->v.Suite.body = body; |
| 1264 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | stmt_ty |
| 1268 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1269 | decorator_list, expr_ty returns, string type_comment, int lineno, |
| 1270 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1271 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1272 | stmt_ty p; |
| 1273 | if (!name) { |
| 1274 | PyErr_SetString(PyExc_ValueError, |
| 1275 | "field name is required for FunctionDef"); |
| 1276 | return NULL; |
| 1277 | } |
| 1278 | if (!args) { |
| 1279 | PyErr_SetString(PyExc_ValueError, |
| 1280 | "field args is required for FunctionDef"); |
| 1281 | return NULL; |
| 1282 | } |
| 1283 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1284 | if (!p) |
| 1285 | return NULL; |
| 1286 | p->kind = FunctionDef_kind; |
| 1287 | p->v.FunctionDef.name = name; |
| 1288 | p->v.FunctionDef.args = args; |
| 1289 | p->v.FunctionDef.body = body; |
| 1290 | p->v.FunctionDef.decorator_list = decorator_list; |
| 1291 | p->v.FunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1292 | p->v.FunctionDef.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1293 | p->lineno = lineno; |
| 1294 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1295 | p->end_lineno = end_lineno; |
| 1296 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1297 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1301 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1302 | * decorator_list, expr_ty returns, string type_comment, int |
| 1303 | lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1304 | PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1305 | { |
| 1306 | stmt_ty p; |
| 1307 | if (!name) { |
| 1308 | PyErr_SetString(PyExc_ValueError, |
| 1309 | "field name is required for AsyncFunctionDef"); |
| 1310 | return NULL; |
| 1311 | } |
| 1312 | if (!args) { |
| 1313 | PyErr_SetString(PyExc_ValueError, |
| 1314 | "field args is required for AsyncFunctionDef"); |
| 1315 | return NULL; |
| 1316 | } |
| 1317 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1318 | if (!p) |
| 1319 | return NULL; |
| 1320 | p->kind = AsyncFunctionDef_kind; |
| 1321 | p->v.AsyncFunctionDef.name = name; |
| 1322 | p->v.AsyncFunctionDef.args = args; |
| 1323 | p->v.AsyncFunctionDef.body = body; |
| 1324 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 1325 | p->v.AsyncFunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1326 | p->v.AsyncFunctionDef.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1327 | p->lineno = lineno; |
| 1328 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1329 | p->end_lineno = end_lineno; |
| 1330 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1331 | return p; |
| 1332 | } |
| 1333 | |
| 1334 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 1335 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1336 | body, asdl_seq * decorator_list, int lineno, int col_offset, int |
| 1337 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1338 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1339 | stmt_ty p; |
| 1340 | if (!name) { |
| 1341 | PyErr_SetString(PyExc_ValueError, |
| 1342 | "field name is required for ClassDef"); |
| 1343 | return NULL; |
| 1344 | } |
| 1345 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1346 | if (!p) |
| 1347 | return NULL; |
| 1348 | p->kind = ClassDef_kind; |
| 1349 | p->v.ClassDef.name = name; |
| 1350 | p->v.ClassDef.bases = bases; |
| 1351 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1352 | p->v.ClassDef.body = body; |
| 1353 | p->v.ClassDef.decorator_list = decorator_list; |
| 1354 | p->lineno = lineno; |
| 1355 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1356 | p->end_lineno = end_lineno; |
| 1357 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1358 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1362 | Return(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 1363 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1364 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1365 | stmt_ty p; |
| 1366 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1367 | if (!p) |
| 1368 | return NULL; |
| 1369 | p->kind = Return_kind; |
| 1370 | p->v.Return.value = value; |
| 1371 | p->lineno = lineno; |
| 1372 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1373 | p->end_lineno = end_lineno; |
| 1374 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1375 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1379 | Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int |
| 1380 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1381 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1382 | stmt_ty p; |
| 1383 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1384 | if (!p) |
| 1385 | return NULL; |
| 1386 | p->kind = Delete_kind; |
| 1387 | p->v.Delete.targets = targets; |
| 1388 | p->lineno = lineno; |
| 1389 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1390 | p->end_lineno = end_lineno; |
| 1391 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1392 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1396 | Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int |
| 1397 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1398 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1399 | stmt_ty p; |
| 1400 | if (!value) { |
| 1401 | PyErr_SetString(PyExc_ValueError, |
| 1402 | "field value is required for Assign"); |
| 1403 | return NULL; |
| 1404 | } |
| 1405 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1406 | if (!p) |
| 1407 | return NULL; |
| 1408 | p->kind = Assign_kind; |
| 1409 | p->v.Assign.targets = targets; |
| 1410 | p->v.Assign.value = value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1411 | p->v.Assign.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1412 | p->lineno = lineno; |
| 1413 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1414 | p->end_lineno = end_lineno; |
| 1415 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1416 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1420 | 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] | 1421 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1422 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1423 | stmt_ty p; |
| 1424 | if (!target) { |
| 1425 | PyErr_SetString(PyExc_ValueError, |
| 1426 | "field target is required for AugAssign"); |
| 1427 | return NULL; |
| 1428 | } |
| 1429 | if (!op) { |
| 1430 | PyErr_SetString(PyExc_ValueError, |
| 1431 | "field op is required for AugAssign"); |
| 1432 | return NULL; |
| 1433 | } |
| 1434 | if (!value) { |
| 1435 | PyErr_SetString(PyExc_ValueError, |
| 1436 | "field value is required for AugAssign"); |
| 1437 | return NULL; |
| 1438 | } |
| 1439 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1440 | if (!p) |
| 1441 | return NULL; |
| 1442 | p->kind = AugAssign_kind; |
| 1443 | p->v.AugAssign.target = target; |
| 1444 | p->v.AugAssign.op = op; |
| 1445 | p->v.AugAssign.value = value; |
| 1446 | p->lineno = lineno; |
| 1447 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1448 | p->end_lineno = end_lineno; |
| 1449 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1450 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 1454 | 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] | 1455 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1456 | *arena) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 1457 | { |
| 1458 | stmt_ty p; |
| 1459 | if (!target) { |
| 1460 | PyErr_SetString(PyExc_ValueError, |
| 1461 | "field target is required for AnnAssign"); |
| 1462 | return NULL; |
| 1463 | } |
| 1464 | if (!annotation) { |
| 1465 | PyErr_SetString(PyExc_ValueError, |
| 1466 | "field annotation is required for AnnAssign"); |
| 1467 | return NULL; |
| 1468 | } |
| 1469 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1470 | if (!p) |
| 1471 | return NULL; |
| 1472 | p->kind = AnnAssign_kind; |
| 1473 | p->v.AnnAssign.target = target; |
| 1474 | p->v.AnnAssign.annotation = annotation; |
| 1475 | p->v.AnnAssign.value = value; |
| 1476 | p->v.AnnAssign.simple = simple; |
| 1477 | p->lineno = lineno; |
| 1478 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1479 | p->end_lineno = end_lineno; |
| 1480 | p->end_col_offset = end_col_offset; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 1481 | return p; |
| 1482 | } |
| 1483 | |
| 1484 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1485 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string |
| 1486 | type_comment, int lineno, int col_offset, int end_lineno, int |
| 1487 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1488 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1489 | stmt_ty p; |
| 1490 | if (!target) { |
| 1491 | PyErr_SetString(PyExc_ValueError, |
| 1492 | "field target is required for For"); |
| 1493 | return NULL; |
| 1494 | } |
| 1495 | if (!iter) { |
| 1496 | PyErr_SetString(PyExc_ValueError, |
| 1497 | "field iter is required for For"); |
| 1498 | return NULL; |
| 1499 | } |
| 1500 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1501 | if (!p) |
| 1502 | return NULL; |
| 1503 | p->kind = For_kind; |
| 1504 | p->v.For.target = target; |
| 1505 | p->v.For.iter = iter; |
| 1506 | p->v.For.body = body; |
| 1507 | p->v.For.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1508 | p->v.For.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1509 | p->lineno = lineno; |
| 1510 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1511 | p->end_lineno = end_lineno; |
| 1512 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1513 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1517 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, |
| 1518 | string type_comment, int lineno, int col_offset, int end_lineno, int |
| 1519 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1520 | { |
| 1521 | stmt_ty p; |
| 1522 | if (!target) { |
| 1523 | PyErr_SetString(PyExc_ValueError, |
| 1524 | "field target is required for AsyncFor"); |
| 1525 | return NULL; |
| 1526 | } |
| 1527 | if (!iter) { |
| 1528 | PyErr_SetString(PyExc_ValueError, |
| 1529 | "field iter is required for AsyncFor"); |
| 1530 | return NULL; |
| 1531 | } |
| 1532 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1533 | if (!p) |
| 1534 | return NULL; |
| 1535 | p->kind = AsyncFor_kind; |
| 1536 | p->v.AsyncFor.target = target; |
| 1537 | p->v.AsyncFor.iter = iter; |
| 1538 | p->v.AsyncFor.body = body; |
| 1539 | p->v.AsyncFor.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1540 | p->v.AsyncFor.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1541 | p->lineno = lineno; |
| 1542 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1543 | p->end_lineno = end_lineno; |
| 1544 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1545 | return p; |
| 1546 | } |
| 1547 | |
| 1548 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1549 | 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] | 1550 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1551 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1552 | stmt_ty p; |
| 1553 | if (!test) { |
| 1554 | PyErr_SetString(PyExc_ValueError, |
| 1555 | "field test is required for While"); |
| 1556 | return NULL; |
| 1557 | } |
| 1558 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1559 | if (!p) |
| 1560 | return NULL; |
| 1561 | p->kind = While_kind; |
| 1562 | p->v.While.test = test; |
| 1563 | p->v.While.body = body; |
| 1564 | p->v.While.orelse = orelse; |
| 1565 | p->lineno = lineno; |
| 1566 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1567 | p->end_lineno = end_lineno; |
| 1568 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1569 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1573 | 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] | 1574 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1575 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1576 | stmt_ty p; |
| 1577 | if (!test) { |
| 1578 | PyErr_SetString(PyExc_ValueError, |
| 1579 | "field test is required for If"); |
| 1580 | return NULL; |
| 1581 | } |
| 1582 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1583 | if (!p) |
| 1584 | return NULL; |
| 1585 | p->kind = If_kind; |
| 1586 | p->v.If.test = test; |
| 1587 | p->v.If.body = body; |
| 1588 | p->v.If.orelse = orelse; |
| 1589 | p->lineno = lineno; |
| 1590 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1591 | p->end_lineno = end_lineno; |
| 1592 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1593 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1597 | With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int |
| 1598 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1599 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1600 | stmt_ty p; |
| 1601 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1602 | if (!p) |
| 1603 | return NULL; |
| 1604 | p->kind = With_kind; |
| 1605 | p->v.With.items = items; |
| 1606 | p->v.With.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1607 | p->v.With.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1608 | p->lineno = lineno; |
| 1609 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1610 | p->end_lineno = end_lineno; |
| 1611 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1612 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1616 | AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, |
| 1617 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1618 | { |
| 1619 | stmt_ty p; |
| 1620 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1621 | if (!p) |
| 1622 | return NULL; |
| 1623 | p->kind = AsyncWith_kind; |
| 1624 | p->v.AsyncWith.items = items; |
| 1625 | p->v.AsyncWith.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1626 | p->v.AsyncWith.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1627 | p->lineno = lineno; |
| 1628 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1629 | p->end_lineno = end_lineno; |
| 1630 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1631 | return p; |
| 1632 | } |
| 1633 | |
| 1634 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1635 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, |
| 1636 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1637 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1638 | stmt_ty p; |
| 1639 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1640 | if (!p) |
| 1641 | return NULL; |
| 1642 | p->kind = Raise_kind; |
| 1643 | p->v.Raise.exc = exc; |
| 1644 | p->v.Raise.cause = cause; |
| 1645 | p->lineno = lineno; |
| 1646 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1647 | p->end_lineno = end_lineno; |
| 1648 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1649 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1653 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1654 | finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1655 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1656 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1657 | stmt_ty p; |
| 1658 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1659 | if (!p) |
| 1660 | return NULL; |
| 1661 | p->kind = Try_kind; |
| 1662 | p->v.Try.body = body; |
| 1663 | p->v.Try.handlers = handlers; |
| 1664 | p->v.Try.orelse = orelse; |
| 1665 | p->v.Try.finalbody = finalbody; |
| 1666 | p->lineno = lineno; |
| 1667 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1668 | p->end_lineno = end_lineno; |
| 1669 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1670 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1674 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, |
| 1675 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1676 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1677 | stmt_ty p; |
| 1678 | if (!test) { |
| 1679 | PyErr_SetString(PyExc_ValueError, |
| 1680 | "field test is required for Assert"); |
| 1681 | return NULL; |
| 1682 | } |
| 1683 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1684 | if (!p) |
| 1685 | return NULL; |
| 1686 | p->kind = Assert_kind; |
| 1687 | p->v.Assert.test = test; |
| 1688 | p->v.Assert.msg = msg; |
| 1689 | p->lineno = lineno; |
| 1690 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1691 | p->end_lineno = end_lineno; |
| 1692 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1693 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1697 | Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 1698 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1699 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1700 | stmt_ty p; |
| 1701 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1702 | if (!p) |
| 1703 | return NULL; |
| 1704 | p->kind = Import_kind; |
| 1705 | p->v.Import.names = names; |
| 1706 | p->lineno = lineno; |
| 1707 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1708 | p->end_lineno = end_lineno; |
| 1709 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1710 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1714 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1715 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1716 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1717 | stmt_ty p; |
| 1718 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1719 | if (!p) |
| 1720 | return NULL; |
| 1721 | p->kind = ImportFrom_kind; |
| 1722 | p->v.ImportFrom.module = module; |
| 1723 | p->v.ImportFrom.names = names; |
| 1724 | p->v.ImportFrom.level = level; |
| 1725 | p->lineno = lineno; |
| 1726 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1727 | p->end_lineno = end_lineno; |
| 1728 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1729 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1733 | Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 1734 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1735 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1736 | stmt_ty p; |
| 1737 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1738 | if (!p) |
| 1739 | return NULL; |
| 1740 | p->kind = Global_kind; |
| 1741 | p->v.Global.names = names; |
| 1742 | p->lineno = lineno; |
| 1743 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1744 | p->end_lineno = end_lineno; |
| 1745 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1746 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1750 | Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 1751 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1752 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1753 | stmt_ty p; |
| 1754 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1755 | if (!p) |
| 1756 | return NULL; |
| 1757 | p->kind = Nonlocal_kind; |
| 1758 | p->v.Nonlocal.names = names; |
| 1759 | p->lineno = lineno; |
| 1760 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1761 | p->end_lineno = end_lineno; |
| 1762 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1763 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1767 | Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 1768 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1769 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1770 | stmt_ty p; |
| 1771 | if (!value) { |
| 1772 | PyErr_SetString(PyExc_ValueError, |
| 1773 | "field value is required for Expr"); |
| 1774 | return NULL; |
| 1775 | } |
| 1776 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1777 | if (!p) |
| 1778 | return NULL; |
| 1779 | p->kind = Expr_kind; |
| 1780 | p->v.Expr.value = value; |
| 1781 | p->lineno = lineno; |
| 1782 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1783 | p->end_lineno = end_lineno; |
| 1784 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1785 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1789 | Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1790 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1791 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1792 | stmt_ty p; |
| 1793 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1794 | if (!p) |
| 1795 | return NULL; |
| 1796 | p->kind = Pass_kind; |
| 1797 | p->lineno = lineno; |
| 1798 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1799 | p->end_lineno = end_lineno; |
| 1800 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1801 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1805 | Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1806 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1807 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1808 | stmt_ty p; |
| 1809 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1810 | if (!p) |
| 1811 | return NULL; |
| 1812 | p->kind = Break_kind; |
| 1813 | p->lineno = lineno; |
| 1814 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1815 | p->end_lineno = end_lineno; |
| 1816 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1817 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1821 | Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1822 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1823 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1824 | stmt_ty p; |
| 1825 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1826 | if (!p) |
| 1827 | return NULL; |
| 1828 | p->kind = Continue_kind; |
| 1829 | p->lineno = lineno; |
| 1830 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1831 | p->end_lineno = end_lineno; |
| 1832 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1833 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1837 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int |
| 1838 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1839 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1840 | expr_ty p; |
| 1841 | if (!op) { |
| 1842 | PyErr_SetString(PyExc_ValueError, |
| 1843 | "field op is required for BoolOp"); |
| 1844 | return NULL; |
| 1845 | } |
| 1846 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1847 | if (!p) |
| 1848 | return NULL; |
| 1849 | p->kind = BoolOp_kind; |
| 1850 | p->v.BoolOp.op = op; |
| 1851 | p->v.BoolOp.values = values; |
| 1852 | p->lineno = lineno; |
| 1853 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1854 | p->end_lineno = end_lineno; |
| 1855 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1856 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | expr_ty |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 1860 | NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int |
| 1861 | end_lineno, int end_col_offset, PyArena *arena) |
| 1862 | { |
| 1863 | expr_ty p; |
| 1864 | if (!target) { |
| 1865 | PyErr_SetString(PyExc_ValueError, |
| 1866 | "field target is required for NamedExpr"); |
| 1867 | return NULL; |
| 1868 | } |
| 1869 | if (!value) { |
| 1870 | PyErr_SetString(PyExc_ValueError, |
| 1871 | "field value is required for NamedExpr"); |
| 1872 | return NULL; |
| 1873 | } |
| 1874 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1875 | if (!p) |
| 1876 | return NULL; |
| 1877 | p->kind = NamedExpr_kind; |
| 1878 | p->v.NamedExpr.target = target; |
| 1879 | p->v.NamedExpr.value = value; |
| 1880 | p->lineno = lineno; |
| 1881 | p->col_offset = col_offset; |
| 1882 | p->end_lineno = end_lineno; |
| 1883 | p->end_col_offset = end_col_offset; |
| 1884 | return p; |
| 1885 | } |
| 1886 | |
| 1887 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1888 | 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] | 1889 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1890 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1891 | expr_ty p; |
| 1892 | if (!left) { |
| 1893 | PyErr_SetString(PyExc_ValueError, |
| 1894 | "field left is required for BinOp"); |
| 1895 | return NULL; |
| 1896 | } |
| 1897 | if (!op) { |
| 1898 | PyErr_SetString(PyExc_ValueError, |
| 1899 | "field op is required for BinOp"); |
| 1900 | return NULL; |
| 1901 | } |
| 1902 | if (!right) { |
| 1903 | PyErr_SetString(PyExc_ValueError, |
| 1904 | "field right is required for BinOp"); |
| 1905 | return NULL; |
| 1906 | } |
| 1907 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1908 | if (!p) |
| 1909 | return NULL; |
| 1910 | p->kind = BinOp_kind; |
| 1911 | p->v.BinOp.left = left; |
| 1912 | p->v.BinOp.op = op; |
| 1913 | p->v.BinOp.right = right; |
| 1914 | p->lineno = lineno; |
| 1915 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1916 | p->end_lineno = end_lineno; |
| 1917 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1918 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1922 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int |
| 1923 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1924 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1925 | expr_ty p; |
| 1926 | if (!op) { |
| 1927 | PyErr_SetString(PyExc_ValueError, |
| 1928 | "field op is required for UnaryOp"); |
| 1929 | return NULL; |
| 1930 | } |
| 1931 | if (!operand) { |
| 1932 | PyErr_SetString(PyExc_ValueError, |
| 1933 | "field operand is required for UnaryOp"); |
| 1934 | return NULL; |
| 1935 | } |
| 1936 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1937 | if (!p) |
| 1938 | return NULL; |
| 1939 | p->kind = UnaryOp_kind; |
| 1940 | p->v.UnaryOp.op = op; |
| 1941 | p->v.UnaryOp.operand = operand; |
| 1942 | p->lineno = lineno; |
| 1943 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1944 | p->end_lineno = end_lineno; |
| 1945 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1946 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1950 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int |
| 1951 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1952 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1953 | expr_ty p; |
| 1954 | if (!args) { |
| 1955 | PyErr_SetString(PyExc_ValueError, |
| 1956 | "field args is required for Lambda"); |
| 1957 | return NULL; |
| 1958 | } |
| 1959 | if (!body) { |
| 1960 | PyErr_SetString(PyExc_ValueError, |
| 1961 | "field body is required for Lambda"); |
| 1962 | return NULL; |
| 1963 | } |
| 1964 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1965 | if (!p) |
| 1966 | return NULL; |
| 1967 | p->kind = Lambda_kind; |
| 1968 | p->v.Lambda.args = args; |
| 1969 | p->v.Lambda.body = body; |
| 1970 | p->lineno = lineno; |
| 1971 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1972 | p->end_lineno = end_lineno; |
| 1973 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1974 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1978 | 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] | 1979 | int end_lineno, int end_col_offset, PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1980 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1981 | expr_ty p; |
| 1982 | if (!test) { |
| 1983 | PyErr_SetString(PyExc_ValueError, |
| 1984 | "field test is required for IfExp"); |
| 1985 | return NULL; |
| 1986 | } |
| 1987 | if (!body) { |
| 1988 | PyErr_SetString(PyExc_ValueError, |
| 1989 | "field body is required for IfExp"); |
| 1990 | return NULL; |
| 1991 | } |
| 1992 | if (!orelse) { |
| 1993 | PyErr_SetString(PyExc_ValueError, |
| 1994 | "field orelse is required for IfExp"); |
| 1995 | return NULL; |
| 1996 | } |
| 1997 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1998 | if (!p) |
| 1999 | return NULL; |
| 2000 | p->kind = IfExp_kind; |
| 2001 | p->v.IfExp.test = test; |
| 2002 | p->v.IfExp.body = body; |
| 2003 | p->v.IfExp.orelse = orelse; |
| 2004 | p->lineno = lineno; |
| 2005 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2006 | p->end_lineno = end_lineno; |
| 2007 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2008 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2012 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int |
| 2013 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2014 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2015 | expr_ty p; |
| 2016 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2017 | if (!p) |
| 2018 | return NULL; |
| 2019 | p->kind = Dict_kind; |
| 2020 | p->v.Dict.keys = keys; |
| 2021 | p->v.Dict.values = values; |
| 2022 | p->lineno = lineno; |
| 2023 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2024 | p->end_lineno = end_lineno; |
| 2025 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2026 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2030 | Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int |
| 2031 | end_col_offset, PyArena *arena) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2032 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2033 | expr_ty p; |
| 2034 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2035 | if (!p) |
| 2036 | return NULL; |
| 2037 | p->kind = Set_kind; |
| 2038 | p->v.Set.elts = elts; |
| 2039 | p->lineno = lineno; |
| 2040 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2041 | p->end_lineno = end_lineno; |
| 2042 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2043 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2047 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2048 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2049 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2050 | expr_ty p; |
| 2051 | if (!elt) { |
| 2052 | PyErr_SetString(PyExc_ValueError, |
| 2053 | "field elt is required for ListComp"); |
| 2054 | return NULL; |
| 2055 | } |
| 2056 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2057 | if (!p) |
| 2058 | return NULL; |
| 2059 | p->kind = ListComp_kind; |
| 2060 | p->v.ListComp.elt = elt; |
| 2061 | p->v.ListComp.generators = generators; |
| 2062 | p->lineno = lineno; |
| 2063 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2064 | p->end_lineno = end_lineno; |
| 2065 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2066 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2070 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2071 | end_lineno, int end_col_offset, PyArena *arena) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2072 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2073 | expr_ty p; |
| 2074 | if (!elt) { |
| 2075 | PyErr_SetString(PyExc_ValueError, |
| 2076 | "field elt is required for SetComp"); |
| 2077 | return NULL; |
| 2078 | } |
| 2079 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2080 | if (!p) |
| 2081 | return NULL; |
| 2082 | p->kind = SetComp_kind; |
| 2083 | p->v.SetComp.elt = elt; |
| 2084 | p->v.SetComp.generators = generators; |
| 2085 | p->lineno = lineno; |
| 2086 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2087 | p->end_lineno = end_lineno; |
| 2088 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2089 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2093 | 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] | 2094 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2095 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2096 | expr_ty p; |
| 2097 | if (!key) { |
| 2098 | PyErr_SetString(PyExc_ValueError, |
| 2099 | "field key is required for DictComp"); |
| 2100 | return NULL; |
| 2101 | } |
| 2102 | if (!value) { |
| 2103 | PyErr_SetString(PyExc_ValueError, |
| 2104 | "field value is required for DictComp"); |
| 2105 | return NULL; |
| 2106 | } |
| 2107 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2108 | if (!p) |
| 2109 | return NULL; |
| 2110 | p->kind = DictComp_kind; |
| 2111 | p->v.DictComp.key = key; |
| 2112 | p->v.DictComp.value = value; |
| 2113 | p->v.DictComp.generators = generators; |
| 2114 | p->lineno = lineno; |
| 2115 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2116 | p->end_lineno = end_lineno; |
| 2117 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2118 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2122 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2123 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2124 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2125 | expr_ty p; |
| 2126 | if (!elt) { |
| 2127 | PyErr_SetString(PyExc_ValueError, |
| 2128 | "field elt is required for GeneratorExp"); |
| 2129 | return NULL; |
| 2130 | } |
| 2131 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2132 | if (!p) |
| 2133 | return NULL; |
| 2134 | p->kind = GeneratorExp_kind; |
| 2135 | p->v.GeneratorExp.elt = elt; |
| 2136 | p->v.GeneratorExp.generators = generators; |
| 2137 | p->lineno = lineno; |
| 2138 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2139 | p->end_lineno = end_lineno; |
| 2140 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2141 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2145 | Await(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2146 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2147 | { |
| 2148 | expr_ty p; |
| 2149 | if (!value) { |
| 2150 | PyErr_SetString(PyExc_ValueError, |
| 2151 | "field value is required for Await"); |
| 2152 | return NULL; |
| 2153 | } |
| 2154 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2155 | if (!p) |
| 2156 | return NULL; |
| 2157 | p->kind = Await_kind; |
| 2158 | p->v.Await.value = value; |
| 2159 | p->lineno = lineno; |
| 2160 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2161 | p->end_lineno = end_lineno; |
| 2162 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2163 | return p; |
| 2164 | } |
| 2165 | |
| 2166 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2167 | Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2168 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2169 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2170 | expr_ty p; |
| 2171 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2172 | if (!p) |
| 2173 | return NULL; |
| 2174 | p->kind = Yield_kind; |
| 2175 | p->v.Yield.value = value; |
| 2176 | p->lineno = lineno; |
| 2177 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2178 | p->end_lineno = end_lineno; |
| 2179 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2180 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2181 | } |
| 2182 | |
| 2183 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2184 | YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2185 | end_col_offset, PyArena *arena) |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2186 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2187 | expr_ty p; |
| 2188 | if (!value) { |
| 2189 | PyErr_SetString(PyExc_ValueError, |
| 2190 | "field value is required for YieldFrom"); |
| 2191 | return NULL; |
| 2192 | } |
| 2193 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2194 | if (!p) |
| 2195 | return NULL; |
| 2196 | p->kind = YieldFrom_kind; |
| 2197 | p->v.YieldFrom.value = value; |
| 2198 | p->lineno = lineno; |
| 2199 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2200 | p->end_lineno = end_lineno; |
| 2201 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2202 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2203 | } |
| 2204 | |
| 2205 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2206 | 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] | 2207 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2208 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2209 | expr_ty p; |
| 2210 | if (!left) { |
| 2211 | PyErr_SetString(PyExc_ValueError, |
| 2212 | "field left is required for Compare"); |
| 2213 | return NULL; |
| 2214 | } |
| 2215 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2216 | if (!p) |
| 2217 | return NULL; |
| 2218 | p->kind = Compare_kind; |
| 2219 | p->v.Compare.left = left; |
| 2220 | p->v.Compare.ops = ops; |
| 2221 | p->v.Compare.comparators = comparators; |
| 2222 | p->lineno = lineno; |
| 2223 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2224 | p->end_lineno = end_lineno; |
| 2225 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2226 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2230 | 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] | 2231 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2232 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2233 | expr_ty p; |
| 2234 | if (!func) { |
| 2235 | PyErr_SetString(PyExc_ValueError, |
| 2236 | "field func is required for Call"); |
| 2237 | return NULL; |
| 2238 | } |
| 2239 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2240 | if (!p) |
| 2241 | return NULL; |
| 2242 | p->kind = Call_kind; |
| 2243 | p->v.Call.func = func; |
| 2244 | p->v.Call.args = args; |
| 2245 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2246 | p->lineno = lineno; |
| 2247 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2248 | p->end_lineno = end_lineno; |
| 2249 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2250 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2251 | } |
| 2252 | |
| 2253 | expr_ty |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2254 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2255 | int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2256 | *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2257 | { |
| 2258 | expr_ty p; |
| 2259 | if (!value) { |
| 2260 | PyErr_SetString(PyExc_ValueError, |
| 2261 | "field value is required for FormattedValue"); |
| 2262 | return NULL; |
| 2263 | } |
| 2264 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2265 | if (!p) |
| 2266 | return NULL; |
| 2267 | p->kind = FormattedValue_kind; |
| 2268 | p->v.FormattedValue.value = value; |
| 2269 | p->v.FormattedValue.conversion = conversion; |
| 2270 | p->v.FormattedValue.format_spec = format_spec; |
| 2271 | p->lineno = lineno; |
| 2272 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2273 | p->end_lineno = end_lineno; |
| 2274 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2275 | return p; |
| 2276 | } |
| 2277 | |
| 2278 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2279 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 2280 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2281 | { |
| 2282 | expr_ty p; |
| 2283 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2284 | if (!p) |
| 2285 | return NULL; |
| 2286 | p->kind = JoinedStr_kind; |
| 2287 | p->v.JoinedStr.values = values; |
| 2288 | p->lineno = lineno; |
| 2289 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2290 | p->end_lineno = end_lineno; |
| 2291 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2292 | return p; |
| 2293 | } |
| 2294 | |
| 2295 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2296 | Constant(constant value, int lineno, int col_offset, int end_lineno, int |
| 2297 | end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2298 | { |
| 2299 | expr_ty p; |
| 2300 | if (!value) { |
| 2301 | PyErr_SetString(PyExc_ValueError, |
| 2302 | "field value is required for Constant"); |
| 2303 | return NULL; |
| 2304 | } |
| 2305 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2306 | if (!p) |
| 2307 | return NULL; |
| 2308 | p->kind = Constant_kind; |
| 2309 | p->v.Constant.value = value; |
| 2310 | p->lineno = lineno; |
| 2311 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2312 | p->end_lineno = end_lineno; |
| 2313 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2314 | return p; |
| 2315 | } |
| 2316 | |
| 2317 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2318 | 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] | 2319 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2320 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2321 | expr_ty p; |
| 2322 | if (!value) { |
| 2323 | PyErr_SetString(PyExc_ValueError, |
| 2324 | "field value is required for Attribute"); |
| 2325 | return NULL; |
| 2326 | } |
| 2327 | if (!attr) { |
| 2328 | PyErr_SetString(PyExc_ValueError, |
| 2329 | "field attr is required for Attribute"); |
| 2330 | return NULL; |
| 2331 | } |
| 2332 | if (!ctx) { |
| 2333 | PyErr_SetString(PyExc_ValueError, |
| 2334 | "field ctx is required for Attribute"); |
| 2335 | return NULL; |
| 2336 | } |
| 2337 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2338 | if (!p) |
| 2339 | return NULL; |
| 2340 | p->kind = Attribute_kind; |
| 2341 | p->v.Attribute.value = value; |
| 2342 | p->v.Attribute.attr = attr; |
| 2343 | p->v.Attribute.ctx = ctx; |
| 2344 | p->lineno = lineno; |
| 2345 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2346 | p->end_lineno = end_lineno; |
| 2347 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2348 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2349 | } |
| 2350 | |
| 2351 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2352 | 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] | 2353 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2354 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2355 | expr_ty p; |
| 2356 | if (!value) { |
| 2357 | PyErr_SetString(PyExc_ValueError, |
| 2358 | "field value is required for Subscript"); |
| 2359 | return NULL; |
| 2360 | } |
| 2361 | if (!slice) { |
| 2362 | PyErr_SetString(PyExc_ValueError, |
| 2363 | "field slice is required for Subscript"); |
| 2364 | return NULL; |
| 2365 | } |
| 2366 | if (!ctx) { |
| 2367 | PyErr_SetString(PyExc_ValueError, |
| 2368 | "field ctx is required for Subscript"); |
| 2369 | return NULL; |
| 2370 | } |
| 2371 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2372 | if (!p) |
| 2373 | return NULL; |
| 2374 | p->kind = Subscript_kind; |
| 2375 | p->v.Subscript.value = value; |
| 2376 | p->v.Subscript.slice = slice; |
| 2377 | p->v.Subscript.ctx = ctx; |
| 2378 | p->lineno = lineno; |
| 2379 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2380 | p->end_lineno = end_lineno; |
| 2381 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2382 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2386 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 2387 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2388 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2389 | expr_ty p; |
| 2390 | if (!value) { |
| 2391 | PyErr_SetString(PyExc_ValueError, |
| 2392 | "field value is required for Starred"); |
| 2393 | return NULL; |
| 2394 | } |
| 2395 | if (!ctx) { |
| 2396 | PyErr_SetString(PyExc_ValueError, |
| 2397 | "field ctx is required for Starred"); |
| 2398 | return NULL; |
| 2399 | } |
| 2400 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2401 | if (!p) |
| 2402 | return NULL; |
| 2403 | p->kind = Starred_kind; |
| 2404 | p->v.Starred.value = value; |
| 2405 | p->v.Starred.ctx = ctx; |
| 2406 | p->lineno = lineno; |
| 2407 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2408 | p->end_lineno = end_lineno; |
| 2409 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2410 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2414 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 2415 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2416 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2417 | expr_ty p; |
| 2418 | if (!id) { |
| 2419 | PyErr_SetString(PyExc_ValueError, |
| 2420 | "field id is required for Name"); |
| 2421 | return NULL; |
| 2422 | } |
| 2423 | if (!ctx) { |
| 2424 | PyErr_SetString(PyExc_ValueError, |
| 2425 | "field ctx is required for Name"); |
| 2426 | return NULL; |
| 2427 | } |
| 2428 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2429 | if (!p) |
| 2430 | return NULL; |
| 2431 | p->kind = Name_kind; |
| 2432 | p->v.Name.id = id; |
| 2433 | p->v.Name.ctx = ctx; |
| 2434 | p->lineno = lineno; |
| 2435 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2436 | p->end_lineno = end_lineno; |
| 2437 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2438 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2439 | } |
| 2440 | |
| 2441 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2442 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 2443 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2444 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2445 | expr_ty p; |
| 2446 | if (!ctx) { |
| 2447 | PyErr_SetString(PyExc_ValueError, |
| 2448 | "field ctx is required for List"); |
| 2449 | return NULL; |
| 2450 | } |
| 2451 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2452 | if (!p) |
| 2453 | return NULL; |
| 2454 | p->kind = List_kind; |
| 2455 | p->v.List.elts = elts; |
| 2456 | p->v.List.ctx = ctx; |
| 2457 | p->lineno = lineno; |
| 2458 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2459 | p->end_lineno = end_lineno; |
| 2460 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2461 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2465 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 2466 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2467 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2468 | expr_ty p; |
| 2469 | if (!ctx) { |
| 2470 | PyErr_SetString(PyExc_ValueError, |
| 2471 | "field ctx is required for Tuple"); |
| 2472 | return NULL; |
| 2473 | } |
| 2474 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2475 | if (!p) |
| 2476 | return NULL; |
| 2477 | p->kind = Tuple_kind; |
| 2478 | p->v.Tuple.elts = elts; |
| 2479 | p->v.Tuple.ctx = ctx; |
| 2480 | p->lineno = lineno; |
| 2481 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2482 | p->end_lineno = end_lineno; |
| 2483 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2484 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2488 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2489 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2490 | slice_ty p; |
| 2491 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2492 | if (!p) |
| 2493 | return NULL; |
| 2494 | p->kind = Slice_kind; |
| 2495 | p->v.Slice.lower = lower; |
| 2496 | p->v.Slice.upper = upper; |
| 2497 | p->v.Slice.step = step; |
| 2498 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2499 | } |
| 2500 | |
| 2501 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2502 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2503 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2504 | slice_ty p; |
| 2505 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2506 | if (!p) |
| 2507 | return NULL; |
| 2508 | p->kind = ExtSlice_kind; |
| 2509 | p->v.ExtSlice.dims = dims; |
| 2510 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2514 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2515 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2516 | slice_ty p; |
| 2517 | if (!value) { |
| 2518 | PyErr_SetString(PyExc_ValueError, |
| 2519 | "field value is required for Index"); |
| 2520 | return NULL; |
| 2521 | } |
| 2522 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2523 | if (!p) |
| 2524 | return NULL; |
| 2525 | p->kind = Index_kind; |
| 2526 | p->v.Index.value = value; |
| 2527 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 2531 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 2532 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2533 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2534 | comprehension_ty p; |
| 2535 | if (!target) { |
| 2536 | PyErr_SetString(PyExc_ValueError, |
| 2537 | "field target is required for comprehension"); |
| 2538 | return NULL; |
| 2539 | } |
| 2540 | if (!iter) { |
| 2541 | PyErr_SetString(PyExc_ValueError, |
| 2542 | "field iter is required for comprehension"); |
| 2543 | return NULL; |
| 2544 | } |
| 2545 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2546 | if (!p) |
| 2547 | return NULL; |
| 2548 | p->target = target; |
| 2549 | p->iter = iter; |
| 2550 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 2551 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2552 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2556 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2557 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2558 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2559 | excepthandler_ty p; |
| 2560 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2561 | if (!p) |
| 2562 | return NULL; |
| 2563 | p->kind = ExceptHandler_kind; |
| 2564 | p->v.ExceptHandler.type = type; |
| 2565 | p->v.ExceptHandler.name = name; |
| 2566 | p->v.ExceptHandler.body = body; |
| 2567 | p->lineno = lineno; |
| 2568 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2569 | p->end_lineno = end_lineno; |
| 2570 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2571 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | arguments_ty |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 2575 | arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq * |
| 2576 | kw_defaults, arg_ty kwarg, asdl_seq * defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2577 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2578 | arguments_ty p; |
| 2579 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2580 | if (!p) |
| 2581 | return NULL; |
| 2582 | p->args = args; |
| 2583 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2584 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2585 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 2586 | p->kwarg = kwarg; |
| 2587 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2588 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2589 | } |
| 2590 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2591 | arg_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2592 | arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int |
| 2593 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2594 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2595 | arg_ty p; |
| 2596 | if (!arg) { |
| 2597 | PyErr_SetString(PyExc_ValueError, |
| 2598 | "field arg is required for arg"); |
| 2599 | return NULL; |
| 2600 | } |
| 2601 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2602 | if (!p) |
| 2603 | return NULL; |
| 2604 | p->arg = arg; |
| 2605 | p->annotation = annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2606 | p->type_comment = type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 2607 | p->lineno = lineno; |
| 2608 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2609 | p->end_lineno = end_lineno; |
| 2610 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2611 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2612 | } |
| 2613 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2614 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2615 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2616 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2617 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2618 | if (!value) { |
| 2619 | PyErr_SetString(PyExc_ValueError, |
| 2620 | "field value is required for keyword"); |
| 2621 | return NULL; |
| 2622 | } |
| 2623 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2624 | if (!p) |
| 2625 | return NULL; |
| 2626 | p->arg = arg; |
| 2627 | p->value = value; |
| 2628 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2629 | } |
| 2630 | |
| 2631 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2632 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2633 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2634 | alias_ty p; |
| 2635 | if (!name) { |
| 2636 | PyErr_SetString(PyExc_ValueError, |
| 2637 | "field name is required for alias"); |
| 2638 | return NULL; |
| 2639 | } |
| 2640 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2641 | if (!p) |
| 2642 | return NULL; |
| 2643 | p->name = name; |
| 2644 | p->asname = asname; |
| 2645 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2646 | } |
| 2647 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2648 | withitem_ty |
| 2649 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2650 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2651 | withitem_ty p; |
| 2652 | if (!context_expr) { |
| 2653 | PyErr_SetString(PyExc_ValueError, |
| 2654 | "field context_expr is required for withitem"); |
| 2655 | return NULL; |
| 2656 | } |
| 2657 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2658 | if (!p) |
| 2659 | return NULL; |
| 2660 | p->context_expr = context_expr; |
| 2661 | p->optional_vars = optional_vars; |
| 2662 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2663 | } |
| 2664 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2665 | type_ignore_ty |
| 2666 | TypeIgnore(int lineno, PyArena *arena) |
| 2667 | { |
| 2668 | type_ignore_ty p; |
| 2669 | p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2670 | if (!p) |
| 2671 | return NULL; |
| 2672 | p->kind = TypeIgnore_kind; |
| 2673 | p->v.TypeIgnore.lineno = lineno; |
| 2674 | return p; |
| 2675 | } |
| 2676 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2677 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2678 | PyObject* |
| 2679 | ast2obj_mod(void* _o) |
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 | mod_ty o = (mod_ty)_o; |
| 2682 | PyObject *result = NULL, *value = NULL; |
| 2683 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 2684 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2685 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2686 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2687 | switch (o->kind) { |
| 2688 | case Module_kind: |
| 2689 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2690 | if (!result) goto failed; |
| 2691 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2692 | if (!value) goto failed; |
| 2693 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2694 | goto failed; |
| 2695 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2696 | value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); |
| 2697 | if (!value) goto failed; |
| 2698 | if (_PyObject_SetAttrId(result, &PyId_type_ignores, value) == -1) |
| 2699 | goto failed; |
| 2700 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2701 | break; |
| 2702 | case Interactive_kind: |
| 2703 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2704 | if (!result) goto failed; |
| 2705 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2706 | if (!value) goto failed; |
| 2707 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2708 | goto failed; |
| 2709 | Py_DECREF(value); |
| 2710 | break; |
| 2711 | case Expression_kind: |
| 2712 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2713 | if (!result) goto failed; |
| 2714 | value = ast2obj_expr(o->v.Expression.body); |
| 2715 | if (!value) goto failed; |
| 2716 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2717 | goto failed; |
| 2718 | Py_DECREF(value); |
| 2719 | break; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2720 | case FunctionType_kind: |
| 2721 | result = PyType_GenericNew(FunctionType_type, NULL, NULL); |
| 2722 | if (!result) goto failed; |
| 2723 | value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); |
| 2724 | if (!value) goto failed; |
| 2725 | if (_PyObject_SetAttrId(result, &PyId_argtypes, value) == -1) |
| 2726 | goto failed; |
| 2727 | Py_DECREF(value); |
| 2728 | value = ast2obj_expr(o->v.FunctionType.returns); |
| 2729 | if (!value) goto failed; |
| 2730 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2731 | goto failed; |
| 2732 | Py_DECREF(value); |
| 2733 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2734 | case Suite_kind: |
| 2735 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2736 | if (!result) goto failed; |
| 2737 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2738 | if (!value) goto failed; |
| 2739 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2740 | goto failed; |
| 2741 | Py_DECREF(value); |
| 2742 | break; |
| 2743 | } |
| 2744 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2745 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2746 | Py_XDECREF(value); |
| 2747 | Py_XDECREF(result); |
| 2748 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2749 | } |
| 2750 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2751 | PyObject* |
| 2752 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2753 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2754 | stmt_ty o = (stmt_ty)_o; |
| 2755 | PyObject *result = NULL, *value = NULL; |
| 2756 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 2757 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2758 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2759 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2760 | switch (o->kind) { |
| 2761 | case FunctionDef_kind: |
| 2762 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2763 | if (!result) goto failed; |
| 2764 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2765 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2766 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2767 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2768 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2769 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2770 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2771 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2772 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2773 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2774 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2775 | if (!value) goto failed; |
| 2776 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2777 | goto failed; |
| 2778 | Py_DECREF(value); |
| 2779 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 2780 | if (!value) goto failed; |
| 2781 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2782 | goto failed; |
| 2783 | Py_DECREF(value); |
| 2784 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2785 | if (!value) goto failed; |
| 2786 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2787 | goto failed; |
| 2788 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2789 | value = ast2obj_string(o->v.FunctionDef.type_comment); |
| 2790 | if (!value) goto failed; |
| 2791 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2792 | goto failed; |
| 2793 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2794 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2795 | case AsyncFunctionDef_kind: |
| 2796 | result = PyType_GenericNew(AsyncFunctionDef_type, NULL, NULL); |
| 2797 | if (!result) goto failed; |
| 2798 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 2799 | if (!value) goto failed; |
| 2800 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2801 | goto failed; |
| 2802 | Py_DECREF(value); |
| 2803 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 2804 | if (!value) goto failed; |
| 2805 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2806 | goto failed; |
| 2807 | Py_DECREF(value); |
| 2808 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 2809 | if (!value) goto failed; |
| 2810 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2811 | goto failed; |
| 2812 | Py_DECREF(value); |
| 2813 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 2814 | ast2obj_expr); |
| 2815 | if (!value) goto failed; |
| 2816 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2817 | goto failed; |
| 2818 | Py_DECREF(value); |
| 2819 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 2820 | if (!value) goto failed; |
| 2821 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2822 | goto failed; |
| 2823 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2824 | value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); |
| 2825 | if (!value) goto failed; |
| 2826 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2827 | goto failed; |
| 2828 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2829 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2830 | case ClassDef_kind: |
| 2831 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2832 | if (!result) goto failed; |
| 2833 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2834 | if (!value) goto failed; |
| 2835 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2836 | goto failed; |
| 2837 | Py_DECREF(value); |
| 2838 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2839 | if (!value) goto failed; |
| 2840 | if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) |
| 2841 | goto failed; |
| 2842 | Py_DECREF(value); |
| 2843 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2844 | if (!value) goto failed; |
| 2845 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 2846 | goto failed; |
| 2847 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2848 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2849 | if (!value) goto failed; |
| 2850 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2851 | goto failed; |
| 2852 | Py_DECREF(value); |
| 2853 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 2854 | if (!value) goto failed; |
| 2855 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2856 | goto failed; |
| 2857 | Py_DECREF(value); |
| 2858 | break; |
| 2859 | case Return_kind: |
| 2860 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2861 | if (!result) goto failed; |
| 2862 | value = ast2obj_expr(o->v.Return.value); |
| 2863 | if (!value) goto failed; |
| 2864 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2865 | goto failed; |
| 2866 | Py_DECREF(value); |
| 2867 | break; |
| 2868 | case Delete_kind: |
| 2869 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2870 | if (!result) goto failed; |
| 2871 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2872 | if (!value) goto failed; |
| 2873 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2874 | goto failed; |
| 2875 | Py_DECREF(value); |
| 2876 | break; |
| 2877 | case Assign_kind: |
| 2878 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2879 | if (!result) goto failed; |
| 2880 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2881 | if (!value) goto failed; |
| 2882 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2883 | goto failed; |
| 2884 | Py_DECREF(value); |
| 2885 | value = ast2obj_expr(o->v.Assign.value); |
| 2886 | if (!value) goto failed; |
| 2887 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2888 | goto failed; |
| 2889 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2890 | value = ast2obj_string(o->v.Assign.type_comment); |
| 2891 | if (!value) goto failed; |
| 2892 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2893 | goto failed; |
| 2894 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2895 | break; |
| 2896 | case AugAssign_kind: |
| 2897 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2898 | if (!result) goto failed; |
| 2899 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2900 | if (!value) goto failed; |
| 2901 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2902 | goto failed; |
| 2903 | Py_DECREF(value); |
| 2904 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2905 | if (!value) goto failed; |
| 2906 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2907 | goto failed; |
| 2908 | Py_DECREF(value); |
| 2909 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2910 | if (!value) goto failed; |
| 2911 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2912 | goto failed; |
| 2913 | Py_DECREF(value); |
| 2914 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2915 | case AnnAssign_kind: |
| 2916 | result = PyType_GenericNew(AnnAssign_type, NULL, NULL); |
| 2917 | if (!result) goto failed; |
| 2918 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 2919 | if (!value) goto failed; |
| 2920 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2921 | goto failed; |
| 2922 | Py_DECREF(value); |
| 2923 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 2924 | if (!value) goto failed; |
| 2925 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 2926 | goto failed; |
| 2927 | Py_DECREF(value); |
| 2928 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 2929 | if (!value) goto failed; |
| 2930 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2931 | goto failed; |
| 2932 | Py_DECREF(value); |
| 2933 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 2934 | if (!value) goto failed; |
| 2935 | if (_PyObject_SetAttrId(result, &PyId_simple, value) == -1) |
| 2936 | goto failed; |
| 2937 | Py_DECREF(value); |
| 2938 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2939 | case For_kind: |
| 2940 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2941 | if (!result) goto failed; |
| 2942 | value = ast2obj_expr(o->v.For.target); |
| 2943 | if (!value) goto failed; |
| 2944 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2945 | goto failed; |
| 2946 | Py_DECREF(value); |
| 2947 | value = ast2obj_expr(o->v.For.iter); |
| 2948 | if (!value) goto failed; |
| 2949 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2950 | goto failed; |
| 2951 | Py_DECREF(value); |
| 2952 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2953 | if (!value) goto failed; |
| 2954 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2955 | goto failed; |
| 2956 | Py_DECREF(value); |
| 2957 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2958 | if (!value) goto failed; |
| 2959 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2960 | goto failed; |
| 2961 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2962 | value = ast2obj_string(o->v.For.type_comment); |
| 2963 | if (!value) goto failed; |
| 2964 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2965 | goto failed; |
| 2966 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2967 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2968 | case AsyncFor_kind: |
| 2969 | result = PyType_GenericNew(AsyncFor_type, NULL, NULL); |
| 2970 | if (!result) goto failed; |
| 2971 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 2972 | if (!value) goto failed; |
| 2973 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2974 | goto failed; |
| 2975 | Py_DECREF(value); |
| 2976 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 2977 | if (!value) goto failed; |
| 2978 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2979 | goto failed; |
| 2980 | Py_DECREF(value); |
| 2981 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 2982 | if (!value) goto failed; |
| 2983 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2984 | goto failed; |
| 2985 | Py_DECREF(value); |
| 2986 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 2987 | if (!value) goto failed; |
| 2988 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2989 | goto failed; |
| 2990 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2991 | value = ast2obj_string(o->v.AsyncFor.type_comment); |
| 2992 | if (!value) goto failed; |
| 2993 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2994 | goto failed; |
| 2995 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2996 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2997 | case While_kind: |
| 2998 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2999 | if (!result) goto failed; |
| 3000 | value = ast2obj_expr(o->v.While.test); |
| 3001 | if (!value) goto failed; |
| 3002 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3003 | goto failed; |
| 3004 | Py_DECREF(value); |
| 3005 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 3006 | if (!value) goto failed; |
| 3007 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3008 | goto failed; |
| 3009 | Py_DECREF(value); |
| 3010 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 3011 | if (!value) goto failed; |
| 3012 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3013 | goto failed; |
| 3014 | Py_DECREF(value); |
| 3015 | break; |
| 3016 | case If_kind: |
| 3017 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 3018 | if (!result) goto failed; |
| 3019 | value = ast2obj_expr(o->v.If.test); |
| 3020 | if (!value) goto failed; |
| 3021 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3022 | goto failed; |
| 3023 | Py_DECREF(value); |
| 3024 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 3025 | if (!value) goto failed; |
| 3026 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3027 | goto failed; |
| 3028 | Py_DECREF(value); |
| 3029 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 3030 | if (!value) goto failed; |
| 3031 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3032 | goto failed; |
| 3033 | Py_DECREF(value); |
| 3034 | break; |
| 3035 | case With_kind: |
| 3036 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 3037 | if (!result) goto failed; |
| 3038 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 3039 | if (!value) goto failed; |
| 3040 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 3041 | goto failed; |
| 3042 | Py_DECREF(value); |
| 3043 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 3044 | if (!value) goto failed; |
| 3045 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3046 | goto failed; |
| 3047 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3048 | value = ast2obj_string(o->v.With.type_comment); |
| 3049 | if (!value) goto failed; |
| 3050 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 3051 | goto failed; |
| 3052 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3053 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3054 | case AsyncWith_kind: |
| 3055 | result = PyType_GenericNew(AsyncWith_type, NULL, NULL); |
| 3056 | if (!result) goto failed; |
| 3057 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 3058 | if (!value) goto failed; |
| 3059 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 3060 | goto failed; |
| 3061 | Py_DECREF(value); |
| 3062 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 3063 | if (!value) goto failed; |
| 3064 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3065 | goto failed; |
| 3066 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3067 | value = ast2obj_string(o->v.AsyncWith.type_comment); |
| 3068 | if (!value) goto failed; |
| 3069 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 3070 | goto failed; |
| 3071 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3072 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3073 | case Raise_kind: |
| 3074 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 3075 | if (!result) goto failed; |
| 3076 | value = ast2obj_expr(o->v.Raise.exc); |
| 3077 | if (!value) goto failed; |
| 3078 | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
| 3079 | goto failed; |
| 3080 | Py_DECREF(value); |
| 3081 | value = ast2obj_expr(o->v.Raise.cause); |
| 3082 | if (!value) goto failed; |
| 3083 | if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) |
| 3084 | goto failed; |
| 3085 | Py_DECREF(value); |
| 3086 | break; |
| 3087 | case Try_kind: |
| 3088 | result = PyType_GenericNew(Try_type, NULL, NULL); |
| 3089 | if (!result) goto failed; |
| 3090 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 3091 | if (!value) goto failed; |
| 3092 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3093 | goto failed; |
| 3094 | Py_DECREF(value); |
| 3095 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 3096 | if (!value) goto failed; |
| 3097 | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
| 3098 | goto failed; |
| 3099 | Py_DECREF(value); |
| 3100 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 3101 | if (!value) goto failed; |
| 3102 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3103 | goto failed; |
| 3104 | Py_DECREF(value); |
| 3105 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 3106 | if (!value) goto failed; |
| 3107 | if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) |
| 3108 | goto failed; |
| 3109 | Py_DECREF(value); |
| 3110 | break; |
| 3111 | case Assert_kind: |
| 3112 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 3113 | if (!result) goto failed; |
| 3114 | value = ast2obj_expr(o->v.Assert.test); |
| 3115 | if (!value) goto failed; |
| 3116 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3117 | goto failed; |
| 3118 | Py_DECREF(value); |
| 3119 | value = ast2obj_expr(o->v.Assert.msg); |
| 3120 | if (!value) goto failed; |
| 3121 | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
| 3122 | goto failed; |
| 3123 | Py_DECREF(value); |
| 3124 | break; |
| 3125 | case Import_kind: |
| 3126 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 3127 | if (!result) goto failed; |
| 3128 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 3129 | if (!value) goto failed; |
| 3130 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3131 | goto failed; |
| 3132 | Py_DECREF(value); |
| 3133 | break; |
| 3134 | case ImportFrom_kind: |
| 3135 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 3136 | if (!result) goto failed; |
| 3137 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 3138 | if (!value) goto failed; |
| 3139 | if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) |
| 3140 | goto failed; |
| 3141 | Py_DECREF(value); |
| 3142 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 3143 | if (!value) goto failed; |
| 3144 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3145 | goto failed; |
| 3146 | Py_DECREF(value); |
| 3147 | value = ast2obj_int(o->v.ImportFrom.level); |
| 3148 | if (!value) goto failed; |
| 3149 | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
| 3150 | goto failed; |
| 3151 | Py_DECREF(value); |
| 3152 | break; |
| 3153 | case Global_kind: |
| 3154 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 3155 | if (!result) goto failed; |
| 3156 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 3157 | if (!value) goto failed; |
| 3158 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3159 | goto failed; |
| 3160 | Py_DECREF(value); |
| 3161 | break; |
| 3162 | case Nonlocal_kind: |
| 3163 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 3164 | if (!result) goto failed; |
| 3165 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 3166 | if (!value) goto failed; |
| 3167 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3168 | goto failed; |
| 3169 | Py_DECREF(value); |
| 3170 | break; |
| 3171 | case Expr_kind: |
| 3172 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 3173 | if (!result) goto failed; |
| 3174 | value = ast2obj_expr(o->v.Expr.value); |
| 3175 | if (!value) goto failed; |
| 3176 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3177 | goto failed; |
| 3178 | Py_DECREF(value); |
| 3179 | break; |
| 3180 | case Pass_kind: |
| 3181 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 3182 | if (!result) goto failed; |
| 3183 | break; |
| 3184 | case Break_kind: |
| 3185 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 3186 | if (!result) goto failed; |
| 3187 | break; |
| 3188 | case Continue_kind: |
| 3189 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 3190 | if (!result) goto failed; |
| 3191 | break; |
| 3192 | } |
| 3193 | value = ast2obj_int(o->lineno); |
| 3194 | if (!value) goto failed; |
| 3195 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3196 | goto failed; |
| 3197 | Py_DECREF(value); |
| 3198 | value = ast2obj_int(o->col_offset); |
| 3199 | if (!value) goto failed; |
| 3200 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3201 | goto failed; |
| 3202 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3203 | value = ast2obj_int(o->end_lineno); |
| 3204 | if (!value) goto failed; |
| 3205 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3206 | goto failed; |
| 3207 | Py_DECREF(value); |
| 3208 | value = ast2obj_int(o->end_col_offset); |
| 3209 | if (!value) goto failed; |
| 3210 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3211 | goto failed; |
| 3212 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3213 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3214 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3215 | Py_XDECREF(value); |
| 3216 | Py_XDECREF(result); |
| 3217 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3220 | PyObject* |
| 3221 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3222 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3223 | expr_ty o = (expr_ty)_o; |
| 3224 | PyObject *result = NULL, *value = NULL; |
| 3225 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3226 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3227 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3228 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3229 | switch (o->kind) { |
| 3230 | case BoolOp_kind: |
| 3231 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 3232 | if (!result) goto failed; |
| 3233 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 3234 | if (!value) goto failed; |
| 3235 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3236 | goto failed; |
| 3237 | Py_DECREF(value); |
| 3238 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 3239 | if (!value) goto failed; |
| 3240 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3241 | goto failed; |
| 3242 | Py_DECREF(value); |
| 3243 | break; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3244 | case NamedExpr_kind: |
| 3245 | result = PyType_GenericNew(NamedExpr_type, NULL, NULL); |
| 3246 | if (!result) goto failed; |
| 3247 | value = ast2obj_expr(o->v.NamedExpr.target); |
| 3248 | if (!value) goto failed; |
| 3249 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 3250 | goto failed; |
| 3251 | Py_DECREF(value); |
| 3252 | value = ast2obj_expr(o->v.NamedExpr.value); |
| 3253 | if (!value) goto failed; |
| 3254 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3255 | goto failed; |
| 3256 | Py_DECREF(value); |
| 3257 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3258 | case BinOp_kind: |
| 3259 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 3260 | if (!result) goto failed; |
| 3261 | value = ast2obj_expr(o->v.BinOp.left); |
| 3262 | if (!value) goto failed; |
| 3263 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3264 | goto failed; |
| 3265 | Py_DECREF(value); |
| 3266 | value = ast2obj_operator(o->v.BinOp.op); |
| 3267 | if (!value) goto failed; |
| 3268 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3269 | goto failed; |
| 3270 | Py_DECREF(value); |
| 3271 | value = ast2obj_expr(o->v.BinOp.right); |
| 3272 | if (!value) goto failed; |
| 3273 | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
| 3274 | goto failed; |
| 3275 | Py_DECREF(value); |
| 3276 | break; |
| 3277 | case UnaryOp_kind: |
| 3278 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 3279 | if (!result) goto failed; |
| 3280 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 3281 | if (!value) goto failed; |
| 3282 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3283 | goto failed; |
| 3284 | Py_DECREF(value); |
| 3285 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 3286 | if (!value) goto failed; |
| 3287 | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
| 3288 | goto failed; |
| 3289 | Py_DECREF(value); |
| 3290 | break; |
| 3291 | case Lambda_kind: |
| 3292 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 3293 | if (!result) goto failed; |
| 3294 | value = ast2obj_arguments(o->v.Lambda.args); |
| 3295 | if (!value) goto failed; |
| 3296 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3297 | goto failed; |
| 3298 | Py_DECREF(value); |
| 3299 | value = ast2obj_expr(o->v.Lambda.body); |
| 3300 | if (!value) goto failed; |
| 3301 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3302 | goto failed; |
| 3303 | Py_DECREF(value); |
| 3304 | break; |
| 3305 | case IfExp_kind: |
| 3306 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 3307 | if (!result) goto failed; |
| 3308 | value = ast2obj_expr(o->v.IfExp.test); |
| 3309 | if (!value) goto failed; |
| 3310 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3311 | goto failed; |
| 3312 | Py_DECREF(value); |
| 3313 | value = ast2obj_expr(o->v.IfExp.body); |
| 3314 | if (!value) goto failed; |
| 3315 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3316 | goto failed; |
| 3317 | Py_DECREF(value); |
| 3318 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 3319 | if (!value) goto failed; |
| 3320 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3321 | goto failed; |
| 3322 | Py_DECREF(value); |
| 3323 | break; |
| 3324 | case Dict_kind: |
| 3325 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 3326 | if (!result) goto failed; |
| 3327 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 3328 | if (!value) goto failed; |
| 3329 | if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) |
| 3330 | goto failed; |
| 3331 | Py_DECREF(value); |
| 3332 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 3333 | if (!value) goto failed; |
| 3334 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3335 | goto failed; |
| 3336 | Py_DECREF(value); |
| 3337 | break; |
| 3338 | case Set_kind: |
| 3339 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 3340 | if (!result) goto failed; |
| 3341 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 3342 | if (!value) goto failed; |
| 3343 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3344 | goto failed; |
| 3345 | Py_DECREF(value); |
| 3346 | break; |
| 3347 | case ListComp_kind: |
| 3348 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 3349 | if (!result) goto failed; |
| 3350 | value = ast2obj_expr(o->v.ListComp.elt); |
| 3351 | if (!value) goto failed; |
| 3352 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3353 | goto failed; |
| 3354 | Py_DECREF(value); |
| 3355 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 3356 | if (!value) goto failed; |
| 3357 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3358 | goto failed; |
| 3359 | Py_DECREF(value); |
| 3360 | break; |
| 3361 | case SetComp_kind: |
| 3362 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 3363 | if (!result) goto failed; |
| 3364 | value = ast2obj_expr(o->v.SetComp.elt); |
| 3365 | if (!value) goto failed; |
| 3366 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3367 | goto failed; |
| 3368 | Py_DECREF(value); |
| 3369 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 3370 | if (!value) goto failed; |
| 3371 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3372 | goto failed; |
| 3373 | Py_DECREF(value); |
| 3374 | break; |
| 3375 | case DictComp_kind: |
| 3376 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 3377 | if (!result) goto failed; |
| 3378 | value = ast2obj_expr(o->v.DictComp.key); |
| 3379 | if (!value) goto failed; |
| 3380 | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
| 3381 | goto failed; |
| 3382 | Py_DECREF(value); |
| 3383 | value = ast2obj_expr(o->v.DictComp.value); |
| 3384 | if (!value) goto failed; |
| 3385 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3386 | goto failed; |
| 3387 | Py_DECREF(value); |
| 3388 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 3389 | if (!value) goto failed; |
| 3390 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3391 | goto failed; |
| 3392 | Py_DECREF(value); |
| 3393 | break; |
| 3394 | case GeneratorExp_kind: |
| 3395 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 3396 | if (!result) goto failed; |
| 3397 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 3398 | if (!value) goto failed; |
| 3399 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3400 | goto failed; |
| 3401 | Py_DECREF(value); |
| 3402 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 3403 | ast2obj_comprehension); |
| 3404 | if (!value) goto failed; |
| 3405 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3406 | goto failed; |
| 3407 | Py_DECREF(value); |
| 3408 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3409 | case Await_kind: |
| 3410 | result = PyType_GenericNew(Await_type, NULL, NULL); |
| 3411 | if (!result) goto failed; |
| 3412 | value = ast2obj_expr(o->v.Await.value); |
| 3413 | if (!value) goto failed; |
| 3414 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3415 | goto failed; |
| 3416 | Py_DECREF(value); |
| 3417 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3418 | case Yield_kind: |
| 3419 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 3420 | if (!result) goto failed; |
| 3421 | value = ast2obj_expr(o->v.Yield.value); |
| 3422 | if (!value) goto failed; |
| 3423 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3424 | goto failed; |
| 3425 | Py_DECREF(value); |
| 3426 | break; |
| 3427 | case YieldFrom_kind: |
| 3428 | result = PyType_GenericNew(YieldFrom_type, NULL, NULL); |
| 3429 | if (!result) goto failed; |
| 3430 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 3431 | if (!value) goto failed; |
| 3432 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3433 | goto failed; |
| 3434 | Py_DECREF(value); |
| 3435 | break; |
| 3436 | case Compare_kind: |
| 3437 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 3438 | if (!result) goto failed; |
| 3439 | value = ast2obj_expr(o->v.Compare.left); |
| 3440 | if (!value) goto failed; |
| 3441 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3442 | goto failed; |
| 3443 | Py_DECREF(value); |
| 3444 | { |
| 3445 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 3446 | value = PyList_New(n); |
| 3447 | if (!value) goto failed; |
| 3448 | for(i = 0; i < n; i++) |
| 3449 | 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] | 3450 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3451 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3452 | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
| 3453 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3454 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3455 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3456 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3457 | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
| 3458 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3459 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3460 | break; |
| 3461 | case Call_kind: |
| 3462 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 3463 | if (!result) goto failed; |
| 3464 | value = ast2obj_expr(o->v.Call.func); |
| 3465 | if (!value) goto failed; |
| 3466 | if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) |
| 3467 | goto failed; |
| 3468 | Py_DECREF(value); |
| 3469 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 3470 | if (!value) goto failed; |
| 3471 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3472 | goto failed; |
| 3473 | Py_DECREF(value); |
| 3474 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 3475 | if (!value) goto failed; |
| 3476 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 3477 | goto failed; |
| 3478 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3479 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3480 | case FormattedValue_kind: |
| 3481 | result = PyType_GenericNew(FormattedValue_type, NULL, NULL); |
| 3482 | if (!result) goto failed; |
| 3483 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 3484 | if (!value) goto failed; |
| 3485 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3486 | goto failed; |
| 3487 | Py_DECREF(value); |
| 3488 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 3489 | if (!value) goto failed; |
| 3490 | if (_PyObject_SetAttrId(result, &PyId_conversion, value) == -1) |
| 3491 | goto failed; |
| 3492 | Py_DECREF(value); |
| 3493 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 3494 | if (!value) goto failed; |
| 3495 | if (_PyObject_SetAttrId(result, &PyId_format_spec, value) == -1) |
| 3496 | goto failed; |
| 3497 | Py_DECREF(value); |
| 3498 | break; |
| 3499 | case JoinedStr_kind: |
| 3500 | result = PyType_GenericNew(JoinedStr_type, NULL, NULL); |
| 3501 | if (!result) goto failed; |
| 3502 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 3503 | if (!value) goto failed; |
| 3504 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3505 | goto failed; |
| 3506 | Py_DECREF(value); |
| 3507 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3508 | case Constant_kind: |
| 3509 | result = PyType_GenericNew(Constant_type, NULL, NULL); |
| 3510 | if (!result) goto failed; |
| 3511 | value = ast2obj_constant(o->v.Constant.value); |
| 3512 | if (!value) goto failed; |
| 3513 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3514 | goto failed; |
| 3515 | Py_DECREF(value); |
| 3516 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3517 | case Attribute_kind: |
| 3518 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 3519 | if (!result) goto failed; |
| 3520 | value = ast2obj_expr(o->v.Attribute.value); |
| 3521 | if (!value) goto failed; |
| 3522 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3523 | goto failed; |
| 3524 | Py_DECREF(value); |
| 3525 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 3526 | if (!value) goto failed; |
| 3527 | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
| 3528 | goto failed; |
| 3529 | Py_DECREF(value); |
| 3530 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 3531 | if (!value) goto failed; |
| 3532 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3533 | goto failed; |
| 3534 | Py_DECREF(value); |
| 3535 | break; |
| 3536 | case Subscript_kind: |
| 3537 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 3538 | if (!result) goto failed; |
| 3539 | value = ast2obj_expr(o->v.Subscript.value); |
| 3540 | if (!value) goto failed; |
| 3541 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3542 | goto failed; |
| 3543 | Py_DECREF(value); |
| 3544 | value = ast2obj_slice(o->v.Subscript.slice); |
| 3545 | if (!value) goto failed; |
| 3546 | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
| 3547 | goto failed; |
| 3548 | Py_DECREF(value); |
| 3549 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 3550 | if (!value) goto failed; |
| 3551 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3552 | goto failed; |
| 3553 | Py_DECREF(value); |
| 3554 | break; |
| 3555 | case Starred_kind: |
| 3556 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 3557 | if (!result) goto failed; |
| 3558 | value = ast2obj_expr(o->v.Starred.value); |
| 3559 | if (!value) goto failed; |
| 3560 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3561 | goto failed; |
| 3562 | Py_DECREF(value); |
| 3563 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 3564 | if (!value) goto failed; |
| 3565 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3566 | goto failed; |
| 3567 | Py_DECREF(value); |
| 3568 | break; |
| 3569 | case Name_kind: |
| 3570 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 3571 | if (!result) goto failed; |
| 3572 | value = ast2obj_identifier(o->v.Name.id); |
| 3573 | if (!value) goto failed; |
| 3574 | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
| 3575 | goto failed; |
| 3576 | Py_DECREF(value); |
| 3577 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 3578 | if (!value) goto failed; |
| 3579 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3580 | goto failed; |
| 3581 | Py_DECREF(value); |
| 3582 | break; |
| 3583 | case List_kind: |
| 3584 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 3585 | if (!result) goto failed; |
| 3586 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 3587 | if (!value) goto failed; |
| 3588 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3589 | goto failed; |
| 3590 | Py_DECREF(value); |
| 3591 | value = ast2obj_expr_context(o->v.List.ctx); |
| 3592 | if (!value) goto failed; |
| 3593 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3594 | goto failed; |
| 3595 | Py_DECREF(value); |
| 3596 | break; |
| 3597 | case Tuple_kind: |
| 3598 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 3599 | if (!result) goto failed; |
| 3600 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 3601 | if (!value) goto failed; |
| 3602 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3603 | goto failed; |
| 3604 | Py_DECREF(value); |
| 3605 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 3606 | if (!value) goto failed; |
| 3607 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3608 | goto failed; |
| 3609 | Py_DECREF(value); |
| 3610 | break; |
| 3611 | } |
| 3612 | value = ast2obj_int(o->lineno); |
| 3613 | if (!value) goto failed; |
| 3614 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3615 | goto failed; |
| 3616 | Py_DECREF(value); |
| 3617 | value = ast2obj_int(o->col_offset); |
| 3618 | if (!value) goto failed; |
| 3619 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3620 | goto failed; |
| 3621 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3622 | value = ast2obj_int(o->end_lineno); |
| 3623 | if (!value) goto failed; |
| 3624 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3625 | goto failed; |
| 3626 | Py_DECREF(value); |
| 3627 | value = ast2obj_int(o->end_col_offset); |
| 3628 | if (!value) goto failed; |
| 3629 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3630 | goto failed; |
| 3631 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3632 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3633 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3634 | Py_XDECREF(value); |
| 3635 | Py_XDECREF(result); |
| 3636 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3637 | } |
| 3638 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3639 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3640 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3641 | switch(o) { |
| 3642 | case Load: |
| 3643 | Py_INCREF(Load_singleton); |
| 3644 | return Load_singleton; |
| 3645 | case Store: |
| 3646 | Py_INCREF(Store_singleton); |
| 3647 | return Store_singleton; |
| 3648 | case Del: |
| 3649 | Py_INCREF(Del_singleton); |
| 3650 | return Del_singleton; |
| 3651 | case AugLoad: |
| 3652 | Py_INCREF(AugLoad_singleton); |
| 3653 | return AugLoad_singleton; |
| 3654 | case AugStore: |
| 3655 | Py_INCREF(AugStore_singleton); |
| 3656 | return AugStore_singleton; |
| 3657 | case Param: |
| 3658 | Py_INCREF(Param_singleton); |
| 3659 | return Param_singleton; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3660 | case NamedStore: |
| 3661 | Py_INCREF(NamedStore_singleton); |
| 3662 | return NamedStore_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3663 | default: |
| 3664 | /* should never happen, but just in case ... */ |
| 3665 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 3666 | return NULL; |
| 3667 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3668 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3669 | PyObject* |
| 3670 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3671 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3672 | slice_ty o = (slice_ty)_o; |
| 3673 | PyObject *result = NULL, *value = NULL; |
| 3674 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3675 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3676 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3677 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3678 | switch (o->kind) { |
| 3679 | case Slice_kind: |
| 3680 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 3681 | if (!result) goto failed; |
| 3682 | value = ast2obj_expr(o->v.Slice.lower); |
| 3683 | if (!value) goto failed; |
| 3684 | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
| 3685 | goto failed; |
| 3686 | Py_DECREF(value); |
| 3687 | value = ast2obj_expr(o->v.Slice.upper); |
| 3688 | if (!value) goto failed; |
| 3689 | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
| 3690 | goto failed; |
| 3691 | Py_DECREF(value); |
| 3692 | value = ast2obj_expr(o->v.Slice.step); |
| 3693 | if (!value) goto failed; |
| 3694 | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
| 3695 | goto failed; |
| 3696 | Py_DECREF(value); |
| 3697 | break; |
| 3698 | case ExtSlice_kind: |
| 3699 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3700 | if (!result) goto failed; |
| 3701 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3702 | if (!value) goto failed; |
| 3703 | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
| 3704 | goto failed; |
| 3705 | Py_DECREF(value); |
| 3706 | break; |
| 3707 | case Index_kind: |
| 3708 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3709 | if (!result) goto failed; |
| 3710 | value = ast2obj_expr(o->v.Index.value); |
| 3711 | if (!value) goto failed; |
| 3712 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3713 | goto failed; |
| 3714 | Py_DECREF(value); |
| 3715 | break; |
| 3716 | } |
| 3717 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3718 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3719 | Py_XDECREF(value); |
| 3720 | Py_XDECREF(result); |
| 3721 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3722 | } |
| 3723 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3724 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3725 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3726 | switch(o) { |
| 3727 | case And: |
| 3728 | Py_INCREF(And_singleton); |
| 3729 | return And_singleton; |
| 3730 | case Or: |
| 3731 | Py_INCREF(Or_singleton); |
| 3732 | return Or_singleton; |
| 3733 | default: |
| 3734 | /* should never happen, but just in case ... */ |
| 3735 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3736 | return NULL; |
| 3737 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3738 | } |
| 3739 | PyObject* ast2obj_operator(operator_ty o) |
| 3740 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3741 | switch(o) { |
| 3742 | case Add: |
| 3743 | Py_INCREF(Add_singleton); |
| 3744 | return Add_singleton; |
| 3745 | case Sub: |
| 3746 | Py_INCREF(Sub_singleton); |
| 3747 | return Sub_singleton; |
| 3748 | case Mult: |
| 3749 | Py_INCREF(Mult_singleton); |
| 3750 | return Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 3751 | case MatMult: |
| 3752 | Py_INCREF(MatMult_singleton); |
| 3753 | return MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3754 | case Div: |
| 3755 | Py_INCREF(Div_singleton); |
| 3756 | return Div_singleton; |
| 3757 | case Mod: |
| 3758 | Py_INCREF(Mod_singleton); |
| 3759 | return Mod_singleton; |
| 3760 | case Pow: |
| 3761 | Py_INCREF(Pow_singleton); |
| 3762 | return Pow_singleton; |
| 3763 | case LShift: |
| 3764 | Py_INCREF(LShift_singleton); |
| 3765 | return LShift_singleton; |
| 3766 | case RShift: |
| 3767 | Py_INCREF(RShift_singleton); |
| 3768 | return RShift_singleton; |
| 3769 | case BitOr: |
| 3770 | Py_INCREF(BitOr_singleton); |
| 3771 | return BitOr_singleton; |
| 3772 | case BitXor: |
| 3773 | Py_INCREF(BitXor_singleton); |
| 3774 | return BitXor_singleton; |
| 3775 | case BitAnd: |
| 3776 | Py_INCREF(BitAnd_singleton); |
| 3777 | return BitAnd_singleton; |
| 3778 | case FloorDiv: |
| 3779 | Py_INCREF(FloorDiv_singleton); |
| 3780 | return FloorDiv_singleton; |
| 3781 | default: |
| 3782 | /* should never happen, but just in case ... */ |
| 3783 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3784 | return NULL; |
| 3785 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3786 | } |
| 3787 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3788 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3789 | switch(o) { |
| 3790 | case Invert: |
| 3791 | Py_INCREF(Invert_singleton); |
| 3792 | return Invert_singleton; |
| 3793 | case Not: |
| 3794 | Py_INCREF(Not_singleton); |
| 3795 | return Not_singleton; |
| 3796 | case UAdd: |
| 3797 | Py_INCREF(UAdd_singleton); |
| 3798 | return UAdd_singleton; |
| 3799 | case USub: |
| 3800 | Py_INCREF(USub_singleton); |
| 3801 | return USub_singleton; |
| 3802 | default: |
| 3803 | /* should never happen, but just in case ... */ |
| 3804 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3805 | return NULL; |
| 3806 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3807 | } |
| 3808 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3809 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3810 | switch(o) { |
| 3811 | case Eq: |
| 3812 | Py_INCREF(Eq_singleton); |
| 3813 | return Eq_singleton; |
| 3814 | case NotEq: |
| 3815 | Py_INCREF(NotEq_singleton); |
| 3816 | return NotEq_singleton; |
| 3817 | case Lt: |
| 3818 | Py_INCREF(Lt_singleton); |
| 3819 | return Lt_singleton; |
| 3820 | case LtE: |
| 3821 | Py_INCREF(LtE_singleton); |
| 3822 | return LtE_singleton; |
| 3823 | case Gt: |
| 3824 | Py_INCREF(Gt_singleton); |
| 3825 | return Gt_singleton; |
| 3826 | case GtE: |
| 3827 | Py_INCREF(GtE_singleton); |
| 3828 | return GtE_singleton; |
| 3829 | case Is: |
| 3830 | Py_INCREF(Is_singleton); |
| 3831 | return Is_singleton; |
| 3832 | case IsNot: |
| 3833 | Py_INCREF(IsNot_singleton); |
| 3834 | return IsNot_singleton; |
| 3835 | case In: |
| 3836 | Py_INCREF(In_singleton); |
| 3837 | return In_singleton; |
| 3838 | case NotIn: |
| 3839 | Py_INCREF(NotIn_singleton); |
| 3840 | return NotIn_singleton; |
| 3841 | default: |
| 3842 | /* should never happen, but just in case ... */ |
| 3843 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3844 | return NULL; |
| 3845 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3846 | } |
| 3847 | PyObject* |
| 3848 | ast2obj_comprehension(void* _o) |
| 3849 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3850 | comprehension_ty o = (comprehension_ty)_o; |
| 3851 | PyObject *result = NULL, *value = NULL; |
| 3852 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3853 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3854 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3855 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3856 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3857 | if (!result) return NULL; |
| 3858 | value = ast2obj_expr(o->target); |
| 3859 | if (!value) goto failed; |
| 3860 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 3861 | goto failed; |
| 3862 | Py_DECREF(value); |
| 3863 | value = ast2obj_expr(o->iter); |
| 3864 | if (!value) goto failed; |
| 3865 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 3866 | goto failed; |
| 3867 | Py_DECREF(value); |
| 3868 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3869 | if (!value) goto failed; |
| 3870 | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
| 3871 | goto failed; |
| 3872 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3873 | value = ast2obj_int(o->is_async); |
| 3874 | if (!value) goto failed; |
| 3875 | if (_PyObject_SetAttrId(result, &PyId_is_async, value) == -1) |
| 3876 | goto failed; |
| 3877 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3878 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3879 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3880 | Py_XDECREF(value); |
| 3881 | Py_XDECREF(result); |
| 3882 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3883 | } |
| 3884 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3885 | PyObject* |
| 3886 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3887 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3888 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3889 | PyObject *result = NULL, *value = NULL; |
| 3890 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3891 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3892 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3893 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3894 | switch (o->kind) { |
| 3895 | case ExceptHandler_kind: |
| 3896 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3897 | if (!result) goto failed; |
| 3898 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3899 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3900 | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
| 3901 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3902 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3903 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3904 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3905 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3906 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3907 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3908 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3909 | if (!value) goto failed; |
| 3910 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3911 | goto failed; |
| 3912 | Py_DECREF(value); |
| 3913 | break; |
| 3914 | } |
| 3915 | value = ast2obj_int(o->lineno); |
| 3916 | if (!value) goto failed; |
| 3917 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3918 | goto failed; |
| 3919 | Py_DECREF(value); |
| 3920 | value = ast2obj_int(o->col_offset); |
| 3921 | if (!value) goto failed; |
| 3922 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3923 | goto failed; |
| 3924 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3925 | value = ast2obj_int(o->end_lineno); |
| 3926 | if (!value) goto failed; |
| 3927 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3928 | goto failed; |
| 3929 | Py_DECREF(value); |
| 3930 | value = ast2obj_int(o->end_col_offset); |
| 3931 | if (!value) goto failed; |
| 3932 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3933 | goto failed; |
| 3934 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3935 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3936 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3937 | Py_XDECREF(value); |
| 3938 | Py_XDECREF(result); |
| 3939 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3940 | } |
| 3941 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3942 | PyObject* |
| 3943 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3944 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3945 | arguments_ty o = (arguments_ty)_o; |
| 3946 | PyObject *result = NULL, *value = NULL; |
| 3947 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3948 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3949 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3950 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3951 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3952 | if (!result) return NULL; |
| 3953 | value = ast2obj_list(o->args, ast2obj_arg); |
| 3954 | if (!value) goto failed; |
| 3955 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3956 | goto failed; |
| 3957 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3958 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3959 | if (!value) goto failed; |
| 3960 | if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) |
| 3961 | goto failed; |
| 3962 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3963 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 3964 | if (!value) goto failed; |
| 3965 | if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) |
| 3966 | goto failed; |
| 3967 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3968 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3969 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3970 | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3971 | goto failed; |
| 3972 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3973 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3974 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3975 | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3976 | goto failed; |
| 3977 | Py_DECREF(value); |
| 3978 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3979 | if (!value) goto failed; |
| 3980 | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
| 3981 | goto failed; |
| 3982 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3983 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3984 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3985 | Py_XDECREF(value); |
| 3986 | Py_XDECREF(result); |
| 3987 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3988 | } |
| 3989 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3990 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3991 | ast2obj_arg(void* _o) |
| 3992 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3993 | arg_ty o = (arg_ty)_o; |
| 3994 | PyObject *result = NULL, *value = NULL; |
| 3995 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3996 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3997 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3998 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3999 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 4000 | if (!result) return NULL; |
| 4001 | value = ast2obj_identifier(o->arg); |
| 4002 | if (!value) goto failed; |
| 4003 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 4004 | goto failed; |
| 4005 | Py_DECREF(value); |
| 4006 | value = ast2obj_expr(o->annotation); |
| 4007 | if (!value) goto failed; |
| 4008 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 4009 | goto failed; |
| 4010 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4011 | value = ast2obj_string(o->type_comment); |
| 4012 | if (!value) goto failed; |
| 4013 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 4014 | goto failed; |
| 4015 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4016 | value = ast2obj_int(o->lineno); |
| 4017 | if (!value) goto failed; |
| 4018 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 4019 | goto failed; |
| 4020 | Py_DECREF(value); |
| 4021 | value = ast2obj_int(o->col_offset); |
| 4022 | if (!value) goto failed; |
| 4023 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 4024 | goto failed; |
| 4025 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4026 | value = ast2obj_int(o->end_lineno); |
| 4027 | if (!value) goto failed; |
| 4028 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 4029 | goto failed; |
| 4030 | Py_DECREF(value); |
| 4031 | value = ast2obj_int(o->end_col_offset); |
| 4032 | if (!value) goto failed; |
| 4033 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 4034 | goto failed; |
| 4035 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4036 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4037 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4038 | Py_XDECREF(value); |
| 4039 | Py_XDECREF(result); |
| 4040 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4041 | } |
| 4042 | |
| 4043 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4044 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4045 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4046 | keyword_ty o = (keyword_ty)_o; |
| 4047 | PyObject *result = NULL, *value = NULL; |
| 4048 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4049 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4050 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4051 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4052 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 4053 | if (!result) return NULL; |
| 4054 | value = ast2obj_identifier(o->arg); |
| 4055 | if (!value) goto failed; |
| 4056 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 4057 | goto failed; |
| 4058 | Py_DECREF(value); |
| 4059 | value = ast2obj_expr(o->value); |
| 4060 | if (!value) goto failed; |
| 4061 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 4062 | goto failed; |
| 4063 | Py_DECREF(value); |
| 4064 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4065 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4066 | Py_XDECREF(value); |
| 4067 | Py_XDECREF(result); |
| 4068 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4069 | } |
| 4070 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4071 | PyObject* |
| 4072 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4073 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4074 | alias_ty o = (alias_ty)_o; |
| 4075 | PyObject *result = NULL, *value = NULL; |
| 4076 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4077 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4078 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4079 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4080 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 4081 | if (!result) return NULL; |
| 4082 | value = ast2obj_identifier(o->name); |
| 4083 | if (!value) goto failed; |
| 4084 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 4085 | goto failed; |
| 4086 | Py_DECREF(value); |
| 4087 | value = ast2obj_identifier(o->asname); |
| 4088 | if (!value) goto failed; |
| 4089 | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
| 4090 | goto failed; |
| 4091 | Py_DECREF(value); |
| 4092 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4093 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4094 | Py_XDECREF(value); |
| 4095 | Py_XDECREF(result); |
| 4096 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4097 | } |
| 4098 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4099 | PyObject* |
| 4100 | ast2obj_withitem(void* _o) |
| 4101 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4102 | withitem_ty o = (withitem_ty)_o; |
| 4103 | PyObject *result = NULL, *value = NULL; |
| 4104 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4105 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4106 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4107 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4108 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 4109 | if (!result) return NULL; |
| 4110 | value = ast2obj_expr(o->context_expr); |
| 4111 | if (!value) goto failed; |
| 4112 | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
| 4113 | goto failed; |
| 4114 | Py_DECREF(value); |
| 4115 | value = ast2obj_expr(o->optional_vars); |
| 4116 | if (!value) goto failed; |
| 4117 | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
| 4118 | goto failed; |
| 4119 | Py_DECREF(value); |
| 4120 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4121 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4122 | Py_XDECREF(value); |
| 4123 | Py_XDECREF(result); |
| 4124 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4125 | } |
| 4126 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4127 | PyObject* |
| 4128 | ast2obj_type_ignore(void* _o) |
| 4129 | { |
| 4130 | type_ignore_ty o = (type_ignore_ty)_o; |
| 4131 | PyObject *result = NULL, *value = NULL; |
| 4132 | if (!o) { |
| 4133 | Py_RETURN_NONE; |
| 4134 | } |
| 4135 | |
| 4136 | switch (o->kind) { |
| 4137 | case TypeIgnore_kind: |
| 4138 | result = PyType_GenericNew(TypeIgnore_type, NULL, NULL); |
| 4139 | if (!result) goto failed; |
| 4140 | value = ast2obj_int(o->v.TypeIgnore.lineno); |
| 4141 | if (!value) goto failed; |
| 4142 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) == -1) |
| 4143 | goto failed; |
| 4144 | Py_DECREF(value); |
| 4145 | break; |
| 4146 | } |
| 4147 | return result; |
| 4148 | failed: |
| 4149 | Py_XDECREF(value); |
| 4150 | Py_XDECREF(result); |
| 4151 | return NULL; |
| 4152 | } |
| 4153 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4154 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4155 | int |
| 4156 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 4157 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4158 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4159 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4160 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4161 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4162 | if (obj == Py_None) { |
| 4163 | *out = NULL; |
| 4164 | return 0; |
| 4165 | } |
| 4166 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 4167 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4168 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4169 | } |
| 4170 | if (isinstance) { |
| 4171 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4172 | asdl_seq* type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4173 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4174 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4175 | return 1; |
| 4176 | } |
| 4177 | if (tmp == NULL) { |
| 4178 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 4179 | return 1; |
| 4180 | } |
| 4181 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4182 | int res; |
| 4183 | Py_ssize_t len; |
| 4184 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4185 | if (!PyList_Check(tmp)) { |
| 4186 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4187 | goto failed; |
| 4188 | } |
| 4189 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4190 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4191 | if (body == NULL) goto failed; |
| 4192 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4193 | stmt_ty val; |
| 4194 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4195 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4196 | if (len != PyList_GET_SIZE(tmp)) { |
| 4197 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 4198 | goto failed; |
| 4199 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4200 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4201 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4202 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4203 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4204 | if (_PyObject_LookupAttrId(obj, &PyId_type_ignores, &tmp) < 0) { |
| 4205 | return 1; |
| 4206 | } |
| 4207 | if (tmp == NULL) { |
| 4208 | PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module"); |
| 4209 | return 1; |
| 4210 | } |
| 4211 | else { |
| 4212 | int res; |
| 4213 | Py_ssize_t len; |
| 4214 | Py_ssize_t i; |
| 4215 | if (!PyList_Check(tmp)) { |
| 4216 | PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4217 | goto failed; |
| 4218 | } |
| 4219 | len = PyList_GET_SIZE(tmp); |
| 4220 | type_ignores = _Py_asdl_seq_new(len, arena); |
| 4221 | if (type_ignores == NULL) goto failed; |
| 4222 | for (i = 0; i < len; i++) { |
| 4223 | type_ignore_ty val; |
| 4224 | res = obj2ast_type_ignore(PyList_GET_ITEM(tmp, i), &val, arena); |
| 4225 | if (res != 0) goto failed; |
| 4226 | if (len != PyList_GET_SIZE(tmp)) { |
| 4227 | PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration"); |
| 4228 | goto failed; |
| 4229 | } |
| 4230 | asdl_seq_SET(type_ignores, i, val); |
| 4231 | } |
| 4232 | Py_CLEAR(tmp); |
| 4233 | } |
| 4234 | *out = Module(body, type_ignores, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4235 | if (*out == NULL) goto failed; |
| 4236 | return 0; |
| 4237 | } |
| 4238 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 4239 | if (isinstance == -1) { |
| 4240 | return 1; |
| 4241 | } |
| 4242 | if (isinstance) { |
| 4243 | asdl_seq* body; |
| 4244 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4245 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4246 | return 1; |
| 4247 | } |
| 4248 | if (tmp == NULL) { |
| 4249 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 4250 | return 1; |
| 4251 | } |
| 4252 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4253 | int res; |
| 4254 | Py_ssize_t len; |
| 4255 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4256 | if (!PyList_Check(tmp)) { |
| 4257 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4258 | goto failed; |
| 4259 | } |
| 4260 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4261 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4262 | if (body == NULL) goto failed; |
| 4263 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4264 | stmt_ty val; |
| 4265 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4266 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4267 | if (len != PyList_GET_SIZE(tmp)) { |
| 4268 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 4269 | goto failed; |
| 4270 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4271 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4272 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4273 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4274 | } |
| 4275 | *out = Interactive(body, arena); |
| 4276 | if (*out == NULL) goto failed; |
| 4277 | return 0; |
| 4278 | } |
| 4279 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 4280 | if (isinstance == -1) { |
| 4281 | return 1; |
| 4282 | } |
| 4283 | if (isinstance) { |
| 4284 | expr_ty body; |
| 4285 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4286 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4287 | return 1; |
| 4288 | } |
| 4289 | if (tmp == NULL) { |
| 4290 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 4291 | return 1; |
| 4292 | } |
| 4293 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4294 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4295 | res = obj2ast_expr(tmp, &body, arena); |
| 4296 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4297 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4298 | } |
| 4299 | *out = Expression(body, arena); |
| 4300 | if (*out == NULL) goto failed; |
| 4301 | return 0; |
| 4302 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4303 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionType_type); |
| 4304 | if (isinstance == -1) { |
| 4305 | return 1; |
| 4306 | } |
| 4307 | if (isinstance) { |
| 4308 | asdl_seq* argtypes; |
| 4309 | expr_ty returns; |
| 4310 | |
| 4311 | if (_PyObject_LookupAttrId(obj, &PyId_argtypes, &tmp) < 0) { |
| 4312 | return 1; |
| 4313 | } |
| 4314 | if (tmp == NULL) { |
| 4315 | PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType"); |
| 4316 | return 1; |
| 4317 | } |
| 4318 | else { |
| 4319 | int res; |
| 4320 | Py_ssize_t len; |
| 4321 | Py_ssize_t i; |
| 4322 | if (!PyList_Check(tmp)) { |
| 4323 | PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4324 | goto failed; |
| 4325 | } |
| 4326 | len = PyList_GET_SIZE(tmp); |
| 4327 | argtypes = _Py_asdl_seq_new(len, arena); |
| 4328 | if (argtypes == NULL) goto failed; |
| 4329 | for (i = 0; i < len; i++) { |
| 4330 | expr_ty val; |
| 4331 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
| 4332 | if (res != 0) goto failed; |
| 4333 | if (len != PyList_GET_SIZE(tmp)) { |
| 4334 | PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration"); |
| 4335 | goto failed; |
| 4336 | } |
| 4337 | asdl_seq_SET(argtypes, i, val); |
| 4338 | } |
| 4339 | Py_CLEAR(tmp); |
| 4340 | } |
| 4341 | if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) { |
| 4342 | return 1; |
| 4343 | } |
| 4344 | if (tmp == NULL) { |
| 4345 | PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType"); |
| 4346 | return 1; |
| 4347 | } |
| 4348 | else { |
| 4349 | int res; |
| 4350 | res = obj2ast_expr(tmp, &returns, arena); |
| 4351 | if (res != 0) goto failed; |
| 4352 | Py_CLEAR(tmp); |
| 4353 | } |
| 4354 | *out = FunctionType(argtypes, returns, arena); |
| 4355 | if (*out == NULL) goto failed; |
| 4356 | return 0; |
| 4357 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4358 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 4359 | if (isinstance == -1) { |
| 4360 | return 1; |
| 4361 | } |
| 4362 | if (isinstance) { |
| 4363 | asdl_seq* body; |
| 4364 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4365 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4366 | return 1; |
| 4367 | } |
| 4368 | if (tmp == NULL) { |
| 4369 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 4370 | return 1; |
| 4371 | } |
| 4372 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4373 | int res; |
| 4374 | Py_ssize_t len; |
| 4375 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4376 | if (!PyList_Check(tmp)) { |
| 4377 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4378 | goto failed; |
| 4379 | } |
| 4380 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4381 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4382 | if (body == NULL) goto failed; |
| 4383 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4384 | stmt_ty val; |
| 4385 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4386 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4387 | if (len != PyList_GET_SIZE(tmp)) { |
| 4388 | PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration"); |
| 4389 | goto failed; |
| 4390 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4391 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4392 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4393 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4394 | } |
| 4395 | *out = Suite(body, arena); |
| 4396 | if (*out == NULL) goto failed; |
| 4397 | return 0; |
| 4398 | } |
| 4399 | |
| 4400 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 4401 | failed: |
| 4402 | Py_XDECREF(tmp); |
| 4403 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4404 | } |
| 4405 | |
| 4406 | int |
| 4407 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 4408 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4409 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4410 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4411 | PyObject *tmp = NULL; |
| 4412 | int lineno; |
| 4413 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4414 | int end_lineno; |
| 4415 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4416 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4417 | if (obj == Py_None) { |
| 4418 | *out = NULL; |
| 4419 | return 0; |
| 4420 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4421 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 4422 | return 1; |
| 4423 | } |
| 4424 | if (tmp == NULL) { |
| 4425 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 4426 | return 1; |
| 4427 | } |
| 4428 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4429 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4430 | res = obj2ast_int(tmp, &lineno, arena); |
| 4431 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4432 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4433 | } |
| 4434 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4435 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4436 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4437 | if (tmp == NULL) { |
| 4438 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 4439 | return 1; |
| 4440 | } |
| 4441 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4442 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4443 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4444 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4445 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4446 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4447 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 4448 | return 1; |
| 4449 | } |
| 4450 | if (tmp == NULL || tmp == Py_None) { |
| 4451 | Py_CLEAR(tmp); |
| 4452 | end_lineno = 0; |
| 4453 | } |
| 4454 | else { |
| 4455 | int res; |
| 4456 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 4457 | if (res != 0) goto failed; |
| 4458 | Py_CLEAR(tmp); |
| 4459 | } |
| 4460 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 4461 | return 1; |
| 4462 | } |
| 4463 | if (tmp == NULL || tmp == Py_None) { |
| 4464 | Py_CLEAR(tmp); |
| 4465 | end_col_offset = 0; |
| 4466 | } |
| 4467 | else { |
| 4468 | int res; |
| 4469 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 4470 | if (res != 0) goto failed; |
| 4471 | Py_CLEAR(tmp); |
| 4472 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4473 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 4474 | if (isinstance == -1) { |
| 4475 | return 1; |
| 4476 | } |
| 4477 | if (isinstance) { |
| 4478 | identifier name; |
| 4479 | arguments_ty args; |
| 4480 | asdl_seq* body; |
| 4481 | asdl_seq* decorator_list; |
| 4482 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4483 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4484 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4485 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4486 | return 1; |
| 4487 | } |
| 4488 | if (tmp == NULL) { |
| 4489 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 4490 | return 1; |
| 4491 | } |
| 4492 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4493 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4494 | res = obj2ast_identifier(tmp, &name, arena); |
| 4495 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4496 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4497 | } |
| 4498 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4499 | return 1; |
| 4500 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4501 | if (tmp == NULL) { |
| 4502 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 4503 | return 1; |
| 4504 | } |
| 4505 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4506 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4507 | res = obj2ast_arguments(tmp, &args, arena); |
| 4508 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4509 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4510 | } |
| 4511 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4512 | return 1; |
| 4513 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4514 | if (tmp == NULL) { |
| 4515 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 4516 | return 1; |
| 4517 | } |
| 4518 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4519 | int res; |
| 4520 | Py_ssize_t len; |
| 4521 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4522 | if (!PyList_Check(tmp)) { |
| 4523 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4524 | goto failed; |
| 4525 | } |
| 4526 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4527 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4528 | if (body == NULL) goto failed; |
| 4529 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4530 | stmt_ty val; |
| 4531 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4532 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4533 | if (len != PyList_GET_SIZE(tmp)) { |
| 4534 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 4535 | goto failed; |
| 4536 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4537 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4538 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4539 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4540 | } |
| 4541 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4542 | return 1; |
| 4543 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4544 | if (tmp == NULL) { |
| 4545 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 4546 | return 1; |
| 4547 | } |
| 4548 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4549 | int res; |
| 4550 | Py_ssize_t len; |
| 4551 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4552 | if (!PyList_Check(tmp)) { |
| 4553 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4554 | goto failed; |
| 4555 | } |
| 4556 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4557 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4558 | if (decorator_list == NULL) goto failed; |
| 4559 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4560 | expr_ty val; |
| 4561 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4562 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4563 | if (len != PyList_GET_SIZE(tmp)) { |
| 4564 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 4565 | goto failed; |
| 4566 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4567 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4568 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4569 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4570 | } |
| 4571 | if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4572 | return 1; |
| 4573 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4574 | if (tmp == NULL || tmp == Py_None) { |
| 4575 | Py_CLEAR(tmp); |
| 4576 | returns = NULL; |
| 4577 | } |
| 4578 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4579 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4580 | res = obj2ast_expr(tmp, &returns, arena); |
| 4581 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4582 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4583 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4584 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 4585 | return 1; |
| 4586 | } |
| 4587 | if (tmp == NULL || tmp == Py_None) { |
| 4588 | Py_CLEAR(tmp); |
| 4589 | type_comment = NULL; |
| 4590 | } |
| 4591 | else { |
| 4592 | int res; |
| 4593 | res = obj2ast_string(tmp, &type_comment, arena); |
| 4594 | if (res != 0) goto failed; |
| 4595 | Py_CLEAR(tmp); |
| 4596 | } |
| 4597 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 4598 | type_comment, lineno, col_offset, end_lineno, |
| 4599 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4600 | if (*out == NULL) goto failed; |
| 4601 | return 0; |
| 4602 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4603 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFunctionDef_type); |
| 4604 | if (isinstance == -1) { |
| 4605 | return 1; |
| 4606 | } |
| 4607 | if (isinstance) { |
| 4608 | identifier name; |
| 4609 | arguments_ty args; |
| 4610 | asdl_seq* body; |
| 4611 | asdl_seq* decorator_list; |
| 4612 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4613 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4614 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4615 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4616 | return 1; |
| 4617 | } |
| 4618 | if (tmp == NULL) { |
| 4619 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 4620 | return 1; |
| 4621 | } |
| 4622 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4623 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4624 | res = obj2ast_identifier(tmp, &name, arena); |
| 4625 | if (res != 0) goto failed; |
| 4626 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4627 | } |
| 4628 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4629 | return 1; |
| 4630 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4631 | if (tmp == NULL) { |
| 4632 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 4633 | return 1; |
| 4634 | } |
| 4635 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4636 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4637 | res = obj2ast_arguments(tmp, &args, arena); |
| 4638 | if (res != 0) goto failed; |
| 4639 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4640 | } |
| 4641 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4642 | return 1; |
| 4643 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4644 | if (tmp == NULL) { |
| 4645 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 4646 | return 1; |
| 4647 | } |
| 4648 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4649 | int res; |
| 4650 | Py_ssize_t len; |
| 4651 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4652 | if (!PyList_Check(tmp)) { |
| 4653 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4654 | goto failed; |
| 4655 | } |
| 4656 | len = PyList_GET_SIZE(tmp); |
| 4657 | body = _Py_asdl_seq_new(len, arena); |
| 4658 | if (body == NULL) goto failed; |
| 4659 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4660 | stmt_ty val; |
| 4661 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4662 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4663 | if (len != PyList_GET_SIZE(tmp)) { |
| 4664 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 4665 | goto failed; |
| 4666 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4667 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4668 | } |
| 4669 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4670 | } |
| 4671 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4672 | return 1; |
| 4673 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4674 | if (tmp == NULL) { |
| 4675 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 4676 | return 1; |
| 4677 | } |
| 4678 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4679 | int res; |
| 4680 | Py_ssize_t len; |
| 4681 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4682 | if (!PyList_Check(tmp)) { |
| 4683 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4684 | goto failed; |
| 4685 | } |
| 4686 | len = PyList_GET_SIZE(tmp); |
| 4687 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 4688 | if (decorator_list == NULL) goto failed; |
| 4689 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4690 | expr_ty val; |
| 4691 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4692 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4693 | if (len != PyList_GET_SIZE(tmp)) { |
| 4694 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 4695 | goto failed; |
| 4696 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4697 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4698 | } |
| 4699 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4700 | } |
| 4701 | if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4702 | return 1; |
| 4703 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4704 | if (tmp == NULL || tmp == Py_None) { |
| 4705 | Py_CLEAR(tmp); |
| 4706 | returns = NULL; |
| 4707 | } |
| 4708 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4709 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4710 | res = obj2ast_expr(tmp, &returns, arena); |
| 4711 | if (res != 0) goto failed; |
| 4712 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4713 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4714 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 4715 | return 1; |
| 4716 | } |
| 4717 | if (tmp == NULL || tmp == Py_None) { |
| 4718 | Py_CLEAR(tmp); |
| 4719 | type_comment = NULL; |
| 4720 | } |
| 4721 | else { |
| 4722 | int res; |
| 4723 | res = obj2ast_string(tmp, &type_comment, arena); |
| 4724 | if (res != 0) goto failed; |
| 4725 | Py_CLEAR(tmp); |
| 4726 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4727 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4728 | type_comment, lineno, col_offset, end_lineno, |
| 4729 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4730 | if (*out == NULL) goto failed; |
| 4731 | return 0; |
| 4732 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4733 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 4734 | if (isinstance == -1) { |
| 4735 | return 1; |
| 4736 | } |
| 4737 | if (isinstance) { |
| 4738 | identifier name; |
| 4739 | asdl_seq* bases; |
| 4740 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4741 | asdl_seq* body; |
| 4742 | asdl_seq* decorator_list; |
| 4743 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4744 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4745 | return 1; |
| 4746 | } |
| 4747 | if (tmp == NULL) { |
| 4748 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 4749 | return 1; |
| 4750 | } |
| 4751 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4752 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4753 | res = obj2ast_identifier(tmp, &name, arena); |
| 4754 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4755 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4756 | } |
| 4757 | if (_PyObject_LookupAttrId(obj, &PyId_bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4758 | return 1; |
| 4759 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4760 | if (tmp == NULL) { |
| 4761 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 4762 | return 1; |
| 4763 | } |
| 4764 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4765 | int res; |
| 4766 | Py_ssize_t len; |
| 4767 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4768 | if (!PyList_Check(tmp)) { |
| 4769 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4770 | goto failed; |
| 4771 | } |
| 4772 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4773 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4774 | if (bases == NULL) goto failed; |
| 4775 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4776 | expr_ty val; |
| 4777 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4778 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4779 | if (len != PyList_GET_SIZE(tmp)) { |
| 4780 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 4781 | goto failed; |
| 4782 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4783 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4784 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4785 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4786 | } |
| 4787 | if (_PyObject_LookupAttrId(obj, &PyId_keywords, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4788 | return 1; |
| 4789 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4790 | if (tmp == NULL) { |
| 4791 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 4792 | return 1; |
| 4793 | } |
| 4794 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4795 | int res; |
| 4796 | Py_ssize_t len; |
| 4797 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4798 | if (!PyList_Check(tmp)) { |
| 4799 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4800 | goto failed; |
| 4801 | } |
| 4802 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4803 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4804 | if (keywords == NULL) goto failed; |
| 4805 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4806 | keyword_ty val; |
| 4807 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4808 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4809 | if (len != PyList_GET_SIZE(tmp)) { |
| 4810 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 4811 | goto failed; |
| 4812 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4813 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4814 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4815 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4816 | } |
| 4817 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4818 | return 1; |
| 4819 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4820 | if (tmp == NULL) { |
| 4821 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 4822 | return 1; |
| 4823 | } |
| 4824 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4825 | int res; |
| 4826 | Py_ssize_t len; |
| 4827 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4828 | if (!PyList_Check(tmp)) { |
| 4829 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4830 | goto failed; |
| 4831 | } |
| 4832 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4833 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4834 | if (body == NULL) goto failed; |
| 4835 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4836 | stmt_ty val; |
| 4837 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4838 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4839 | if (len != PyList_GET_SIZE(tmp)) { |
| 4840 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 4841 | goto failed; |
| 4842 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4843 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4844 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4845 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4846 | } |
| 4847 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4848 | return 1; |
| 4849 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4850 | if (tmp == NULL) { |
| 4851 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 4852 | return 1; |
| 4853 | } |
| 4854 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4855 | int res; |
| 4856 | Py_ssize_t len; |
| 4857 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4858 | if (!PyList_Check(tmp)) { |
| 4859 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4860 | goto failed; |
| 4861 | } |
| 4862 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4863 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4864 | if (decorator_list == NULL) goto failed; |
| 4865 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4866 | expr_ty val; |
| 4867 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4868 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4869 | if (len != PyList_GET_SIZE(tmp)) { |
| 4870 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
| 4871 | goto failed; |
| 4872 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4873 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4874 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4875 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4876 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 4877 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4878 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4879 | if (*out == NULL) goto failed; |
| 4880 | return 0; |
| 4881 | } |
| 4882 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 4883 | if (isinstance == -1) { |
| 4884 | return 1; |
| 4885 | } |
| 4886 | if (isinstance) { |
| 4887 | expr_ty value; |
| 4888 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4889 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 4890 | return 1; |
| 4891 | } |
| 4892 | if (tmp == NULL || tmp == Py_None) { |
| 4893 | Py_CLEAR(tmp); |
| 4894 | value = NULL; |
| 4895 | } |
| 4896 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4897 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4898 | res = obj2ast_expr(tmp, &value, arena); |
| 4899 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4900 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4901 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4902 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 4903 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4904 | if (*out == NULL) goto failed; |
| 4905 | return 0; |
| 4906 | } |
| 4907 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 4908 | if (isinstance == -1) { |
| 4909 | return 1; |
| 4910 | } |
| 4911 | if (isinstance) { |
| 4912 | asdl_seq* targets; |
| 4913 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4914 | if (_PyObject_LookupAttrId(obj, &PyId_targets, &tmp) < 0) { |
| 4915 | return 1; |
| 4916 | } |
| 4917 | if (tmp == NULL) { |
| 4918 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 4919 | return 1; |
| 4920 | } |
| 4921 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4922 | int res; |
| 4923 | Py_ssize_t len; |
| 4924 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4925 | if (!PyList_Check(tmp)) { |
| 4926 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4927 | goto failed; |
| 4928 | } |
| 4929 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4930 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4931 | if (targets == NULL) goto failed; |
| 4932 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4933 | expr_ty val; |
| 4934 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4935 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4936 | if (len != PyList_GET_SIZE(tmp)) { |
| 4937 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 4938 | goto failed; |
| 4939 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4940 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4941 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4942 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4943 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4944 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 4945 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4946 | if (*out == NULL) goto failed; |
| 4947 | return 0; |
| 4948 | } |
| 4949 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 4950 | if (isinstance == -1) { |
| 4951 | return 1; |
| 4952 | } |
| 4953 | if (isinstance) { |
| 4954 | asdl_seq* targets; |
| 4955 | expr_ty value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4956 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4957 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4958 | if (_PyObject_LookupAttrId(obj, &PyId_targets, &tmp) < 0) { |
| 4959 | return 1; |
| 4960 | } |
| 4961 | if (tmp == NULL) { |
| 4962 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 4963 | return 1; |
| 4964 | } |
| 4965 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4966 | int res; |
| 4967 | Py_ssize_t len; |
| 4968 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4969 | if (!PyList_Check(tmp)) { |
| 4970 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4971 | goto failed; |
| 4972 | } |
| 4973 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4974 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4975 | if (targets == NULL) goto failed; |
| 4976 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4977 | expr_ty val; |
| 4978 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4979 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4980 | if (len != PyList_GET_SIZE(tmp)) { |
| 4981 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 4982 | goto failed; |
| 4983 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4984 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4985 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4986 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4987 | } |
| 4988 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4989 | return 1; |
| 4990 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4991 | if (tmp == NULL) { |
| 4992 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 4993 | return 1; |
| 4994 | } |
| 4995 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4996 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4997 | res = obj2ast_expr(tmp, &value, arena); |
| 4998 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4999 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5000 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5001 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5002 | return 1; |
| 5003 | } |
| 5004 | if (tmp == NULL || tmp == Py_None) { |
| 5005 | Py_CLEAR(tmp); |
| 5006 | type_comment = NULL; |
| 5007 | } |
| 5008 | else { |
| 5009 | int res; |
| 5010 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5011 | if (res != 0) goto failed; |
| 5012 | Py_CLEAR(tmp); |
| 5013 | } |
| 5014 | *out = Assign(targets, value, type_comment, lineno, col_offset, |
| 5015 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5016 | if (*out == NULL) goto failed; |
| 5017 | return 0; |
| 5018 | } |
| 5019 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 5020 | if (isinstance == -1) { |
| 5021 | return 1; |
| 5022 | } |
| 5023 | if (isinstance) { |
| 5024 | expr_ty target; |
| 5025 | operator_ty op; |
| 5026 | expr_ty value; |
| 5027 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5028 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5029 | return 1; |
| 5030 | } |
| 5031 | if (tmp == NULL) { |
| 5032 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 5033 | return 1; |
| 5034 | } |
| 5035 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5036 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5037 | res = obj2ast_expr(tmp, &target, arena); |
| 5038 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5039 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5040 | } |
| 5041 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5042 | return 1; |
| 5043 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5044 | if (tmp == NULL) { |
| 5045 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 5046 | return 1; |
| 5047 | } |
| 5048 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5049 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5050 | res = obj2ast_operator(tmp, &op, arena); |
| 5051 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5052 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5053 | } |
| 5054 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5055 | return 1; |
| 5056 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5057 | if (tmp == NULL) { |
| 5058 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 5059 | return 1; |
| 5060 | } |
| 5061 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5062 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5063 | res = obj2ast_expr(tmp, &value, arena); |
| 5064 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5065 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5066 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5067 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 5068 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5069 | if (*out == NULL) goto failed; |
| 5070 | return 0; |
| 5071 | } |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5072 | isinstance = PyObject_IsInstance(obj, (PyObject*)AnnAssign_type); |
| 5073 | if (isinstance == -1) { |
| 5074 | return 1; |
| 5075 | } |
| 5076 | if (isinstance) { |
| 5077 | expr_ty target; |
| 5078 | expr_ty annotation; |
| 5079 | expr_ty value; |
| 5080 | int simple; |
| 5081 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5082 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5083 | return 1; |
| 5084 | } |
| 5085 | if (tmp == NULL) { |
| 5086 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 5087 | return 1; |
| 5088 | } |
| 5089 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5090 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5091 | res = obj2ast_expr(tmp, &target, arena); |
| 5092 | if (res != 0) goto failed; |
| 5093 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5094 | } |
| 5095 | if (_PyObject_LookupAttrId(obj, &PyId_annotation, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5096 | return 1; |
| 5097 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5098 | if (tmp == NULL) { |
| 5099 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 5100 | return 1; |
| 5101 | } |
| 5102 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5103 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5104 | res = obj2ast_expr(tmp, &annotation, arena); |
| 5105 | if (res != 0) goto failed; |
| 5106 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5107 | } |
| 5108 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5109 | return 1; |
| 5110 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5111 | if (tmp == NULL || tmp == Py_None) { |
| 5112 | Py_CLEAR(tmp); |
| 5113 | value = NULL; |
| 5114 | } |
| 5115 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5116 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5117 | res = obj2ast_expr(tmp, &value, arena); |
| 5118 | if (res != 0) goto failed; |
| 5119 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5120 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5121 | if (_PyObject_LookupAttrId(obj, &PyId_simple, &tmp) < 0) { |
| 5122 | return 1; |
| 5123 | } |
| 5124 | if (tmp == NULL) { |
| 5125 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 5126 | return 1; |
| 5127 | } |
| 5128 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5129 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5130 | res = obj2ast_int(tmp, &simple, arena); |
| 5131 | if (res != 0) goto failed; |
| 5132 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5133 | } |
| 5134 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5135 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5136 | if (*out == NULL) goto failed; |
| 5137 | return 0; |
| 5138 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5139 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 5140 | if (isinstance == -1) { |
| 5141 | return 1; |
| 5142 | } |
| 5143 | if (isinstance) { |
| 5144 | expr_ty target; |
| 5145 | expr_ty iter; |
| 5146 | asdl_seq* body; |
| 5147 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5148 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5149 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5150 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5151 | return 1; |
| 5152 | } |
| 5153 | if (tmp == NULL) { |
| 5154 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 5155 | return 1; |
| 5156 | } |
| 5157 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5158 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5159 | res = obj2ast_expr(tmp, &target, arena); |
| 5160 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5161 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5162 | } |
| 5163 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5164 | return 1; |
| 5165 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5166 | if (tmp == NULL) { |
| 5167 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 5168 | return 1; |
| 5169 | } |
| 5170 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5171 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5172 | res = obj2ast_expr(tmp, &iter, arena); |
| 5173 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5174 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5175 | } |
| 5176 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5177 | return 1; |
| 5178 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5179 | if (tmp == NULL) { |
| 5180 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 5181 | return 1; |
| 5182 | } |
| 5183 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5184 | int res; |
| 5185 | Py_ssize_t len; |
| 5186 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5187 | if (!PyList_Check(tmp)) { |
| 5188 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5189 | goto failed; |
| 5190 | } |
| 5191 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5192 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5193 | if (body == NULL) goto failed; |
| 5194 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5195 | stmt_ty val; |
| 5196 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5197 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5198 | if (len != PyList_GET_SIZE(tmp)) { |
| 5199 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 5200 | goto failed; |
| 5201 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5202 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5203 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5204 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5205 | } |
| 5206 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5207 | return 1; |
| 5208 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5209 | if (tmp == NULL) { |
| 5210 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 5211 | return 1; |
| 5212 | } |
| 5213 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5214 | int res; |
| 5215 | Py_ssize_t len; |
| 5216 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5217 | if (!PyList_Check(tmp)) { |
| 5218 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5219 | goto failed; |
| 5220 | } |
| 5221 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5222 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5223 | if (orelse == NULL) goto failed; |
| 5224 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5225 | stmt_ty val; |
| 5226 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5227 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5228 | if (len != PyList_GET_SIZE(tmp)) { |
| 5229 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 5230 | goto failed; |
| 5231 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5232 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5233 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5234 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5235 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5236 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5237 | return 1; |
| 5238 | } |
| 5239 | if (tmp == NULL || tmp == Py_None) { |
| 5240 | Py_CLEAR(tmp); |
| 5241 | type_comment = NULL; |
| 5242 | } |
| 5243 | else { |
| 5244 | int res; |
| 5245 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5246 | if (res != 0) goto failed; |
| 5247 | Py_CLEAR(tmp); |
| 5248 | } |
| 5249 | *out = For(target, iter, body, orelse, type_comment, lineno, |
| 5250 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5251 | if (*out == NULL) goto failed; |
| 5252 | return 0; |
| 5253 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5254 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFor_type); |
| 5255 | if (isinstance == -1) { |
| 5256 | return 1; |
| 5257 | } |
| 5258 | if (isinstance) { |
| 5259 | expr_ty target; |
| 5260 | expr_ty iter; |
| 5261 | asdl_seq* body; |
| 5262 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5263 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5264 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5265 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5266 | return 1; |
| 5267 | } |
| 5268 | if (tmp == NULL) { |
| 5269 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 5270 | return 1; |
| 5271 | } |
| 5272 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5273 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5274 | res = obj2ast_expr(tmp, &target, arena); |
| 5275 | if (res != 0) goto failed; |
| 5276 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5277 | } |
| 5278 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5279 | return 1; |
| 5280 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5281 | if (tmp == NULL) { |
| 5282 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 5283 | return 1; |
| 5284 | } |
| 5285 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5286 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5287 | res = obj2ast_expr(tmp, &iter, arena); |
| 5288 | if (res != 0) goto failed; |
| 5289 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5290 | } |
| 5291 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5292 | return 1; |
| 5293 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5294 | if (tmp == NULL) { |
| 5295 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 5296 | return 1; |
| 5297 | } |
| 5298 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5299 | int res; |
| 5300 | Py_ssize_t len; |
| 5301 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5302 | if (!PyList_Check(tmp)) { |
| 5303 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5304 | goto failed; |
| 5305 | } |
| 5306 | len = PyList_GET_SIZE(tmp); |
| 5307 | body = _Py_asdl_seq_new(len, arena); |
| 5308 | if (body == NULL) goto failed; |
| 5309 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5310 | stmt_ty val; |
| 5311 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5312 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5313 | if (len != PyList_GET_SIZE(tmp)) { |
| 5314 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 5315 | goto failed; |
| 5316 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5317 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5318 | } |
| 5319 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5320 | } |
| 5321 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5322 | return 1; |
| 5323 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5324 | if (tmp == NULL) { |
| 5325 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 5326 | return 1; |
| 5327 | } |
| 5328 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5329 | int res; |
| 5330 | Py_ssize_t len; |
| 5331 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5332 | if (!PyList_Check(tmp)) { |
| 5333 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5334 | goto failed; |
| 5335 | } |
| 5336 | len = PyList_GET_SIZE(tmp); |
| 5337 | orelse = _Py_asdl_seq_new(len, arena); |
| 5338 | if (orelse == NULL) goto failed; |
| 5339 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5340 | stmt_ty val; |
| 5341 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5342 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5343 | if (len != PyList_GET_SIZE(tmp)) { |
| 5344 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 5345 | goto failed; |
| 5346 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5347 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5348 | } |
| 5349 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5350 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5351 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5352 | return 1; |
| 5353 | } |
| 5354 | if (tmp == NULL || tmp == Py_None) { |
| 5355 | Py_CLEAR(tmp); |
| 5356 | type_comment = NULL; |
| 5357 | } |
| 5358 | else { |
| 5359 | int res; |
| 5360 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5361 | if (res != 0) goto failed; |
| 5362 | Py_CLEAR(tmp); |
| 5363 | } |
| 5364 | *out = AsyncFor(target, iter, body, orelse, type_comment, lineno, |
| 5365 | col_offset, end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5366 | if (*out == NULL) goto failed; |
| 5367 | return 0; |
| 5368 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5369 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 5370 | if (isinstance == -1) { |
| 5371 | return 1; |
| 5372 | } |
| 5373 | if (isinstance) { |
| 5374 | expr_ty test; |
| 5375 | asdl_seq* body; |
| 5376 | asdl_seq* orelse; |
| 5377 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5378 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 5379 | return 1; |
| 5380 | } |
| 5381 | if (tmp == NULL) { |
| 5382 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 5383 | return 1; |
| 5384 | } |
| 5385 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5386 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5387 | res = obj2ast_expr(tmp, &test, arena); |
| 5388 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5389 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5390 | } |
| 5391 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5392 | return 1; |
| 5393 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5394 | if (tmp == NULL) { |
| 5395 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 5396 | return 1; |
| 5397 | } |
| 5398 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5399 | int res; |
| 5400 | Py_ssize_t len; |
| 5401 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5402 | if (!PyList_Check(tmp)) { |
| 5403 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5404 | goto failed; |
| 5405 | } |
| 5406 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5407 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5408 | if (body == NULL) goto failed; |
| 5409 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5410 | stmt_ty val; |
| 5411 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5412 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5413 | if (len != PyList_GET_SIZE(tmp)) { |
| 5414 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 5415 | goto failed; |
| 5416 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5417 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5418 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5419 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5420 | } |
| 5421 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5422 | return 1; |
| 5423 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5424 | if (tmp == NULL) { |
| 5425 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 5426 | return 1; |
| 5427 | } |
| 5428 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5429 | int res; |
| 5430 | Py_ssize_t len; |
| 5431 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5432 | if (!PyList_Check(tmp)) { |
| 5433 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5434 | goto failed; |
| 5435 | } |
| 5436 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5437 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5438 | if (orelse == NULL) goto failed; |
| 5439 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5440 | stmt_ty val; |
| 5441 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5442 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5443 | if (len != PyList_GET_SIZE(tmp)) { |
| 5444 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 5445 | goto failed; |
| 5446 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5447 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5448 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5449 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5450 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5451 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 5452 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5453 | if (*out == NULL) goto failed; |
| 5454 | return 0; |
| 5455 | } |
| 5456 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 5457 | if (isinstance == -1) { |
| 5458 | return 1; |
| 5459 | } |
| 5460 | if (isinstance) { |
| 5461 | expr_ty test; |
| 5462 | asdl_seq* body; |
| 5463 | asdl_seq* orelse; |
| 5464 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5465 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 5466 | return 1; |
| 5467 | } |
| 5468 | if (tmp == NULL) { |
| 5469 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 5470 | return 1; |
| 5471 | } |
| 5472 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5473 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5474 | res = obj2ast_expr(tmp, &test, arena); |
| 5475 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5476 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5477 | } |
| 5478 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5479 | return 1; |
| 5480 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5481 | if (tmp == NULL) { |
| 5482 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 5483 | return 1; |
| 5484 | } |
| 5485 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5486 | int res; |
| 5487 | Py_ssize_t len; |
| 5488 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5489 | if (!PyList_Check(tmp)) { |
| 5490 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5491 | goto failed; |
| 5492 | } |
| 5493 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5494 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5495 | if (body == NULL) goto failed; |
| 5496 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5497 | stmt_ty val; |
| 5498 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5499 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5500 | if (len != PyList_GET_SIZE(tmp)) { |
| 5501 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 5502 | goto failed; |
| 5503 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5504 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5505 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5506 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5507 | } |
| 5508 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5509 | return 1; |
| 5510 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5511 | if (tmp == NULL) { |
| 5512 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 5513 | return 1; |
| 5514 | } |
| 5515 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5516 | int res; |
| 5517 | Py_ssize_t len; |
| 5518 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5519 | if (!PyList_Check(tmp)) { |
| 5520 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5521 | goto failed; |
| 5522 | } |
| 5523 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5524 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5525 | if (orelse == NULL) goto failed; |
| 5526 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5527 | stmt_ty val; |
| 5528 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5529 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5530 | if (len != PyList_GET_SIZE(tmp)) { |
| 5531 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 5532 | goto failed; |
| 5533 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5534 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5535 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5536 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5537 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5538 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 5539 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5540 | if (*out == NULL) goto failed; |
| 5541 | return 0; |
| 5542 | } |
| 5543 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 5544 | if (isinstance == -1) { |
| 5545 | return 1; |
| 5546 | } |
| 5547 | if (isinstance) { |
| 5548 | asdl_seq* items; |
| 5549 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5550 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5551 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5552 | if (_PyObject_LookupAttrId(obj, &PyId_items, &tmp) < 0) { |
| 5553 | return 1; |
| 5554 | } |
| 5555 | if (tmp == NULL) { |
| 5556 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 5557 | return 1; |
| 5558 | } |
| 5559 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5560 | int res; |
| 5561 | Py_ssize_t len; |
| 5562 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5563 | if (!PyList_Check(tmp)) { |
| 5564 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5565 | goto failed; |
| 5566 | } |
| 5567 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5568 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5569 | if (items == NULL) goto failed; |
| 5570 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5571 | withitem_ty val; |
| 5572 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5573 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5574 | if (len != PyList_GET_SIZE(tmp)) { |
| 5575 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 5576 | goto failed; |
| 5577 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5578 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5579 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5580 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5581 | } |
| 5582 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5583 | return 1; |
| 5584 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5585 | if (tmp == NULL) { |
| 5586 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 5587 | return 1; |
| 5588 | } |
| 5589 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5590 | int res; |
| 5591 | Py_ssize_t len; |
| 5592 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5593 | if (!PyList_Check(tmp)) { |
| 5594 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5595 | goto failed; |
| 5596 | } |
| 5597 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5598 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5599 | if (body == NULL) goto failed; |
| 5600 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5601 | stmt_ty val; |
| 5602 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5603 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5604 | if (len != PyList_GET_SIZE(tmp)) { |
| 5605 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 5606 | goto failed; |
| 5607 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5608 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5609 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5610 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5611 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5612 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5613 | return 1; |
| 5614 | } |
| 5615 | if (tmp == NULL || tmp == Py_None) { |
| 5616 | Py_CLEAR(tmp); |
| 5617 | type_comment = NULL; |
| 5618 | } |
| 5619 | else { |
| 5620 | int res; |
| 5621 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5622 | if (res != 0) goto failed; |
| 5623 | Py_CLEAR(tmp); |
| 5624 | } |
| 5625 | *out = With(items, body, type_comment, lineno, col_offset, end_lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5626 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5627 | if (*out == NULL) goto failed; |
| 5628 | return 0; |
| 5629 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5630 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncWith_type); |
| 5631 | if (isinstance == -1) { |
| 5632 | return 1; |
| 5633 | } |
| 5634 | if (isinstance) { |
| 5635 | asdl_seq* items; |
| 5636 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5637 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5638 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5639 | if (_PyObject_LookupAttrId(obj, &PyId_items, &tmp) < 0) { |
| 5640 | return 1; |
| 5641 | } |
| 5642 | if (tmp == NULL) { |
| 5643 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 5644 | return 1; |
| 5645 | } |
| 5646 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5647 | int res; |
| 5648 | Py_ssize_t len; |
| 5649 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5650 | if (!PyList_Check(tmp)) { |
| 5651 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5652 | goto failed; |
| 5653 | } |
| 5654 | len = PyList_GET_SIZE(tmp); |
| 5655 | items = _Py_asdl_seq_new(len, arena); |
| 5656 | if (items == NULL) goto failed; |
| 5657 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5658 | withitem_ty val; |
| 5659 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5660 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5661 | if (len != PyList_GET_SIZE(tmp)) { |
| 5662 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 5663 | goto failed; |
| 5664 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5665 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5666 | } |
| 5667 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5668 | } |
| 5669 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5670 | return 1; |
| 5671 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5672 | if (tmp == NULL) { |
| 5673 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 5674 | return 1; |
| 5675 | } |
| 5676 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5677 | int res; |
| 5678 | Py_ssize_t len; |
| 5679 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5680 | if (!PyList_Check(tmp)) { |
| 5681 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5682 | goto failed; |
| 5683 | } |
| 5684 | len = PyList_GET_SIZE(tmp); |
| 5685 | body = _Py_asdl_seq_new(len, arena); |
| 5686 | if (body == NULL) goto failed; |
| 5687 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5688 | stmt_ty val; |
| 5689 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5690 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5691 | if (len != PyList_GET_SIZE(tmp)) { |
| 5692 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 5693 | goto failed; |
| 5694 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5695 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5696 | } |
| 5697 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5698 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5699 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5700 | return 1; |
| 5701 | } |
| 5702 | if (tmp == NULL || tmp == Py_None) { |
| 5703 | Py_CLEAR(tmp); |
| 5704 | type_comment = NULL; |
| 5705 | } |
| 5706 | else { |
| 5707 | int res; |
| 5708 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5709 | if (res != 0) goto failed; |
| 5710 | Py_CLEAR(tmp); |
| 5711 | } |
| 5712 | *out = AsyncWith(items, body, type_comment, lineno, col_offset, |
| 5713 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5714 | if (*out == NULL) goto failed; |
| 5715 | return 0; |
| 5716 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5717 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 5718 | if (isinstance == -1) { |
| 5719 | return 1; |
| 5720 | } |
| 5721 | if (isinstance) { |
| 5722 | expr_ty exc; |
| 5723 | expr_ty cause; |
| 5724 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5725 | if (_PyObject_LookupAttrId(obj, &PyId_exc, &tmp) < 0) { |
| 5726 | return 1; |
| 5727 | } |
| 5728 | if (tmp == NULL || tmp == Py_None) { |
| 5729 | Py_CLEAR(tmp); |
| 5730 | exc = NULL; |
| 5731 | } |
| 5732 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5733 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5734 | res = obj2ast_expr(tmp, &exc, arena); |
| 5735 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5736 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5737 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5738 | if (_PyObject_LookupAttrId(obj, &PyId_cause, &tmp) < 0) { |
| 5739 | return 1; |
| 5740 | } |
| 5741 | if (tmp == NULL || tmp == Py_None) { |
| 5742 | Py_CLEAR(tmp); |
| 5743 | cause = NULL; |
| 5744 | } |
| 5745 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5746 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5747 | res = obj2ast_expr(tmp, &cause, arena); |
| 5748 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5749 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5750 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5751 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 5752 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5753 | if (*out == NULL) goto failed; |
| 5754 | return 0; |
| 5755 | } |
| 5756 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
| 5757 | if (isinstance == -1) { |
| 5758 | return 1; |
| 5759 | } |
| 5760 | if (isinstance) { |
| 5761 | asdl_seq* body; |
| 5762 | asdl_seq* handlers; |
| 5763 | asdl_seq* orelse; |
| 5764 | asdl_seq* finalbody; |
| 5765 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5766 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 5767 | return 1; |
| 5768 | } |
| 5769 | if (tmp == NULL) { |
| 5770 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 5771 | return 1; |
| 5772 | } |
| 5773 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5774 | int res; |
| 5775 | Py_ssize_t len; |
| 5776 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5777 | if (!PyList_Check(tmp)) { |
| 5778 | PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5779 | goto failed; |
| 5780 | } |
| 5781 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5782 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5783 | if (body == NULL) goto failed; |
| 5784 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5785 | stmt_ty val; |
| 5786 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5787 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5788 | if (len != PyList_GET_SIZE(tmp)) { |
| 5789 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 5790 | goto failed; |
| 5791 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5792 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5793 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5794 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5795 | } |
| 5796 | if (_PyObject_LookupAttrId(obj, &PyId_handlers, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5797 | return 1; |
| 5798 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5799 | if (tmp == NULL) { |
| 5800 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 5801 | return 1; |
| 5802 | } |
| 5803 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5804 | int res; |
| 5805 | Py_ssize_t len; |
| 5806 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5807 | if (!PyList_Check(tmp)) { |
| 5808 | PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5809 | goto failed; |
| 5810 | } |
| 5811 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5812 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5813 | if (handlers == NULL) goto failed; |
| 5814 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5815 | excepthandler_ty val; |
| 5816 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5817 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5818 | if (len != PyList_GET_SIZE(tmp)) { |
| 5819 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 5820 | goto failed; |
| 5821 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5822 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5823 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5824 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5825 | } |
| 5826 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5827 | return 1; |
| 5828 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5829 | if (tmp == NULL) { |
| 5830 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 5831 | return 1; |
| 5832 | } |
| 5833 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5834 | int res; |
| 5835 | Py_ssize_t len; |
| 5836 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5837 | if (!PyList_Check(tmp)) { |
| 5838 | PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5839 | goto failed; |
| 5840 | } |
| 5841 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5842 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5843 | if (orelse == NULL) goto failed; |
| 5844 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5845 | stmt_ty val; |
| 5846 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5847 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5848 | if (len != PyList_GET_SIZE(tmp)) { |
| 5849 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 5850 | goto failed; |
| 5851 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5852 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5853 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5854 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5855 | } |
| 5856 | if (_PyObject_LookupAttrId(obj, &PyId_finalbody, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5857 | return 1; |
| 5858 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5859 | if (tmp == NULL) { |
| 5860 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 5861 | return 1; |
| 5862 | } |
| 5863 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5864 | int res; |
| 5865 | Py_ssize_t len; |
| 5866 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5867 | if (!PyList_Check(tmp)) { |
| 5868 | PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5869 | goto failed; |
| 5870 | } |
| 5871 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5872 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5873 | if (finalbody == NULL) goto failed; |
| 5874 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5875 | stmt_ty val; |
| 5876 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5877 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5878 | if (len != PyList_GET_SIZE(tmp)) { |
| 5879 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 5880 | goto failed; |
| 5881 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5882 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5883 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5884 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5885 | } |
| 5886 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5887 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5888 | if (*out == NULL) goto failed; |
| 5889 | return 0; |
| 5890 | } |
| 5891 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 5892 | if (isinstance == -1) { |
| 5893 | return 1; |
| 5894 | } |
| 5895 | if (isinstance) { |
| 5896 | expr_ty test; |
| 5897 | expr_ty msg; |
| 5898 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5899 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 5900 | return 1; |
| 5901 | } |
| 5902 | if (tmp == NULL) { |
| 5903 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 5904 | return 1; |
| 5905 | } |
| 5906 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5907 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5908 | res = obj2ast_expr(tmp, &test, arena); |
| 5909 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5910 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5911 | } |
| 5912 | if (_PyObject_LookupAttrId(obj, &PyId_msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5913 | return 1; |
| 5914 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5915 | if (tmp == NULL || tmp == Py_None) { |
| 5916 | Py_CLEAR(tmp); |
| 5917 | msg = NULL; |
| 5918 | } |
| 5919 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5920 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5921 | res = obj2ast_expr(tmp, &msg, arena); |
| 5922 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5923 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5924 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5925 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 5926 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5927 | if (*out == NULL) goto failed; |
| 5928 | return 0; |
| 5929 | } |
| 5930 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 5931 | if (isinstance == -1) { |
| 5932 | return 1; |
| 5933 | } |
| 5934 | if (isinstance) { |
| 5935 | asdl_seq* names; |
| 5936 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5937 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 5938 | return 1; |
| 5939 | } |
| 5940 | if (tmp == NULL) { |
| 5941 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 5942 | return 1; |
| 5943 | } |
| 5944 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5945 | int res; |
| 5946 | Py_ssize_t len; |
| 5947 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5948 | if (!PyList_Check(tmp)) { |
| 5949 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5950 | goto failed; |
| 5951 | } |
| 5952 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5953 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5954 | if (names == NULL) goto failed; |
| 5955 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5956 | alias_ty val; |
| 5957 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5958 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5959 | if (len != PyList_GET_SIZE(tmp)) { |
| 5960 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 5961 | goto failed; |
| 5962 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5963 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5964 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5965 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5966 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5967 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 5968 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5969 | if (*out == NULL) goto failed; |
| 5970 | return 0; |
| 5971 | } |
| 5972 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 5973 | if (isinstance == -1) { |
| 5974 | return 1; |
| 5975 | } |
| 5976 | if (isinstance) { |
| 5977 | identifier module; |
| 5978 | asdl_seq* names; |
| 5979 | int level; |
| 5980 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5981 | if (_PyObject_LookupAttrId(obj, &PyId_module, &tmp) < 0) { |
| 5982 | return 1; |
| 5983 | } |
| 5984 | if (tmp == NULL || tmp == Py_None) { |
| 5985 | Py_CLEAR(tmp); |
| 5986 | module = NULL; |
| 5987 | } |
| 5988 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5989 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5990 | res = obj2ast_identifier(tmp, &module, arena); |
| 5991 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5992 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5993 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5994 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 5995 | return 1; |
| 5996 | } |
| 5997 | if (tmp == NULL) { |
| 5998 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 5999 | return 1; |
| 6000 | } |
| 6001 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6002 | int res; |
| 6003 | Py_ssize_t len; |
| 6004 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6005 | if (!PyList_Check(tmp)) { |
| 6006 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6007 | goto failed; |
| 6008 | } |
| 6009 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6010 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6011 | if (names == NULL) goto failed; |
| 6012 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6013 | alias_ty val; |
| 6014 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6015 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6016 | if (len != PyList_GET_SIZE(tmp)) { |
| 6017 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 6018 | goto failed; |
| 6019 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6020 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6021 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6022 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6023 | } |
| 6024 | if (_PyObject_LookupAttrId(obj, &PyId_level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6025 | return 1; |
| 6026 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6027 | if (tmp == NULL || tmp == Py_None) { |
| 6028 | Py_CLEAR(tmp); |
| 6029 | level = 0; |
| 6030 | } |
| 6031 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6032 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6033 | res = obj2ast_int(tmp, &level, arena); |
| 6034 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6035 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6036 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6037 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 6038 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6039 | if (*out == NULL) goto failed; |
| 6040 | return 0; |
| 6041 | } |
| 6042 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 6043 | if (isinstance == -1) { |
| 6044 | return 1; |
| 6045 | } |
| 6046 | if (isinstance) { |
| 6047 | asdl_seq* names; |
| 6048 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6049 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 6050 | return 1; |
| 6051 | } |
| 6052 | if (tmp == NULL) { |
| 6053 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 6054 | return 1; |
| 6055 | } |
| 6056 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6057 | int res; |
| 6058 | Py_ssize_t len; |
| 6059 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6060 | if (!PyList_Check(tmp)) { |
| 6061 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6062 | goto failed; |
| 6063 | } |
| 6064 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6065 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6066 | if (names == NULL) goto failed; |
| 6067 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6068 | identifier val; |
| 6069 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6070 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6071 | if (len != PyList_GET_SIZE(tmp)) { |
| 6072 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 6073 | goto failed; |
| 6074 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6075 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6076 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6077 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6078 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6079 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6080 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6081 | if (*out == NULL) goto failed; |
| 6082 | return 0; |
| 6083 | } |
| 6084 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 6085 | if (isinstance == -1) { |
| 6086 | return 1; |
| 6087 | } |
| 6088 | if (isinstance) { |
| 6089 | asdl_seq* names; |
| 6090 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6091 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 6092 | return 1; |
| 6093 | } |
| 6094 | if (tmp == NULL) { |
| 6095 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 6096 | return 1; |
| 6097 | } |
| 6098 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6099 | int res; |
| 6100 | Py_ssize_t len; |
| 6101 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6102 | if (!PyList_Check(tmp)) { |
| 6103 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6104 | goto failed; |
| 6105 | } |
| 6106 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6107 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6108 | if (names == NULL) goto failed; |
| 6109 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6110 | identifier val; |
| 6111 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6112 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6113 | if (len != PyList_GET_SIZE(tmp)) { |
| 6114 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 6115 | goto failed; |
| 6116 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6117 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6118 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6119 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6120 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6121 | *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6122 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6123 | if (*out == NULL) goto failed; |
| 6124 | return 0; |
| 6125 | } |
| 6126 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 6127 | if (isinstance == -1) { |
| 6128 | return 1; |
| 6129 | } |
| 6130 | if (isinstance) { |
| 6131 | expr_ty value; |
| 6132 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6133 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6134 | return 1; |
| 6135 | } |
| 6136 | if (tmp == NULL) { |
| 6137 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 6138 | return 1; |
| 6139 | } |
| 6140 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6141 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6142 | res = obj2ast_expr(tmp, &value, arena); |
| 6143 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6144 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6145 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6146 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6147 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6148 | if (*out == NULL) goto failed; |
| 6149 | return 0; |
| 6150 | } |
| 6151 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 6152 | if (isinstance == -1) { |
| 6153 | return 1; |
| 6154 | } |
| 6155 | if (isinstance) { |
| 6156 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6157 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6158 | if (*out == NULL) goto failed; |
| 6159 | return 0; |
| 6160 | } |
| 6161 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 6162 | if (isinstance == -1) { |
| 6163 | return 1; |
| 6164 | } |
| 6165 | if (isinstance) { |
| 6166 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6167 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6168 | if (*out == NULL) goto failed; |
| 6169 | return 0; |
| 6170 | } |
| 6171 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 6172 | if (isinstance == -1) { |
| 6173 | return 1; |
| 6174 | } |
| 6175 | if (isinstance) { |
| 6176 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6177 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6178 | if (*out == NULL) goto failed; |
| 6179 | return 0; |
| 6180 | } |
| 6181 | |
| 6182 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 6183 | failed: |
| 6184 | Py_XDECREF(tmp); |
| 6185 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6186 | } |
| 6187 | |
| 6188 | int |
| 6189 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 6190 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6191 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6192 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6193 | PyObject *tmp = NULL; |
| 6194 | int lineno; |
| 6195 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6196 | int end_lineno; |
| 6197 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6198 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6199 | if (obj == Py_None) { |
| 6200 | *out = NULL; |
| 6201 | return 0; |
| 6202 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6203 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 6204 | return 1; |
| 6205 | } |
| 6206 | if (tmp == NULL) { |
| 6207 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 6208 | return 1; |
| 6209 | } |
| 6210 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6211 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6212 | res = obj2ast_int(tmp, &lineno, arena); |
| 6213 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6214 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6215 | } |
| 6216 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6217 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6218 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6219 | if (tmp == NULL) { |
| 6220 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 6221 | return 1; |
| 6222 | } |
| 6223 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6224 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6225 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6226 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6227 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6228 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6229 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 6230 | return 1; |
| 6231 | } |
| 6232 | if (tmp == NULL || tmp == Py_None) { |
| 6233 | Py_CLEAR(tmp); |
| 6234 | end_lineno = 0; |
| 6235 | } |
| 6236 | else { |
| 6237 | int res; |
| 6238 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 6239 | if (res != 0) goto failed; |
| 6240 | Py_CLEAR(tmp); |
| 6241 | } |
| 6242 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 6243 | return 1; |
| 6244 | } |
| 6245 | if (tmp == NULL || tmp == Py_None) { |
| 6246 | Py_CLEAR(tmp); |
| 6247 | end_col_offset = 0; |
| 6248 | } |
| 6249 | else { |
| 6250 | int res; |
| 6251 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 6252 | if (res != 0) goto failed; |
| 6253 | Py_CLEAR(tmp); |
| 6254 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6255 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 6256 | if (isinstance == -1) { |
| 6257 | return 1; |
| 6258 | } |
| 6259 | if (isinstance) { |
| 6260 | boolop_ty op; |
| 6261 | asdl_seq* values; |
| 6262 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6263 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
| 6264 | return 1; |
| 6265 | } |
| 6266 | if (tmp == NULL) { |
| 6267 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 6268 | return 1; |
| 6269 | } |
| 6270 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6271 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6272 | res = obj2ast_boolop(tmp, &op, arena); |
| 6273 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6274 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6275 | } |
| 6276 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6277 | return 1; |
| 6278 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6279 | if (tmp == NULL) { |
| 6280 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 6281 | return 1; |
| 6282 | } |
| 6283 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6284 | int res; |
| 6285 | Py_ssize_t len; |
| 6286 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6287 | if (!PyList_Check(tmp)) { |
| 6288 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6289 | goto failed; |
| 6290 | } |
| 6291 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6292 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6293 | if (values == NULL) goto failed; |
| 6294 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6295 | expr_ty val; |
| 6296 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6297 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6298 | if (len != PyList_GET_SIZE(tmp)) { |
| 6299 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 6300 | goto failed; |
| 6301 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6302 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6303 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6304 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6305 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6306 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 6307 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6308 | if (*out == NULL) goto failed; |
| 6309 | return 0; |
| 6310 | } |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 6311 | isinstance = PyObject_IsInstance(obj, (PyObject*)NamedExpr_type); |
| 6312 | if (isinstance == -1) { |
| 6313 | return 1; |
| 6314 | } |
| 6315 | if (isinstance) { |
| 6316 | expr_ty target; |
| 6317 | expr_ty value; |
| 6318 | |
| 6319 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 6320 | return 1; |
| 6321 | } |
| 6322 | if (tmp == NULL) { |
| 6323 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); |
| 6324 | return 1; |
| 6325 | } |
| 6326 | else { |
| 6327 | int res; |
| 6328 | res = obj2ast_expr(tmp, &target, arena); |
| 6329 | if (res != 0) goto failed; |
| 6330 | Py_CLEAR(tmp); |
| 6331 | } |
| 6332 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6333 | return 1; |
| 6334 | } |
| 6335 | if (tmp == NULL) { |
| 6336 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); |
| 6337 | return 1; |
| 6338 | } |
| 6339 | else { |
| 6340 | int res; |
| 6341 | res = obj2ast_expr(tmp, &value, arena); |
| 6342 | if (res != 0) goto failed; |
| 6343 | Py_CLEAR(tmp); |
| 6344 | } |
| 6345 | *out = NamedExpr(target, value, lineno, col_offset, end_lineno, |
| 6346 | end_col_offset, arena); |
| 6347 | if (*out == NULL) goto failed; |
| 6348 | return 0; |
| 6349 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6350 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 6351 | if (isinstance == -1) { |
| 6352 | return 1; |
| 6353 | } |
| 6354 | if (isinstance) { |
| 6355 | expr_ty left; |
| 6356 | operator_ty op; |
| 6357 | expr_ty right; |
| 6358 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6359 | if (_PyObject_LookupAttrId(obj, &PyId_left, &tmp) < 0) { |
| 6360 | return 1; |
| 6361 | } |
| 6362 | if (tmp == NULL) { |
| 6363 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 6364 | return 1; |
| 6365 | } |
| 6366 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6367 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6368 | res = obj2ast_expr(tmp, &left, arena); |
| 6369 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6370 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6371 | } |
| 6372 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6373 | return 1; |
| 6374 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6375 | if (tmp == NULL) { |
| 6376 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 6377 | return 1; |
| 6378 | } |
| 6379 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6380 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6381 | res = obj2ast_operator(tmp, &op, arena); |
| 6382 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6383 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6384 | } |
| 6385 | if (_PyObject_LookupAttrId(obj, &PyId_right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6386 | return 1; |
| 6387 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6388 | if (tmp == NULL) { |
| 6389 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 6390 | return 1; |
| 6391 | } |
| 6392 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6393 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6394 | res = obj2ast_expr(tmp, &right, arena); |
| 6395 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6396 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6397 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6398 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 6399 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6400 | if (*out == NULL) goto failed; |
| 6401 | return 0; |
| 6402 | } |
| 6403 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 6404 | if (isinstance == -1) { |
| 6405 | return 1; |
| 6406 | } |
| 6407 | if (isinstance) { |
| 6408 | unaryop_ty op; |
| 6409 | expr_ty operand; |
| 6410 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6411 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
| 6412 | return 1; |
| 6413 | } |
| 6414 | if (tmp == NULL) { |
| 6415 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 6416 | return 1; |
| 6417 | } |
| 6418 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6419 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6420 | res = obj2ast_unaryop(tmp, &op, arena); |
| 6421 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6422 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6423 | } |
| 6424 | if (_PyObject_LookupAttrId(obj, &PyId_operand, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6425 | return 1; |
| 6426 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6427 | if (tmp == NULL) { |
| 6428 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 6429 | return 1; |
| 6430 | } |
| 6431 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6432 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6433 | res = obj2ast_expr(tmp, &operand, arena); |
| 6434 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6435 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6436 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6437 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 6438 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6439 | if (*out == NULL) goto failed; |
| 6440 | return 0; |
| 6441 | } |
| 6442 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 6443 | if (isinstance == -1) { |
| 6444 | return 1; |
| 6445 | } |
| 6446 | if (isinstance) { |
| 6447 | arguments_ty args; |
| 6448 | expr_ty body; |
| 6449 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6450 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
| 6451 | return 1; |
| 6452 | } |
| 6453 | if (tmp == NULL) { |
| 6454 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 6455 | return 1; |
| 6456 | } |
| 6457 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6458 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6459 | res = obj2ast_arguments(tmp, &args, arena); |
| 6460 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6461 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6462 | } |
| 6463 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6464 | return 1; |
| 6465 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6466 | if (tmp == NULL) { |
| 6467 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 6468 | return 1; |
| 6469 | } |
| 6470 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6471 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6472 | res = obj2ast_expr(tmp, &body, arena); |
| 6473 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6474 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6475 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6476 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 6477 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6478 | if (*out == NULL) goto failed; |
| 6479 | return 0; |
| 6480 | } |
| 6481 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 6482 | if (isinstance == -1) { |
| 6483 | return 1; |
| 6484 | } |
| 6485 | if (isinstance) { |
| 6486 | expr_ty test; |
| 6487 | expr_ty body; |
| 6488 | expr_ty orelse; |
| 6489 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6490 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 6491 | return 1; |
| 6492 | } |
| 6493 | if (tmp == NULL) { |
| 6494 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 6495 | return 1; |
| 6496 | } |
| 6497 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6498 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6499 | res = obj2ast_expr(tmp, &test, arena); |
| 6500 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6501 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6502 | } |
| 6503 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6504 | return 1; |
| 6505 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6506 | if (tmp == NULL) { |
| 6507 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 6508 | return 1; |
| 6509 | } |
| 6510 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6511 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6512 | res = obj2ast_expr(tmp, &body, arena); |
| 6513 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6514 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6515 | } |
| 6516 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6517 | return 1; |
| 6518 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6519 | if (tmp == NULL) { |
| 6520 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 6521 | return 1; |
| 6522 | } |
| 6523 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6524 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6525 | res = obj2ast_expr(tmp, &orelse, arena); |
| 6526 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6527 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6528 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6529 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 6530 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6531 | if (*out == NULL) goto failed; |
| 6532 | return 0; |
| 6533 | } |
| 6534 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 6535 | if (isinstance == -1) { |
| 6536 | return 1; |
| 6537 | } |
| 6538 | if (isinstance) { |
| 6539 | asdl_seq* keys; |
| 6540 | asdl_seq* values; |
| 6541 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6542 | if (_PyObject_LookupAttrId(obj, &PyId_keys, &tmp) < 0) { |
| 6543 | return 1; |
| 6544 | } |
| 6545 | if (tmp == NULL) { |
| 6546 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 6547 | return 1; |
| 6548 | } |
| 6549 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6550 | int res; |
| 6551 | Py_ssize_t len; |
| 6552 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6553 | if (!PyList_Check(tmp)) { |
| 6554 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6555 | goto failed; |
| 6556 | } |
| 6557 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6558 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6559 | if (keys == NULL) goto failed; |
| 6560 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6561 | expr_ty val; |
| 6562 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6563 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6564 | if (len != PyList_GET_SIZE(tmp)) { |
| 6565 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 6566 | goto failed; |
| 6567 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6568 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6569 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6570 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6571 | } |
| 6572 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6573 | return 1; |
| 6574 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6575 | if (tmp == NULL) { |
| 6576 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 6577 | return 1; |
| 6578 | } |
| 6579 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6580 | int res; |
| 6581 | Py_ssize_t len; |
| 6582 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6583 | if (!PyList_Check(tmp)) { |
| 6584 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6585 | goto failed; |
| 6586 | } |
| 6587 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6588 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6589 | if (values == NULL) goto failed; |
| 6590 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6591 | expr_ty val; |
| 6592 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6593 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6594 | if (len != PyList_GET_SIZE(tmp)) { |
| 6595 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 6596 | goto failed; |
| 6597 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6598 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6599 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6600 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6601 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6602 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 6603 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6604 | if (*out == NULL) goto failed; |
| 6605 | return 0; |
| 6606 | } |
| 6607 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 6608 | if (isinstance == -1) { |
| 6609 | return 1; |
| 6610 | } |
| 6611 | if (isinstance) { |
| 6612 | asdl_seq* elts; |
| 6613 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6614 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 6615 | return 1; |
| 6616 | } |
| 6617 | if (tmp == NULL) { |
| 6618 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 6619 | return 1; |
| 6620 | } |
| 6621 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6622 | int res; |
| 6623 | Py_ssize_t len; |
| 6624 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6625 | if (!PyList_Check(tmp)) { |
| 6626 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6627 | goto failed; |
| 6628 | } |
| 6629 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6630 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6631 | if (elts == NULL) goto failed; |
| 6632 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6633 | expr_ty val; |
| 6634 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6635 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6636 | if (len != PyList_GET_SIZE(tmp)) { |
| 6637 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 6638 | goto failed; |
| 6639 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6640 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6641 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6642 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6643 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6644 | *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6645 | if (*out == NULL) goto failed; |
| 6646 | return 0; |
| 6647 | } |
| 6648 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 6649 | if (isinstance == -1) { |
| 6650 | return 1; |
| 6651 | } |
| 6652 | if (isinstance) { |
| 6653 | expr_ty elt; |
| 6654 | asdl_seq* generators; |
| 6655 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6656 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6657 | return 1; |
| 6658 | } |
| 6659 | if (tmp == NULL) { |
| 6660 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 6661 | return 1; |
| 6662 | } |
| 6663 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6664 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6665 | res = obj2ast_expr(tmp, &elt, arena); |
| 6666 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6667 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6668 | } |
| 6669 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6670 | return 1; |
| 6671 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6672 | if (tmp == NULL) { |
| 6673 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 6674 | return 1; |
| 6675 | } |
| 6676 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6677 | int res; |
| 6678 | Py_ssize_t len; |
| 6679 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6680 | if (!PyList_Check(tmp)) { |
| 6681 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6682 | goto failed; |
| 6683 | } |
| 6684 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6685 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6686 | if (generators == NULL) goto failed; |
| 6687 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6688 | comprehension_ty val; |
| 6689 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6690 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6691 | if (len != PyList_GET_SIZE(tmp)) { |
| 6692 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 6693 | goto failed; |
| 6694 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6695 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6696 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6697 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6698 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6699 | *out = ListComp(elt, generators, lineno, col_offset, end_lineno, |
| 6700 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6701 | if (*out == NULL) goto failed; |
| 6702 | return 0; |
| 6703 | } |
| 6704 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 6705 | if (isinstance == -1) { |
| 6706 | return 1; |
| 6707 | } |
| 6708 | if (isinstance) { |
| 6709 | expr_ty elt; |
| 6710 | asdl_seq* generators; |
| 6711 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6712 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6713 | return 1; |
| 6714 | } |
| 6715 | if (tmp == NULL) { |
| 6716 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 6717 | return 1; |
| 6718 | } |
| 6719 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6720 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6721 | res = obj2ast_expr(tmp, &elt, arena); |
| 6722 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6723 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6724 | } |
| 6725 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6726 | return 1; |
| 6727 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6728 | if (tmp == NULL) { |
| 6729 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 6730 | return 1; |
| 6731 | } |
| 6732 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6733 | int res; |
| 6734 | Py_ssize_t len; |
| 6735 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6736 | if (!PyList_Check(tmp)) { |
| 6737 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6738 | goto failed; |
| 6739 | } |
| 6740 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6741 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6742 | if (generators == NULL) goto failed; |
| 6743 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6744 | comprehension_ty val; |
| 6745 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6746 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6747 | if (len != PyList_GET_SIZE(tmp)) { |
| 6748 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 6749 | goto failed; |
| 6750 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6751 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6752 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6753 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6754 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6755 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 6756 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6757 | if (*out == NULL) goto failed; |
| 6758 | return 0; |
| 6759 | } |
| 6760 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 6761 | if (isinstance == -1) { |
| 6762 | return 1; |
| 6763 | } |
| 6764 | if (isinstance) { |
| 6765 | expr_ty key; |
| 6766 | expr_ty value; |
| 6767 | asdl_seq* generators; |
| 6768 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6769 | if (_PyObject_LookupAttrId(obj, &PyId_key, &tmp) < 0) { |
| 6770 | return 1; |
| 6771 | } |
| 6772 | if (tmp == NULL) { |
| 6773 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 6774 | return 1; |
| 6775 | } |
| 6776 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6777 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6778 | res = obj2ast_expr(tmp, &key, arena); |
| 6779 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6780 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6781 | } |
| 6782 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6783 | return 1; |
| 6784 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6785 | if (tmp == NULL) { |
| 6786 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 6787 | return 1; |
| 6788 | } |
| 6789 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6790 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6791 | res = obj2ast_expr(tmp, &value, arena); |
| 6792 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6793 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6794 | } |
| 6795 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6796 | return 1; |
| 6797 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6798 | if (tmp == NULL) { |
| 6799 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 6800 | return 1; |
| 6801 | } |
| 6802 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6803 | int res; |
| 6804 | Py_ssize_t len; |
| 6805 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6806 | if (!PyList_Check(tmp)) { |
| 6807 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6808 | goto failed; |
| 6809 | } |
| 6810 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6811 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6812 | if (generators == NULL) goto failed; |
| 6813 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6814 | comprehension_ty val; |
| 6815 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6816 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6817 | if (len != PyList_GET_SIZE(tmp)) { |
| 6818 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 6819 | goto failed; |
| 6820 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6821 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6822 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6823 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6824 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6825 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 6826 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6827 | if (*out == NULL) goto failed; |
| 6828 | return 0; |
| 6829 | } |
| 6830 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 6831 | if (isinstance == -1) { |
| 6832 | return 1; |
| 6833 | } |
| 6834 | if (isinstance) { |
| 6835 | expr_ty elt; |
| 6836 | asdl_seq* generators; |
| 6837 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6838 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6839 | return 1; |
| 6840 | } |
| 6841 | if (tmp == NULL) { |
| 6842 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 6843 | return 1; |
| 6844 | } |
| 6845 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6846 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6847 | res = obj2ast_expr(tmp, &elt, arena); |
| 6848 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6849 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6850 | } |
| 6851 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6852 | return 1; |
| 6853 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6854 | if (tmp == NULL) { |
| 6855 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 6856 | return 1; |
| 6857 | } |
| 6858 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6859 | int res; |
| 6860 | Py_ssize_t len; |
| 6861 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6862 | if (!PyList_Check(tmp)) { |
| 6863 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6864 | goto failed; |
| 6865 | } |
| 6866 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6867 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6868 | if (generators == NULL) goto failed; |
| 6869 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6870 | comprehension_ty val; |
| 6871 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6872 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6873 | if (len != PyList_GET_SIZE(tmp)) { |
| 6874 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 6875 | goto failed; |
| 6876 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6877 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6878 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6879 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6880 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6881 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 6882 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6883 | if (*out == NULL) goto failed; |
| 6884 | return 0; |
| 6885 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6886 | isinstance = PyObject_IsInstance(obj, (PyObject*)Await_type); |
| 6887 | if (isinstance == -1) { |
| 6888 | return 1; |
| 6889 | } |
| 6890 | if (isinstance) { |
| 6891 | expr_ty value; |
| 6892 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6893 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6894 | return 1; |
| 6895 | } |
| 6896 | if (tmp == NULL) { |
| 6897 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 6898 | return 1; |
| 6899 | } |
| 6900 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6901 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6902 | res = obj2ast_expr(tmp, &value, arena); |
| 6903 | if (res != 0) goto failed; |
| 6904 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6905 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6906 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6907 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6908 | if (*out == NULL) goto failed; |
| 6909 | return 0; |
| 6910 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6911 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 6912 | if (isinstance == -1) { |
| 6913 | return 1; |
| 6914 | } |
| 6915 | if (isinstance) { |
| 6916 | expr_ty value; |
| 6917 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6918 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6919 | return 1; |
| 6920 | } |
| 6921 | if (tmp == NULL || tmp == Py_None) { |
| 6922 | Py_CLEAR(tmp); |
| 6923 | value = NULL; |
| 6924 | } |
| 6925 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6926 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6927 | res = obj2ast_expr(tmp, &value, arena); |
| 6928 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6929 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6930 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6931 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6932 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6933 | if (*out == NULL) goto failed; |
| 6934 | return 0; |
| 6935 | } |
| 6936 | isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); |
| 6937 | if (isinstance == -1) { |
| 6938 | return 1; |
| 6939 | } |
| 6940 | if (isinstance) { |
| 6941 | expr_ty value; |
| 6942 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6943 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6944 | return 1; |
| 6945 | } |
| 6946 | if (tmp == NULL) { |
| 6947 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 6948 | return 1; |
| 6949 | } |
| 6950 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6951 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6952 | res = obj2ast_expr(tmp, &value, arena); |
| 6953 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6954 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6955 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6956 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6957 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6958 | if (*out == NULL) goto failed; |
| 6959 | return 0; |
| 6960 | } |
| 6961 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 6962 | if (isinstance == -1) { |
| 6963 | return 1; |
| 6964 | } |
| 6965 | if (isinstance) { |
| 6966 | expr_ty left; |
| 6967 | asdl_int_seq* ops; |
| 6968 | asdl_seq* comparators; |
| 6969 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6970 | if (_PyObject_LookupAttrId(obj, &PyId_left, &tmp) < 0) { |
| 6971 | return 1; |
| 6972 | } |
| 6973 | if (tmp == NULL) { |
| 6974 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 6975 | return 1; |
| 6976 | } |
| 6977 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6978 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6979 | res = obj2ast_expr(tmp, &left, arena); |
| 6980 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6981 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6982 | } |
| 6983 | if (_PyObject_LookupAttrId(obj, &PyId_ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6984 | return 1; |
| 6985 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6986 | if (tmp == NULL) { |
| 6987 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 6988 | return 1; |
| 6989 | } |
| 6990 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6991 | int res; |
| 6992 | Py_ssize_t len; |
| 6993 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6994 | if (!PyList_Check(tmp)) { |
| 6995 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6996 | goto failed; |
| 6997 | } |
| 6998 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6999 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7000 | if (ops == NULL) goto failed; |
| 7001 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7002 | cmpop_ty val; |
| 7003 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7004 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7005 | if (len != PyList_GET_SIZE(tmp)) { |
| 7006 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 7007 | goto failed; |
| 7008 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7009 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7010 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7011 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7012 | } |
| 7013 | if (_PyObject_LookupAttrId(obj, &PyId_comparators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7014 | return 1; |
| 7015 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7016 | if (tmp == NULL) { |
| 7017 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 7018 | return 1; |
| 7019 | } |
| 7020 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7021 | int res; |
| 7022 | Py_ssize_t len; |
| 7023 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7024 | if (!PyList_Check(tmp)) { |
| 7025 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7026 | goto failed; |
| 7027 | } |
| 7028 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7029 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7030 | if (comparators == NULL) goto failed; |
| 7031 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7032 | expr_ty val; |
| 7033 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7034 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7035 | if (len != PyList_GET_SIZE(tmp)) { |
| 7036 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 7037 | goto failed; |
| 7038 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7039 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7040 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7041 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7042 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7043 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 7044 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7045 | if (*out == NULL) goto failed; |
| 7046 | return 0; |
| 7047 | } |
| 7048 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 7049 | if (isinstance == -1) { |
| 7050 | return 1; |
| 7051 | } |
| 7052 | if (isinstance) { |
| 7053 | expr_ty func; |
| 7054 | asdl_seq* args; |
| 7055 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7056 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7057 | if (_PyObject_LookupAttrId(obj, &PyId_func, &tmp) < 0) { |
| 7058 | return 1; |
| 7059 | } |
| 7060 | if (tmp == NULL) { |
| 7061 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 7062 | return 1; |
| 7063 | } |
| 7064 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7065 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7066 | res = obj2ast_expr(tmp, &func, arena); |
| 7067 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7068 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7069 | } |
| 7070 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7071 | return 1; |
| 7072 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7073 | if (tmp == NULL) { |
| 7074 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 7075 | return 1; |
| 7076 | } |
| 7077 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7078 | int res; |
| 7079 | Py_ssize_t len; |
| 7080 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7081 | if (!PyList_Check(tmp)) { |
| 7082 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7083 | goto failed; |
| 7084 | } |
| 7085 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7086 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7087 | if (args == NULL) goto failed; |
| 7088 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7089 | expr_ty val; |
| 7090 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7091 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7092 | if (len != PyList_GET_SIZE(tmp)) { |
| 7093 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 7094 | goto failed; |
| 7095 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7096 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7097 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7098 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7099 | } |
| 7100 | if (_PyObject_LookupAttrId(obj, &PyId_keywords, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7101 | return 1; |
| 7102 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7103 | if (tmp == NULL) { |
| 7104 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 7105 | return 1; |
| 7106 | } |
| 7107 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7108 | int res; |
| 7109 | Py_ssize_t len; |
| 7110 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7111 | if (!PyList_Check(tmp)) { |
| 7112 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7113 | goto failed; |
| 7114 | } |
| 7115 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7116 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7117 | if (keywords == NULL) goto failed; |
| 7118 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7119 | keyword_ty val; |
| 7120 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7121 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7122 | if (len != PyList_GET_SIZE(tmp)) { |
| 7123 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 7124 | goto failed; |
| 7125 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7126 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7127 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7128 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7129 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7130 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 7131 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7132 | if (*out == NULL) goto failed; |
| 7133 | return 0; |
| 7134 | } |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7135 | isinstance = PyObject_IsInstance(obj, (PyObject*)FormattedValue_type); |
| 7136 | if (isinstance == -1) { |
| 7137 | return 1; |
| 7138 | } |
| 7139 | if (isinstance) { |
| 7140 | expr_ty value; |
| 7141 | int conversion; |
| 7142 | expr_ty format_spec; |
| 7143 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7144 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7145 | return 1; |
| 7146 | } |
| 7147 | if (tmp == NULL) { |
| 7148 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 7149 | return 1; |
| 7150 | } |
| 7151 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7152 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7153 | res = obj2ast_expr(tmp, &value, arena); |
| 7154 | if (res != 0) goto failed; |
| 7155 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7156 | } |
| 7157 | if (_PyObject_LookupAttrId(obj, &PyId_conversion, &tmp) < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7158 | return 1; |
| 7159 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7160 | if (tmp == NULL || tmp == Py_None) { |
| 7161 | Py_CLEAR(tmp); |
| 7162 | conversion = 0; |
| 7163 | } |
| 7164 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7165 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7166 | res = obj2ast_int(tmp, &conversion, arena); |
| 7167 | if (res != 0) goto failed; |
| 7168 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7169 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7170 | if (_PyObject_LookupAttrId(obj, &PyId_format_spec, &tmp) < 0) { |
| 7171 | return 1; |
| 7172 | } |
| 7173 | if (tmp == NULL || tmp == Py_None) { |
| 7174 | Py_CLEAR(tmp); |
| 7175 | format_spec = NULL; |
| 7176 | } |
| 7177 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7178 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7179 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 7180 | if (res != 0) goto failed; |
| 7181 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7182 | } |
| 7183 | *out = FormattedValue(value, conversion, format_spec, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7184 | col_offset, end_lineno, end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7185 | if (*out == NULL) goto failed; |
| 7186 | return 0; |
| 7187 | } |
| 7188 | isinstance = PyObject_IsInstance(obj, (PyObject*)JoinedStr_type); |
| 7189 | if (isinstance == -1) { |
| 7190 | return 1; |
| 7191 | } |
| 7192 | if (isinstance) { |
| 7193 | asdl_seq* values; |
| 7194 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7195 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
| 7196 | return 1; |
| 7197 | } |
| 7198 | if (tmp == NULL) { |
| 7199 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 7200 | return 1; |
| 7201 | } |
| 7202 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7203 | int res; |
| 7204 | Py_ssize_t len; |
| 7205 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7206 | if (!PyList_Check(tmp)) { |
| 7207 | PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7208 | goto failed; |
| 7209 | } |
| 7210 | len = PyList_GET_SIZE(tmp); |
| 7211 | values = _Py_asdl_seq_new(len, arena); |
| 7212 | if (values == NULL) goto failed; |
| 7213 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7214 | expr_ty val; |
| 7215 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7216 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 7217 | if (len != PyList_GET_SIZE(tmp)) { |
| 7218 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 7219 | goto failed; |
| 7220 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7221 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7222 | } |
| 7223 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7224 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7225 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 7226 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7227 | if (*out == NULL) goto failed; |
| 7228 | return 0; |
| 7229 | } |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7230 | isinstance = PyObject_IsInstance(obj, (PyObject*)Constant_type); |
| 7231 | if (isinstance == -1) { |
| 7232 | return 1; |
| 7233 | } |
| 7234 | if (isinstance) { |
| 7235 | constant value; |
| 7236 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7237 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7238 | return 1; |
| 7239 | } |
| 7240 | if (tmp == NULL) { |
| 7241 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 7242 | return 1; |
| 7243 | } |
| 7244 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7245 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7246 | res = obj2ast_constant(tmp, &value, arena); |
| 7247 | if (res != 0) goto failed; |
| 7248 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7249 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7250 | *out = Constant(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7251 | arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7252 | if (*out == NULL) goto failed; |
| 7253 | return 0; |
| 7254 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7255 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 7256 | if (isinstance == -1) { |
| 7257 | return 1; |
| 7258 | } |
| 7259 | if (isinstance) { |
| 7260 | expr_ty value; |
| 7261 | identifier attr; |
| 7262 | expr_context_ty ctx; |
| 7263 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7264 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7265 | return 1; |
| 7266 | } |
| 7267 | if (tmp == NULL) { |
| 7268 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 7269 | return 1; |
| 7270 | } |
| 7271 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7272 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7273 | res = obj2ast_expr(tmp, &value, arena); |
| 7274 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7275 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7276 | } |
| 7277 | if (_PyObject_LookupAttrId(obj, &PyId_attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7278 | return 1; |
| 7279 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7280 | if (tmp == NULL) { |
| 7281 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 7282 | return 1; |
| 7283 | } |
| 7284 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7285 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7286 | res = obj2ast_identifier(tmp, &attr, arena); |
| 7287 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7288 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7289 | } |
| 7290 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7291 | return 1; |
| 7292 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7293 | if (tmp == NULL) { |
| 7294 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 7295 | return 1; |
| 7296 | } |
| 7297 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7298 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7299 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7300 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7301 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7302 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7303 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 7304 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7305 | if (*out == NULL) goto failed; |
| 7306 | return 0; |
| 7307 | } |
| 7308 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 7309 | if (isinstance == -1) { |
| 7310 | return 1; |
| 7311 | } |
| 7312 | if (isinstance) { |
| 7313 | expr_ty value; |
| 7314 | slice_ty slice; |
| 7315 | expr_context_ty ctx; |
| 7316 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7317 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7318 | return 1; |
| 7319 | } |
| 7320 | if (tmp == NULL) { |
| 7321 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 7322 | return 1; |
| 7323 | } |
| 7324 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7325 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7326 | res = obj2ast_expr(tmp, &value, arena); |
| 7327 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7328 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7329 | } |
| 7330 | if (_PyObject_LookupAttrId(obj, &PyId_slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7331 | return 1; |
| 7332 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7333 | if (tmp == NULL) { |
| 7334 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 7335 | return 1; |
| 7336 | } |
| 7337 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7338 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7339 | res = obj2ast_slice(tmp, &slice, arena); |
| 7340 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7341 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7342 | } |
| 7343 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7344 | return 1; |
| 7345 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7346 | if (tmp == NULL) { |
| 7347 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 7348 | return 1; |
| 7349 | } |
| 7350 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7351 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7352 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7353 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7354 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7355 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7356 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 7357 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7358 | if (*out == NULL) goto failed; |
| 7359 | return 0; |
| 7360 | } |
| 7361 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 7362 | if (isinstance == -1) { |
| 7363 | return 1; |
| 7364 | } |
| 7365 | if (isinstance) { |
| 7366 | expr_ty value; |
| 7367 | expr_context_ty ctx; |
| 7368 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7369 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7370 | return 1; |
| 7371 | } |
| 7372 | if (tmp == NULL) { |
| 7373 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 7374 | return 1; |
| 7375 | } |
| 7376 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7377 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7378 | res = obj2ast_expr(tmp, &value, arena); |
| 7379 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7380 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7381 | } |
| 7382 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7383 | return 1; |
| 7384 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7385 | if (tmp == NULL) { |
| 7386 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 7387 | return 1; |
| 7388 | } |
| 7389 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7390 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7391 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7392 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7393 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7394 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7395 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 7396 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7397 | if (*out == NULL) goto failed; |
| 7398 | return 0; |
| 7399 | } |
| 7400 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 7401 | if (isinstance == -1) { |
| 7402 | return 1; |
| 7403 | } |
| 7404 | if (isinstance) { |
| 7405 | identifier id; |
| 7406 | expr_context_ty ctx; |
| 7407 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7408 | if (_PyObject_LookupAttrId(obj, &PyId_id, &tmp) < 0) { |
| 7409 | return 1; |
| 7410 | } |
| 7411 | if (tmp == NULL) { |
| 7412 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 7413 | return 1; |
| 7414 | } |
| 7415 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7416 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7417 | res = obj2ast_identifier(tmp, &id, arena); |
| 7418 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7419 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7420 | } |
| 7421 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7422 | return 1; |
| 7423 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7424 | if (tmp == NULL) { |
| 7425 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 7426 | return 1; |
| 7427 | } |
| 7428 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7429 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7430 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7431 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7432 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7433 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7434 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7435 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7436 | if (*out == NULL) goto failed; |
| 7437 | return 0; |
| 7438 | } |
| 7439 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 7440 | if (isinstance == -1) { |
| 7441 | return 1; |
| 7442 | } |
| 7443 | if (isinstance) { |
| 7444 | asdl_seq* elts; |
| 7445 | expr_context_ty ctx; |
| 7446 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7447 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 7448 | return 1; |
| 7449 | } |
| 7450 | if (tmp == NULL) { |
| 7451 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 7452 | return 1; |
| 7453 | } |
| 7454 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7455 | int res; |
| 7456 | Py_ssize_t len; |
| 7457 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7458 | if (!PyList_Check(tmp)) { |
| 7459 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7460 | goto failed; |
| 7461 | } |
| 7462 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7463 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7464 | if (elts == NULL) goto failed; |
| 7465 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7466 | expr_ty val; |
| 7467 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7468 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7469 | if (len != PyList_GET_SIZE(tmp)) { |
| 7470 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 7471 | goto failed; |
| 7472 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7473 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7474 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7475 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7476 | } |
| 7477 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7478 | return 1; |
| 7479 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7480 | if (tmp == NULL) { |
| 7481 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 7482 | return 1; |
| 7483 | } |
| 7484 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7485 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7486 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7487 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7488 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7489 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7490 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7491 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7492 | if (*out == NULL) goto failed; |
| 7493 | return 0; |
| 7494 | } |
| 7495 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 7496 | if (isinstance == -1) { |
| 7497 | return 1; |
| 7498 | } |
| 7499 | if (isinstance) { |
| 7500 | asdl_seq* elts; |
| 7501 | expr_context_ty ctx; |
| 7502 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7503 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 7504 | return 1; |
| 7505 | } |
| 7506 | if (tmp == NULL) { |
| 7507 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 7508 | return 1; |
| 7509 | } |
| 7510 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7511 | int res; |
| 7512 | Py_ssize_t len; |
| 7513 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7514 | if (!PyList_Check(tmp)) { |
| 7515 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7516 | goto failed; |
| 7517 | } |
| 7518 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7519 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7520 | if (elts == NULL) goto failed; |
| 7521 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7522 | expr_ty val; |
| 7523 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7524 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7525 | if (len != PyList_GET_SIZE(tmp)) { |
| 7526 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 7527 | goto failed; |
| 7528 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7529 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7530 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7531 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7532 | } |
| 7533 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7534 | return 1; |
| 7535 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7536 | if (tmp == NULL) { |
| 7537 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 7538 | return 1; |
| 7539 | } |
| 7540 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7541 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7542 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7543 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7544 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7545 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7546 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7547 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7548 | if (*out == NULL) goto failed; |
| 7549 | return 0; |
| 7550 | } |
| 7551 | |
| 7552 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 7553 | failed: |
| 7554 | Py_XDECREF(tmp); |
| 7555 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7556 | } |
| 7557 | |
| 7558 | int |
| 7559 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 7560 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7561 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7562 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7563 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 7564 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7565 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7566 | } |
| 7567 | if (isinstance) { |
| 7568 | *out = Load; |
| 7569 | return 0; |
| 7570 | } |
| 7571 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 7572 | if (isinstance == -1) { |
| 7573 | return 1; |
| 7574 | } |
| 7575 | if (isinstance) { |
| 7576 | *out = Store; |
| 7577 | return 0; |
| 7578 | } |
| 7579 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 7580 | if (isinstance == -1) { |
| 7581 | return 1; |
| 7582 | } |
| 7583 | if (isinstance) { |
| 7584 | *out = Del; |
| 7585 | return 0; |
| 7586 | } |
| 7587 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 7588 | if (isinstance == -1) { |
| 7589 | return 1; |
| 7590 | } |
| 7591 | if (isinstance) { |
| 7592 | *out = AugLoad; |
| 7593 | return 0; |
| 7594 | } |
| 7595 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 7596 | if (isinstance == -1) { |
| 7597 | return 1; |
| 7598 | } |
| 7599 | if (isinstance) { |
| 7600 | *out = AugStore; |
| 7601 | return 0; |
| 7602 | } |
| 7603 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 7604 | if (isinstance == -1) { |
| 7605 | return 1; |
| 7606 | } |
| 7607 | if (isinstance) { |
| 7608 | *out = Param; |
| 7609 | return 0; |
| 7610 | } |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7611 | isinstance = PyObject_IsInstance(obj, (PyObject *)NamedStore_type); |
| 7612 | if (isinstance == -1) { |
| 7613 | return 1; |
| 7614 | } |
| 7615 | if (isinstance) { |
| 7616 | *out = NamedStore; |
| 7617 | return 0; |
| 7618 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7619 | |
| 7620 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 7621 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7622 | } |
| 7623 | |
| 7624 | int |
| 7625 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 7626 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7627 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7628 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7629 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7630 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7631 | if (obj == Py_None) { |
| 7632 | *out = NULL; |
| 7633 | return 0; |
| 7634 | } |
| 7635 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 7636 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7637 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7638 | } |
| 7639 | if (isinstance) { |
| 7640 | expr_ty lower; |
| 7641 | expr_ty upper; |
| 7642 | expr_ty step; |
| 7643 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7644 | if (_PyObject_LookupAttrId(obj, &PyId_lower, &tmp) < 0) { |
| 7645 | return 1; |
| 7646 | } |
| 7647 | if (tmp == NULL || tmp == Py_None) { |
| 7648 | Py_CLEAR(tmp); |
| 7649 | lower = NULL; |
| 7650 | } |
| 7651 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7652 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7653 | res = obj2ast_expr(tmp, &lower, arena); |
| 7654 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7655 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7656 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7657 | if (_PyObject_LookupAttrId(obj, &PyId_upper, &tmp) < 0) { |
| 7658 | return 1; |
| 7659 | } |
| 7660 | if (tmp == NULL || tmp == Py_None) { |
| 7661 | Py_CLEAR(tmp); |
| 7662 | upper = NULL; |
| 7663 | } |
| 7664 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7665 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7666 | res = obj2ast_expr(tmp, &upper, arena); |
| 7667 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7668 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7669 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7670 | if (_PyObject_LookupAttrId(obj, &PyId_step, &tmp) < 0) { |
| 7671 | return 1; |
| 7672 | } |
| 7673 | if (tmp == NULL || tmp == Py_None) { |
| 7674 | Py_CLEAR(tmp); |
| 7675 | step = NULL; |
| 7676 | } |
| 7677 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7678 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7679 | res = obj2ast_expr(tmp, &step, arena); |
| 7680 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7681 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7682 | } |
| 7683 | *out = Slice(lower, upper, step, arena); |
| 7684 | if (*out == NULL) goto failed; |
| 7685 | return 0; |
| 7686 | } |
| 7687 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 7688 | if (isinstance == -1) { |
| 7689 | return 1; |
| 7690 | } |
| 7691 | if (isinstance) { |
| 7692 | asdl_seq* dims; |
| 7693 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7694 | if (_PyObject_LookupAttrId(obj, &PyId_dims, &tmp) < 0) { |
| 7695 | return 1; |
| 7696 | } |
| 7697 | if (tmp == NULL) { |
| 7698 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 7699 | return 1; |
| 7700 | } |
| 7701 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7702 | int res; |
| 7703 | Py_ssize_t len; |
| 7704 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7705 | if (!PyList_Check(tmp)) { |
| 7706 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7707 | goto failed; |
| 7708 | } |
| 7709 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7710 | dims = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7711 | if (dims == NULL) goto failed; |
| 7712 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7713 | slice_ty val; |
| 7714 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7715 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7716 | if (len != PyList_GET_SIZE(tmp)) { |
| 7717 | PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration"); |
| 7718 | goto failed; |
| 7719 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7720 | asdl_seq_SET(dims, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7721 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7722 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7723 | } |
| 7724 | *out = ExtSlice(dims, arena); |
| 7725 | if (*out == NULL) goto failed; |
| 7726 | return 0; |
| 7727 | } |
| 7728 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 7729 | if (isinstance == -1) { |
| 7730 | return 1; |
| 7731 | } |
| 7732 | if (isinstance) { |
| 7733 | expr_ty value; |
| 7734 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7735 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7736 | return 1; |
| 7737 | } |
| 7738 | if (tmp == NULL) { |
| 7739 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 7740 | return 1; |
| 7741 | } |
| 7742 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7743 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7744 | res = obj2ast_expr(tmp, &value, arena); |
| 7745 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7746 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7747 | } |
| 7748 | *out = Index(value, arena); |
| 7749 | if (*out == NULL) goto failed; |
| 7750 | return 0; |
| 7751 | } |
| 7752 | |
| 7753 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 7754 | failed: |
| 7755 | Py_XDECREF(tmp); |
| 7756 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7757 | } |
| 7758 | |
| 7759 | int |
| 7760 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 7761 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7762 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7763 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7764 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 7765 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7766 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7767 | } |
| 7768 | if (isinstance) { |
| 7769 | *out = And; |
| 7770 | return 0; |
| 7771 | } |
| 7772 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 7773 | if (isinstance == -1) { |
| 7774 | return 1; |
| 7775 | } |
| 7776 | if (isinstance) { |
| 7777 | *out = Or; |
| 7778 | return 0; |
| 7779 | } |
| 7780 | |
| 7781 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 7782 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7783 | } |
| 7784 | |
| 7785 | int |
| 7786 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 7787 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7788 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7789 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7790 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 7791 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7792 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7793 | } |
| 7794 | if (isinstance) { |
| 7795 | *out = Add; |
| 7796 | return 0; |
| 7797 | } |
| 7798 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 7799 | if (isinstance == -1) { |
| 7800 | return 1; |
| 7801 | } |
| 7802 | if (isinstance) { |
| 7803 | *out = Sub; |
| 7804 | return 0; |
| 7805 | } |
| 7806 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 7807 | if (isinstance == -1) { |
| 7808 | return 1; |
| 7809 | } |
| 7810 | if (isinstance) { |
| 7811 | *out = Mult; |
| 7812 | return 0; |
| 7813 | } |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 7814 | isinstance = PyObject_IsInstance(obj, (PyObject *)MatMult_type); |
| 7815 | if (isinstance == -1) { |
| 7816 | return 1; |
| 7817 | } |
| 7818 | if (isinstance) { |
| 7819 | *out = MatMult; |
| 7820 | return 0; |
| 7821 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7822 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 7823 | if (isinstance == -1) { |
| 7824 | return 1; |
| 7825 | } |
| 7826 | if (isinstance) { |
| 7827 | *out = Div; |
| 7828 | return 0; |
| 7829 | } |
| 7830 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 7831 | if (isinstance == -1) { |
| 7832 | return 1; |
| 7833 | } |
| 7834 | if (isinstance) { |
| 7835 | *out = Mod; |
| 7836 | return 0; |
| 7837 | } |
| 7838 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 7839 | if (isinstance == -1) { |
| 7840 | return 1; |
| 7841 | } |
| 7842 | if (isinstance) { |
| 7843 | *out = Pow; |
| 7844 | return 0; |
| 7845 | } |
| 7846 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 7847 | if (isinstance == -1) { |
| 7848 | return 1; |
| 7849 | } |
| 7850 | if (isinstance) { |
| 7851 | *out = LShift; |
| 7852 | return 0; |
| 7853 | } |
| 7854 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 7855 | if (isinstance == -1) { |
| 7856 | return 1; |
| 7857 | } |
| 7858 | if (isinstance) { |
| 7859 | *out = RShift; |
| 7860 | return 0; |
| 7861 | } |
| 7862 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 7863 | if (isinstance == -1) { |
| 7864 | return 1; |
| 7865 | } |
| 7866 | if (isinstance) { |
| 7867 | *out = BitOr; |
| 7868 | return 0; |
| 7869 | } |
| 7870 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 7871 | if (isinstance == -1) { |
| 7872 | return 1; |
| 7873 | } |
| 7874 | if (isinstance) { |
| 7875 | *out = BitXor; |
| 7876 | return 0; |
| 7877 | } |
| 7878 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 7879 | if (isinstance == -1) { |
| 7880 | return 1; |
| 7881 | } |
| 7882 | if (isinstance) { |
| 7883 | *out = BitAnd; |
| 7884 | return 0; |
| 7885 | } |
| 7886 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 7887 | if (isinstance == -1) { |
| 7888 | return 1; |
| 7889 | } |
| 7890 | if (isinstance) { |
| 7891 | *out = FloorDiv; |
| 7892 | return 0; |
| 7893 | } |
| 7894 | |
| 7895 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 7896 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7897 | } |
| 7898 | |
| 7899 | int |
| 7900 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 7901 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7902 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7903 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7904 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 7905 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7906 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7907 | } |
| 7908 | if (isinstance) { |
| 7909 | *out = Invert; |
| 7910 | return 0; |
| 7911 | } |
| 7912 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 7913 | if (isinstance == -1) { |
| 7914 | return 1; |
| 7915 | } |
| 7916 | if (isinstance) { |
| 7917 | *out = Not; |
| 7918 | return 0; |
| 7919 | } |
| 7920 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 7921 | if (isinstance == -1) { |
| 7922 | return 1; |
| 7923 | } |
| 7924 | if (isinstance) { |
| 7925 | *out = UAdd; |
| 7926 | return 0; |
| 7927 | } |
| 7928 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 7929 | if (isinstance == -1) { |
| 7930 | return 1; |
| 7931 | } |
| 7932 | if (isinstance) { |
| 7933 | *out = USub; |
| 7934 | return 0; |
| 7935 | } |
| 7936 | |
| 7937 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 7938 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7939 | } |
| 7940 | |
| 7941 | int |
| 7942 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 7943 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7944 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7945 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7946 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 7947 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7948 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7949 | } |
| 7950 | if (isinstance) { |
| 7951 | *out = Eq; |
| 7952 | return 0; |
| 7953 | } |
| 7954 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 7955 | if (isinstance == -1) { |
| 7956 | return 1; |
| 7957 | } |
| 7958 | if (isinstance) { |
| 7959 | *out = NotEq; |
| 7960 | return 0; |
| 7961 | } |
| 7962 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 7963 | if (isinstance == -1) { |
| 7964 | return 1; |
| 7965 | } |
| 7966 | if (isinstance) { |
| 7967 | *out = Lt; |
| 7968 | return 0; |
| 7969 | } |
| 7970 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 7971 | if (isinstance == -1) { |
| 7972 | return 1; |
| 7973 | } |
| 7974 | if (isinstance) { |
| 7975 | *out = LtE; |
| 7976 | return 0; |
| 7977 | } |
| 7978 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 7979 | if (isinstance == -1) { |
| 7980 | return 1; |
| 7981 | } |
| 7982 | if (isinstance) { |
| 7983 | *out = Gt; |
| 7984 | return 0; |
| 7985 | } |
| 7986 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 7987 | if (isinstance == -1) { |
| 7988 | return 1; |
| 7989 | } |
| 7990 | if (isinstance) { |
| 7991 | *out = GtE; |
| 7992 | return 0; |
| 7993 | } |
| 7994 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 7995 | if (isinstance == -1) { |
| 7996 | return 1; |
| 7997 | } |
| 7998 | if (isinstance) { |
| 7999 | *out = Is; |
| 8000 | return 0; |
| 8001 | } |
| 8002 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 8003 | if (isinstance == -1) { |
| 8004 | return 1; |
| 8005 | } |
| 8006 | if (isinstance) { |
| 8007 | *out = IsNot; |
| 8008 | return 0; |
| 8009 | } |
| 8010 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 8011 | if (isinstance == -1) { |
| 8012 | return 1; |
| 8013 | } |
| 8014 | if (isinstance) { |
| 8015 | *out = In; |
| 8016 | return 0; |
| 8017 | } |
| 8018 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 8019 | if (isinstance == -1) { |
| 8020 | return 1; |
| 8021 | } |
| 8022 | if (isinstance) { |
| 8023 | *out = NotIn; |
| 8024 | return 0; |
| 8025 | } |
| 8026 | |
| 8027 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 8028 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8029 | } |
| 8030 | |
| 8031 | int |
| 8032 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 8033 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8034 | PyObject* tmp = NULL; |
| 8035 | expr_ty target; |
| 8036 | expr_ty iter; |
| 8037 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8038 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8039 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8040 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 8041 | return 1; |
| 8042 | } |
| 8043 | if (tmp == NULL) { |
| 8044 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 8045 | return 1; |
| 8046 | } |
| 8047 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8048 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8049 | res = obj2ast_expr(tmp, &target, arena); |
| 8050 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8051 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8052 | } |
| 8053 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8054 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8055 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8056 | if (tmp == NULL) { |
| 8057 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 8058 | return 1; |
| 8059 | } |
| 8060 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8061 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8062 | res = obj2ast_expr(tmp, &iter, arena); |
| 8063 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8064 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8065 | } |
| 8066 | if (_PyObject_LookupAttrId(obj, &PyId_ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8067 | return 1; |
| 8068 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8069 | if (tmp == NULL) { |
| 8070 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 8071 | return 1; |
| 8072 | } |
| 8073 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8074 | int res; |
| 8075 | Py_ssize_t len; |
| 8076 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8077 | if (!PyList_Check(tmp)) { |
| 8078 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8079 | goto failed; |
| 8080 | } |
| 8081 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8082 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8083 | if (ifs == NULL) goto failed; |
| 8084 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8085 | expr_ty val; |
| 8086 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8087 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8088 | if (len != PyList_GET_SIZE(tmp)) { |
| 8089 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 8090 | goto failed; |
| 8091 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8092 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8093 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8094 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8095 | } |
| 8096 | if (_PyObject_LookupAttrId(obj, &PyId_is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8097 | return 1; |
| 8098 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8099 | if (tmp == NULL) { |
| 8100 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 8101 | return 1; |
| 8102 | } |
| 8103 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8104 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8105 | res = obj2ast_int(tmp, &is_async, arena); |
| 8106 | if (res != 0) goto failed; |
| 8107 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8108 | } |
| 8109 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8110 | return 0; |
| 8111 | failed: |
| 8112 | Py_XDECREF(tmp); |
| 8113 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8114 | } |
| 8115 | |
| 8116 | int |
| 8117 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 8118 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8119 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 8120 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8121 | PyObject *tmp = NULL; |
| 8122 | int lineno; |
| 8123 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8124 | int end_lineno; |
| 8125 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8126 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8127 | if (obj == Py_None) { |
| 8128 | *out = NULL; |
| 8129 | return 0; |
| 8130 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8131 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 8132 | return 1; |
| 8133 | } |
| 8134 | if (tmp == NULL) { |
| 8135 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 8136 | return 1; |
| 8137 | } |
| 8138 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8139 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8140 | res = obj2ast_int(tmp, &lineno, arena); |
| 8141 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8142 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8143 | } |
| 8144 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8145 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8146 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8147 | if (tmp == NULL) { |
| 8148 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 8149 | return 1; |
| 8150 | } |
| 8151 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8152 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8153 | res = obj2ast_int(tmp, &col_offset, arena); |
| 8154 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8155 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8156 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8157 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 8158 | return 1; |
| 8159 | } |
| 8160 | if (tmp == NULL || tmp == Py_None) { |
| 8161 | Py_CLEAR(tmp); |
| 8162 | end_lineno = 0; |
| 8163 | } |
| 8164 | else { |
| 8165 | int res; |
| 8166 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 8167 | if (res != 0) goto failed; |
| 8168 | Py_CLEAR(tmp); |
| 8169 | } |
| 8170 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 8171 | return 1; |
| 8172 | } |
| 8173 | if (tmp == NULL || tmp == Py_None) { |
| 8174 | Py_CLEAR(tmp); |
| 8175 | end_col_offset = 0; |
| 8176 | } |
| 8177 | else { |
| 8178 | int res; |
| 8179 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 8180 | if (res != 0) goto failed; |
| 8181 | Py_CLEAR(tmp); |
| 8182 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8183 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 8184 | if (isinstance == -1) { |
| 8185 | return 1; |
| 8186 | } |
| 8187 | if (isinstance) { |
| 8188 | expr_ty type; |
| 8189 | identifier name; |
| 8190 | asdl_seq* body; |
| 8191 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8192 | if (_PyObject_LookupAttrId(obj, &PyId_type, &tmp) < 0) { |
| 8193 | return 1; |
| 8194 | } |
| 8195 | if (tmp == NULL || tmp == Py_None) { |
| 8196 | Py_CLEAR(tmp); |
| 8197 | type = NULL; |
| 8198 | } |
| 8199 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8200 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8201 | res = obj2ast_expr(tmp, &type, arena); |
| 8202 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8203 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8204 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8205 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 8206 | return 1; |
| 8207 | } |
| 8208 | if (tmp == NULL || tmp == Py_None) { |
| 8209 | Py_CLEAR(tmp); |
| 8210 | name = NULL; |
| 8211 | } |
| 8212 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8213 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8214 | res = obj2ast_identifier(tmp, &name, arena); |
| 8215 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8216 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8217 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8218 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 8219 | return 1; |
| 8220 | } |
| 8221 | if (tmp == NULL) { |
| 8222 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 8223 | return 1; |
| 8224 | } |
| 8225 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8226 | int res; |
| 8227 | Py_ssize_t len; |
| 8228 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8229 | if (!PyList_Check(tmp)) { |
| 8230 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8231 | goto failed; |
| 8232 | } |
| 8233 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8234 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8235 | if (body == NULL) goto failed; |
| 8236 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8237 | stmt_ty val; |
| 8238 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8239 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8240 | if (len != PyList_GET_SIZE(tmp)) { |
| 8241 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 8242 | goto failed; |
| 8243 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8244 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8245 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8246 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8247 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8248 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 8249 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8250 | if (*out == NULL) goto failed; |
| 8251 | return 0; |
| 8252 | } |
| 8253 | |
| 8254 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 8255 | failed: |
| 8256 | Py_XDECREF(tmp); |
| 8257 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8258 | } |
| 8259 | |
| 8260 | int |
| 8261 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 8262 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8263 | PyObject* tmp = NULL; |
| 8264 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8265 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8266 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8267 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8268 | arg_ty kwarg; |
| 8269 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8270 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8271 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
| 8272 | return 1; |
| 8273 | } |
| 8274 | if (tmp == NULL) { |
| 8275 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 8276 | return 1; |
| 8277 | } |
| 8278 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8279 | int res; |
| 8280 | Py_ssize_t len; |
| 8281 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8282 | if (!PyList_Check(tmp)) { |
| 8283 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8284 | goto failed; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8285 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8286 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8287 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8288 | if (args == NULL) goto failed; |
| 8289 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8290 | arg_ty val; |
| 8291 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8292 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8293 | if (len != PyList_GET_SIZE(tmp)) { |
| 8294 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 8295 | goto failed; |
| 8296 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8297 | asdl_seq_SET(args, i, val); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8298 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8299 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8300 | } |
| 8301 | if (_PyObject_LookupAttrId(obj, &PyId_vararg, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8302 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8303 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8304 | if (tmp == NULL || tmp == Py_None) { |
| 8305 | Py_CLEAR(tmp); |
| 8306 | vararg = NULL; |
| 8307 | } |
| 8308 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8309 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8310 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8311 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8312 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8313 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8314 | if (_PyObject_LookupAttrId(obj, &PyId_kwonlyargs, &tmp) < 0) { |
| 8315 | return 1; |
| 8316 | } |
| 8317 | if (tmp == NULL) { |
| 8318 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 8319 | return 1; |
| 8320 | } |
| 8321 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8322 | int res; |
| 8323 | Py_ssize_t len; |
| 8324 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8325 | if (!PyList_Check(tmp)) { |
| 8326 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8327 | goto failed; |
| 8328 | } |
| 8329 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8330 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8331 | if (kwonlyargs == NULL) goto failed; |
| 8332 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8333 | arg_ty val; |
| 8334 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8335 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8336 | if (len != PyList_GET_SIZE(tmp)) { |
| 8337 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 8338 | goto failed; |
| 8339 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8340 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8341 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8342 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8343 | } |
| 8344 | if (_PyObject_LookupAttrId(obj, &PyId_kw_defaults, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8345 | return 1; |
| 8346 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8347 | if (tmp == NULL) { |
| 8348 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 8349 | return 1; |
| 8350 | } |
| 8351 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8352 | int res; |
| 8353 | Py_ssize_t len; |
| 8354 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8355 | if (!PyList_Check(tmp)) { |
| 8356 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8357 | goto failed; |
| 8358 | } |
| 8359 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8360 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8361 | if (kw_defaults == NULL) goto failed; |
| 8362 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8363 | expr_ty val; |
| 8364 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8365 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8366 | if (len != PyList_GET_SIZE(tmp)) { |
| 8367 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 8368 | goto failed; |
| 8369 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8370 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8371 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8372 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8373 | } |
| 8374 | if (_PyObject_LookupAttrId(obj, &PyId_kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8375 | return 1; |
| 8376 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8377 | if (tmp == NULL || tmp == Py_None) { |
| 8378 | Py_CLEAR(tmp); |
| 8379 | kwarg = NULL; |
| 8380 | } |
| 8381 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8382 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8383 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 8384 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 8385 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8386 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8387 | if (_PyObject_LookupAttrId(obj, &PyId_defaults, &tmp) < 0) { |
| 8388 | return 1; |
| 8389 | } |
| 8390 | if (tmp == NULL) { |
| 8391 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 8392 | return 1; |
| 8393 | } |
| 8394 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8395 | int res; |
| 8396 | Py_ssize_t len; |
| 8397 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8398 | if (!PyList_Check(tmp)) { |
| 8399 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8400 | goto failed; |
| 8401 | } |
| 8402 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8403 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8404 | if (defaults == NULL) goto failed; |
| 8405 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8406 | expr_ty val; |
| 8407 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8408 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8409 | if (len != PyList_GET_SIZE(tmp)) { |
| 8410 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 8411 | goto failed; |
| 8412 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8413 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8414 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 8415 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8416 | } |
| 8417 | *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg, defaults, |
| 8418 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8419 | return 0; |
| 8420 | failed: |
| 8421 | Py_XDECREF(tmp); |
| 8422 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8423 | } |
| 8424 | |
| 8425 | int |
| 8426 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 8427 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8428 | PyObject* tmp = NULL; |
| 8429 | identifier arg; |
| 8430 | expr_ty annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8431 | string type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8432 | int lineno; |
| 8433 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8434 | int end_lineno; |
| 8435 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8436 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8437 | if (_PyObject_LookupAttrId(obj, &PyId_arg, &tmp) < 0) { |
| 8438 | return 1; |
| 8439 | } |
| 8440 | if (tmp == NULL) { |
| 8441 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 8442 | return 1; |
| 8443 | } |
| 8444 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8445 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8446 | res = obj2ast_identifier(tmp, &arg, arena); |
| 8447 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8448 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8449 | } |
| 8450 | if (_PyObject_LookupAttrId(obj, &PyId_annotation, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8451 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8452 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8453 | if (tmp == NULL || tmp == Py_None) { |
| 8454 | Py_CLEAR(tmp); |
| 8455 | annotation = NULL; |
| 8456 | } |
| 8457 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8458 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8459 | res = obj2ast_expr(tmp, &annotation, arena); |
| 8460 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8461 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8462 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8463 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 8464 | return 1; |
| 8465 | } |
| 8466 | if (tmp == NULL || tmp == Py_None) { |
| 8467 | Py_CLEAR(tmp); |
| 8468 | type_comment = NULL; |
| 8469 | } |
| 8470 | else { |
| 8471 | int res; |
| 8472 | res = obj2ast_string(tmp, &type_comment, arena); |
| 8473 | if (res != 0) goto failed; |
| 8474 | Py_CLEAR(tmp); |
| 8475 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8476 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 8477 | return 1; |
| 8478 | } |
| 8479 | if (tmp == NULL) { |
| 8480 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 8481 | return 1; |
| 8482 | } |
| 8483 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8484 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8485 | res = obj2ast_int(tmp, &lineno, arena); |
| 8486 | if (res != 0) goto failed; |
| 8487 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8488 | } |
| 8489 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8490 | return 1; |
| 8491 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8492 | if (tmp == NULL) { |
| 8493 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 8494 | return 1; |
| 8495 | } |
| 8496 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8497 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8498 | res = obj2ast_int(tmp, &col_offset, arena); |
| 8499 | if (res != 0) goto failed; |
| 8500 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8501 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8502 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 8503 | return 1; |
| 8504 | } |
| 8505 | if (tmp == NULL || tmp == Py_None) { |
| 8506 | Py_CLEAR(tmp); |
| 8507 | end_lineno = 0; |
| 8508 | } |
| 8509 | else { |
| 8510 | int res; |
| 8511 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 8512 | if (res != 0) goto failed; |
| 8513 | Py_CLEAR(tmp); |
| 8514 | } |
| 8515 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 8516 | return 1; |
| 8517 | } |
| 8518 | if (tmp == NULL || tmp == Py_None) { |
| 8519 | Py_CLEAR(tmp); |
| 8520 | end_col_offset = 0; |
| 8521 | } |
| 8522 | else { |
| 8523 | int res; |
| 8524 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 8525 | if (res != 0) goto failed; |
| 8526 | Py_CLEAR(tmp); |
| 8527 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8528 | *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno, |
| 8529 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8530 | return 0; |
| 8531 | failed: |
| 8532 | Py_XDECREF(tmp); |
| 8533 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8534 | } |
| 8535 | |
| 8536 | int |
| 8537 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 8538 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8539 | PyObject* tmp = NULL; |
| 8540 | identifier arg; |
| 8541 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8542 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8543 | if (_PyObject_LookupAttrId(obj, &PyId_arg, &tmp) < 0) { |
| 8544 | return 1; |
| 8545 | } |
| 8546 | if (tmp == NULL || tmp == Py_None) { |
| 8547 | Py_CLEAR(tmp); |
| 8548 | arg = NULL; |
| 8549 | } |
| 8550 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8551 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8552 | res = obj2ast_identifier(tmp, &arg, arena); |
| 8553 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8554 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8555 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8556 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 8557 | return 1; |
| 8558 | } |
| 8559 | if (tmp == NULL) { |
| 8560 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 8561 | return 1; |
| 8562 | } |
| 8563 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8564 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8565 | res = obj2ast_expr(tmp, &value, arena); |
| 8566 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8567 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8568 | } |
| 8569 | *out = keyword(arg, value, arena); |
| 8570 | return 0; |
| 8571 | failed: |
| 8572 | Py_XDECREF(tmp); |
| 8573 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8574 | } |
| 8575 | |
| 8576 | int |
| 8577 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 8578 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8579 | PyObject* tmp = NULL; |
| 8580 | identifier name; |
| 8581 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8582 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8583 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 8584 | return 1; |
| 8585 | } |
| 8586 | if (tmp == NULL) { |
| 8587 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 8588 | return 1; |
| 8589 | } |
| 8590 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8591 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8592 | res = obj2ast_identifier(tmp, &name, arena); |
| 8593 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8594 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8595 | } |
| 8596 | if (_PyObject_LookupAttrId(obj, &PyId_asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8597 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8598 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8599 | if (tmp == NULL || tmp == Py_None) { |
| 8600 | Py_CLEAR(tmp); |
| 8601 | asname = NULL; |
| 8602 | } |
| 8603 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8604 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8605 | res = obj2ast_identifier(tmp, &asname, arena); |
| 8606 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8607 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8608 | } |
| 8609 | *out = alias(name, asname, arena); |
| 8610 | return 0; |
| 8611 | failed: |
| 8612 | Py_XDECREF(tmp); |
| 8613 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8614 | } |
| 8615 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8616 | int |
| 8617 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 8618 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8619 | PyObject* tmp = NULL; |
| 8620 | expr_ty context_expr; |
| 8621 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8622 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8623 | if (_PyObject_LookupAttrId(obj, &PyId_context_expr, &tmp) < 0) { |
| 8624 | return 1; |
| 8625 | } |
| 8626 | if (tmp == NULL) { |
| 8627 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 8628 | return 1; |
| 8629 | } |
| 8630 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8631 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8632 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 8633 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8634 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8635 | } |
| 8636 | if (_PyObject_LookupAttrId(obj, &PyId_optional_vars, &tmp) < 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8637 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8638 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8639 | if (tmp == NULL || tmp == Py_None) { |
| 8640 | Py_CLEAR(tmp); |
| 8641 | optional_vars = NULL; |
| 8642 | } |
| 8643 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8644 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8645 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 8646 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8647 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8648 | } |
| 8649 | *out = withitem(context_expr, optional_vars, arena); |
| 8650 | return 0; |
| 8651 | failed: |
| 8652 | Py_XDECREF(tmp); |
| 8653 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8654 | } |
| 8655 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8656 | int |
| 8657 | obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) |
| 8658 | { |
| 8659 | int isinstance; |
| 8660 | |
| 8661 | PyObject *tmp = NULL; |
| 8662 | |
| 8663 | if (obj == Py_None) { |
| 8664 | *out = NULL; |
| 8665 | return 0; |
| 8666 | } |
| 8667 | isinstance = PyObject_IsInstance(obj, (PyObject*)TypeIgnore_type); |
| 8668 | if (isinstance == -1) { |
| 8669 | return 1; |
| 8670 | } |
| 8671 | if (isinstance) { |
| 8672 | int lineno; |
| 8673 | |
| 8674 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 8675 | return 1; |
| 8676 | } |
| 8677 | if (tmp == NULL) { |
| 8678 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore"); |
| 8679 | return 1; |
| 8680 | } |
| 8681 | else { |
| 8682 | int res; |
| 8683 | res = obj2ast_int(tmp, &lineno, arena); |
| 8684 | if (res != 0) goto failed; |
| 8685 | Py_CLEAR(tmp); |
| 8686 | } |
| 8687 | *out = TypeIgnore(lineno, arena); |
| 8688 | if (*out == NULL) goto failed; |
| 8689 | return 0; |
| 8690 | } |
| 8691 | |
| 8692 | PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj); |
| 8693 | failed: |
| 8694 | Py_XDECREF(tmp); |
| 8695 | return 1; |
| 8696 | } |
| 8697 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8698 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 8699 | static struct PyModuleDef _astmodule = { |
| 8700 | PyModuleDef_HEAD_INIT, "_ast" |
| 8701 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8702 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 8703 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8704 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8705 | PyObject *m, *d; |
| 8706 | if (!init_types()) return NULL; |
| 8707 | m = PyModule_Create(&_astmodule); |
| 8708 | if (!m) return NULL; |
| 8709 | d = PyModule_GetDict(m); |
| 8710 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8711 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8712 | return NULL; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8713 | if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) |
| 8714 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8715 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; |
| 8716 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return |
| 8717 | NULL; |
| 8718 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) < |
| 8719 | 0) return NULL; |
| 8720 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0) |
| 8721 | return NULL; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8722 | if (PyDict_SetItemString(d, "FunctionType", (PyObject*)FunctionType_type) < |
| 8723 | 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8724 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 8725 | NULL; |
| 8726 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL; |
| 8727 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) < |
| 8728 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8729 | if (PyDict_SetItemString(d, "AsyncFunctionDef", |
| 8730 | (PyObject*)AsyncFunctionDef_type) < 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8731 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 8732 | return NULL; |
| 8733 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return |
| 8734 | NULL; |
| 8735 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return |
| 8736 | NULL; |
| 8737 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return |
| 8738 | NULL; |
| 8739 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0) |
| 8740 | return NULL; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 8741 | if (PyDict_SetItemString(d, "AnnAssign", (PyObject*)AnnAssign_type) < 0) |
| 8742 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8743 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8744 | if (PyDict_SetItemString(d, "AsyncFor", (PyObject*)AsyncFor_type) < 0) |
| 8745 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8746 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 8747 | NULL; |
| 8748 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 8749 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8750 | if (PyDict_SetItemString(d, "AsyncWith", (PyObject*)AsyncWith_type) < 0) |
| 8751 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8752 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 8753 | NULL; |
| 8754 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL; |
| 8755 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return |
| 8756 | NULL; |
| 8757 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return |
| 8758 | NULL; |
| 8759 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0) |
| 8760 | return NULL; |
| 8761 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return |
| 8762 | NULL; |
| 8763 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
| 8764 | return NULL; |
| 8765 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL; |
| 8766 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL; |
| 8767 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 8768 | NULL; |
| 8769 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 8770 | return NULL; |
| 8771 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL; |
| 8772 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return |
| 8773 | NULL; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 8774 | if (PyDict_SetItemString(d, "NamedExpr", (PyObject*)NamedExpr_type) < 0) |
| 8775 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8776 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 8777 | NULL; |
| 8778 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return |
| 8779 | NULL; |
| 8780 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return |
| 8781 | NULL; |
| 8782 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 8783 | NULL; |
| 8784 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL; |
| 8785 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL; |
| 8786 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 8787 | return NULL; |
| 8788 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return |
| 8789 | NULL; |
| 8790 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
| 8791 | return NULL; |
| 8792 | if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) < |
| 8793 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8794 | if (PyDict_SetItemString(d, "Await", (PyObject*)Await_type) < 0) return |
| 8795 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8796 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 8797 | NULL; |
| 8798 | if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0) |
| 8799 | return NULL; |
| 8800 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return |
| 8801 | NULL; |
| 8802 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8803 | if (PyDict_SetItemString(d, "FormattedValue", |
| 8804 | (PyObject*)FormattedValue_type) < 0) return NULL; |
| 8805 | if (PyDict_SetItemString(d, "JoinedStr", (PyObject*)JoinedStr_type) < 0) |
| 8806 | return NULL; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8807 | if (PyDict_SetItemString(d, "Constant", (PyObject*)Constant_type) < 0) |
| 8808 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8809 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0) |
| 8810 | return NULL; |
| 8811 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0) |
| 8812 | return NULL; |
| 8813 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return |
| 8814 | NULL; |
| 8815 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL; |
| 8816 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL; |
| 8817 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 8818 | NULL; |
| 8819 | if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) < |
| 8820 | 0) return NULL; |
| 8821 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL; |
| 8822 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 8823 | NULL; |
| 8824 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL; |
| 8825 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return |
| 8826 | NULL; |
| 8827 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 8828 | return NULL; |
| 8829 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 8830 | NULL; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 8831 | if (PyDict_SetItemString(d, "NamedStore", (PyObject*)NamedStore_type) < 0) |
| 8832 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8833 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 8834 | NULL; |
| 8835 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 8836 | NULL; |
| 8837 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 8838 | return NULL; |
| 8839 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 8840 | NULL; |
| 8841 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return |
| 8842 | NULL; |
| 8843 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL; |
| 8844 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
| 8845 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 8846 | return NULL; |
| 8847 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL; |
| 8848 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL; |
| 8849 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8850 | if (PyDict_SetItemString(d, "MatMult", (PyObject*)MatMult_type) < 0) return |
| 8851 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8852 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL; |
| 8853 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL; |
| 8854 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL; |
| 8855 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return |
| 8856 | NULL; |
| 8857 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return |
| 8858 | NULL; |
| 8859 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 8860 | NULL; |
| 8861 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return |
| 8862 | NULL; |
| 8863 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return |
| 8864 | NULL; |
| 8865 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 8866 | return NULL; |
| 8867 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return |
| 8868 | NULL; |
| 8869 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return |
| 8870 | NULL; |
| 8871 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL; |
| 8872 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL; |
| 8873 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL; |
| 8874 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 8875 | NULL; |
| 8876 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 8877 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 8878 | NULL; |
| 8879 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 8880 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL; |
| 8881 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 8882 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL; |
| 8883 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 8884 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 8885 | NULL; |
| 8886 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 8887 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 8888 | NULL; |
| 8889 | if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type) |
| 8890 | < 0) return NULL; |
| 8891 | if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type) |
| 8892 | < 0) return NULL; |
| 8893 | if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type) |
| 8894 | < 0) return NULL; |
| 8895 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0) |
| 8896 | return NULL; |
| 8897 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL; |
| 8898 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return |
| 8899 | NULL; |
| 8900 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 8901 | NULL; |
| 8902 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 8903 | return NULL; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8904 | if (PyDict_SetItemString(d, "type_ignore", (PyObject*)type_ignore_type) < |
| 8905 | 0) return NULL; |
| 8906 | if (PyDict_SetItemString(d, "TypeIgnore", (PyObject*)TypeIgnore_type) < 0) |
| 8907 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8908 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8909 | } |
| 8910 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8911 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 8912 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8913 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 8914 | if (!init_types()) |
| 8915 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 8916 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8917 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 8918 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8919 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 8920 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8921 | { |
| 8922 | mod_ty res; |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 8923 | PyObject *req_type[3]; |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 8924 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 8925 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 8926 | |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 8927 | req_type[0] = (PyObject*)Module_type; |
| 8928 | req_type[1] = (PyObject*)Expression_type; |
| 8929 | req_type[2] = (PyObject*)Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 8930 | |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 8931 | assert(0 <= mode && mode <= 2); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8932 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 8933 | if (!init_types()) |
| 8934 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8935 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 8936 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 8937 | if (isinstance == -1) |
| 8938 | return NULL; |
| 8939 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8940 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 8941 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8942 | return NULL; |
| 8943 | } |
| 8944 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 8945 | return NULL; |
| 8946 | else |
| 8947 | return res; |
| 8948 | } |
| 8949 | |
| 8950 | int PyAST_Check(PyObject* obj) |
| 8951 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 8952 | if (!init_types()) |
| 8953 | return -1; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 8954 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8955 | } |
| 8956 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 8957 | |