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); |
Eric V. Smith | 9a4135e | 2019-05-08 16:28:48 -0400 | [diff] [blame] | 317 | _Py_IDENTIFIER(expr_text); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 318 | static char *FormattedValue_fields[]={ |
| 319 | "value", |
| 320 | "conversion", |
| 321 | "format_spec", |
Eric V. Smith | 9a4135e | 2019-05-08 16:28:48 -0400 | [diff] [blame] | 322 | "expr_text", |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 323 | }; |
| 324 | static PyTypeObject *JoinedStr_type; |
| 325 | static char *JoinedStr_fields[]={ |
| 326 | "values", |
| 327 | }; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 328 | static PyTypeObject *Constant_type; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 329 | _Py_IDENTIFIER(kind); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 330 | static char *Constant_fields[]={ |
| 331 | "value", |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 332 | "kind", |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 333 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 334 | static PyTypeObject *Attribute_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 335 | _Py_IDENTIFIER(attr); |
| 336 | _Py_IDENTIFIER(ctx); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 337 | static char *Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 338 | "value", |
| 339 | "attr", |
| 340 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 341 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 342 | static PyTypeObject *Subscript_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 343 | _Py_IDENTIFIER(slice); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 344 | static char *Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 345 | "value", |
| 346 | "slice", |
| 347 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 348 | }; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 349 | static PyTypeObject *Starred_type; |
| 350 | static char *Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 351 | "value", |
| 352 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 353 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 354 | static PyTypeObject *Name_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 355 | _Py_IDENTIFIER(id); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 356 | static char *Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 357 | "id", |
| 358 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 359 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 360 | static PyTypeObject *List_type; |
| 361 | static char *List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 362 | "elts", |
| 363 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 364 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 365 | static PyTypeObject *Tuple_type; |
| 366 | static char *Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 367 | "elts", |
| 368 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 369 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 370 | static PyTypeObject *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 371 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
Serhiy Storchaka | d8b3a98 | 2019-03-05 20:42:06 +0200 | [diff] [blame] | 372 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 373 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 374 | static PyTypeObject *Load_type; |
| 375 | static PyTypeObject *Store_type; |
| 376 | static PyTypeObject *Del_type; |
| 377 | static PyTypeObject *AugLoad_type; |
| 378 | static PyTypeObject *AugStore_type; |
| 379 | static PyTypeObject *Param_type; |
| 380 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 381 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 382 | static PyTypeObject *Slice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 383 | _Py_IDENTIFIER(lower); |
| 384 | _Py_IDENTIFIER(upper); |
| 385 | _Py_IDENTIFIER(step); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 386 | static char *Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 387 | "lower", |
| 388 | "upper", |
| 389 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 390 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 391 | static PyTypeObject *ExtSlice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 392 | _Py_IDENTIFIER(dims); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 393 | static char *ExtSlice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 394 | "dims", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 395 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 396 | static PyTypeObject *Index_type; |
| 397 | static char *Index_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 398 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 399 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 400 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 401 | static PyObject *And_singleton, *Or_singleton; |
| 402 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 403 | static PyTypeObject *And_type; |
| 404 | static PyTypeObject *Or_type; |
| 405 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 406 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 407 | *MatMult_singleton, *Div_singleton, *Mod_singleton, *Pow_singleton, |
| 408 | *LShift_singleton, *RShift_singleton, *BitOr_singleton, *BitXor_singleton, |
| 409 | *BitAnd_singleton, *FloorDiv_singleton; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 410 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 411 | static PyTypeObject *Add_type; |
| 412 | static PyTypeObject *Sub_type; |
| 413 | static PyTypeObject *Mult_type; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 414 | static PyTypeObject *MatMult_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 415 | static PyTypeObject *Div_type; |
| 416 | static PyTypeObject *Mod_type; |
| 417 | static PyTypeObject *Pow_type; |
| 418 | static PyTypeObject *LShift_type; |
| 419 | static PyTypeObject *RShift_type; |
| 420 | static PyTypeObject *BitOr_type; |
| 421 | static PyTypeObject *BitXor_type; |
| 422 | static PyTypeObject *BitAnd_type; |
| 423 | static PyTypeObject *FloorDiv_type; |
| 424 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 425 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 426 | *USub_singleton; |
| 427 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 428 | static PyTypeObject *Invert_type; |
| 429 | static PyTypeObject *Not_type; |
| 430 | static PyTypeObject *UAdd_type; |
| 431 | static PyTypeObject *USub_type; |
| 432 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 433 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 434 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 435 | *NotIn_singleton; |
| 436 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 437 | static PyTypeObject *Eq_type; |
| 438 | static PyTypeObject *NotEq_type; |
| 439 | static PyTypeObject *Lt_type; |
| 440 | static PyTypeObject *LtE_type; |
| 441 | static PyTypeObject *Gt_type; |
| 442 | static PyTypeObject *GtE_type; |
| 443 | static PyTypeObject *Is_type; |
| 444 | static PyTypeObject *IsNot_type; |
| 445 | static PyTypeObject *In_type; |
| 446 | static PyTypeObject *NotIn_type; |
| 447 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 448 | static PyObject* ast2obj_comprehension(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 449 | _Py_IDENTIFIER(ifs); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 450 | _Py_IDENTIFIER(is_async); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 451 | static char *comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 452 | "target", |
| 453 | "iter", |
| 454 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 455 | "is_async", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 456 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 457 | static PyTypeObject *excepthandler_type; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 458 | static char *excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 459 | "lineno", |
| 460 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 461 | "end_lineno", |
| 462 | "end_col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 463 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 464 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 465 | static PyTypeObject *ExceptHandler_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 466 | _Py_IDENTIFIER(type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 467 | static char *ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 468 | "type", |
| 469 | "name", |
| 470 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 471 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 472 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 473 | static PyObject* ast2obj_arguments(void*); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 474 | _Py_IDENTIFIER(posonlyargs); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 475 | _Py_IDENTIFIER(vararg); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 476 | _Py_IDENTIFIER(kwonlyargs); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 477 | _Py_IDENTIFIER(kw_defaults); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 478 | _Py_IDENTIFIER(kwarg); |
| 479 | _Py_IDENTIFIER(defaults); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 480 | static char *arguments_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 481 | "args", |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 482 | "posonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 483 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 484 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 485 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 486 | "kwarg", |
| 487 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 488 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 489 | static PyTypeObject *arg_type; |
| 490 | static PyObject* ast2obj_arg(void*); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 491 | static char *arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 492 | "lineno", |
| 493 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 494 | "end_lineno", |
| 495 | "end_col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 496 | }; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 497 | _Py_IDENTIFIER(arg); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 498 | static char *arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 499 | "arg", |
| 500 | "annotation", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 501 | "type_comment", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 502 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 503 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 504 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 505 | static char *keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 506 | "arg", |
| 507 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 508 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 509 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 510 | static PyObject* ast2obj_alias(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 511 | _Py_IDENTIFIER(asname); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 512 | static char *alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 513 | "name", |
| 514 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 515 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 516 | static PyTypeObject *withitem_type; |
| 517 | static PyObject* ast2obj_withitem(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 518 | _Py_IDENTIFIER(context_expr); |
| 519 | _Py_IDENTIFIER(optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 520 | static char *withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 521 | "context_expr", |
| 522 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 523 | }; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 524 | static PyTypeObject *type_ignore_type; |
| 525 | static PyObject* ast2obj_type_ignore(void*); |
| 526 | static PyTypeObject *TypeIgnore_type; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 527 | _Py_IDENTIFIER(tag); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 528 | static char *TypeIgnore_fields[]={ |
| 529 | "lineno", |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 530 | "tag", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 531 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 532 | |
| 533 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 534 | _Py_IDENTIFIER(_fields); |
| 535 | _Py_IDENTIFIER(_attributes); |
| 536 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 537 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 538 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 539 | PyObject *dict; |
| 540 | } AST_object; |
| 541 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 542 | static void |
| 543 | ast_dealloc(AST_object *self) |
| 544 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 545 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
| 546 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 547 | Py_CLEAR(self->dict); |
Antoine Pitrou | 5075074 | 2012-07-08 12:43:32 +0200 | [diff] [blame] | 548 | Py_TYPE(self)->tp_free(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 549 | } |
| 550 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 551 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 552 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 553 | { |
| 554 | Py_VISIT(self->dict); |
| 555 | return 0; |
| 556 | } |
| 557 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 558 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 559 | ast_clear(AST_object *self) |
| 560 | { |
| 561 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 562 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 566 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 567 | { |
| 568 | Py_ssize_t i, numfields = 0; |
| 569 | int res = -1; |
| 570 | PyObject *key, *value, *fields; |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 571 | if (_PyObject_LookupAttrId((PyObject*)Py_TYPE(self), &PyId__fields, &fields) < 0) { |
| 572 | goto cleanup; |
| 573 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 574 | if (fields) { |
| 575 | numfields = PySequence_Size(fields); |
| 576 | if (numfields == -1) |
| 577 | goto cleanup; |
| 578 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 579 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 580 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 581 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 582 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 583 | "%zd positional argument%s", |
| 584 | Py_TYPE(self)->tp_name, |
| 585 | numfields, numfields == 1 ? "" : "s"); |
| 586 | res = -1; |
| 587 | goto cleanup; |
| 588 | } |
| 589 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 590 | /* cannot be reached when fields is NULL */ |
| 591 | PyObject *name = PySequence_GetItem(fields, i); |
| 592 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 593 | res = -1; |
| 594 | goto cleanup; |
| 595 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 596 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 597 | Py_DECREF(name); |
| 598 | if (res < 0) |
| 599 | goto cleanup; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 600 | } |
| 601 | if (kw) { |
| 602 | i = 0; /* needed by PyDict_Next */ |
| 603 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 604 | res = PyObject_SetAttr(self, key, value); |
| 605 | if (res < 0) |
| 606 | goto cleanup; |
| 607 | } |
| 608 | } |
| 609 | cleanup: |
| 610 | Py_XDECREF(fields); |
| 611 | return res; |
| 612 | } |
| 613 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 614 | /* Pickling support */ |
| 615 | static PyObject * |
| 616 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 617 | { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 618 | _Py_IDENTIFIER(__dict__); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 619 | PyObject *dict; |
| 620 | if (_PyObject_LookupAttrId(self, &PyId___dict__, &dict) < 0) { |
| 621 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 622 | } |
| 623 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 624 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 625 | } |
| 626 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 627 | } |
| 628 | |
| 629 | static PyMethodDef ast_type_methods[] = { |
| 630 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 631 | {NULL} |
| 632 | }; |
| 633 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 634 | static PyGetSetDef ast_type_getsets[] = { |
| 635 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 636 | {NULL} |
| 637 | }; |
| 638 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 639 | static PyTypeObject AST_type = { |
| 640 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 641 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 642 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 643 | 0, |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 644 | (destructor)ast_dealloc, /* tp_dealloc */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 645 | 0, /* tp_print */ |
| 646 | 0, /* tp_getattr */ |
| 647 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 648 | 0, /* tp_reserved */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 649 | 0, /* tp_repr */ |
| 650 | 0, /* tp_as_number */ |
| 651 | 0, /* tp_as_sequence */ |
| 652 | 0, /* tp_as_mapping */ |
| 653 | 0, /* tp_hash */ |
| 654 | 0, /* tp_call */ |
| 655 | 0, /* tp_str */ |
| 656 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 657 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 658 | 0, /* tp_as_buffer */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 659 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 660 | 0, /* tp_doc */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 661 | (traverseproc)ast_traverse, /* tp_traverse */ |
| 662 | (inquiry)ast_clear, /* tp_clear */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 663 | 0, /* tp_richcompare */ |
| 664 | 0, /* tp_weaklistoffset */ |
| 665 | 0, /* tp_iter */ |
| 666 | 0, /* tp_iternext */ |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 667 | ast_type_methods, /* tp_methods */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 668 | 0, /* tp_members */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 669 | ast_type_getsets, /* tp_getset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 670 | 0, /* tp_base */ |
| 671 | 0, /* tp_dict */ |
| 672 | 0, /* tp_descr_get */ |
| 673 | 0, /* tp_descr_set */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 674 | offsetof(AST_object, dict),/* tp_dictoffset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 675 | (initproc)ast_type_init, /* tp_init */ |
| 676 | PyType_GenericAlloc, /* tp_alloc */ |
| 677 | PyType_GenericNew, /* tp_new */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 678 | PyObject_GC_Del, /* tp_free */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 679 | }; |
| 680 | |
| 681 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 682 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 683 | { |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 684 | _Py_IDENTIFIER(__module__); |
| 685 | _Py_IDENTIFIER(_ast); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 686 | PyObject *fnames, *result; |
| 687 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 688 | fnames = PyTuple_New(num_fields); |
| 689 | if (!fnames) return NULL; |
| 690 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 691 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 692 | if (!field) { |
| 693 | Py_DECREF(fnames); |
| 694 | return NULL; |
| 695 | } |
| 696 | PyTuple_SET_ITEM(fnames, i, field); |
| 697 | } |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 698 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}", |
| 699 | type, base, |
| 700 | _PyUnicode_FromId(&PyId__fields), fnames, |
| 701 | _PyUnicode_FromId(&PyId___module__), |
| 702 | _PyUnicode_FromId(&PyId__ast)); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 703 | Py_DECREF(fnames); |
| 704 | return (PyTypeObject*)result; |
| 705 | } |
| 706 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 707 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 708 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 709 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 710 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 711 | if (!l) |
| 712 | return 0; |
| 713 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 714 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 715 | if (!s) { |
| 716 | Py_DECREF(l); |
| 717 | return 0; |
| 718 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 719 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 720 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 721 | result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 722 | Py_DECREF(l); |
| 723 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 724 | } |
| 725 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 726 | /* Conversion AST -> Python */ |
| 727 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 728 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 729 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 730 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 731 | PyObject *result = PyList_New(n); |
| 732 | PyObject *value; |
| 733 | if (!result) |
| 734 | return NULL; |
| 735 | for (i = 0; i < n; i++) { |
| 736 | value = func(asdl_seq_GET(seq, i)); |
| 737 | if (!value) { |
| 738 | Py_DECREF(result); |
| 739 | return NULL; |
| 740 | } |
| 741 | PyList_SET_ITEM(result, i, value); |
| 742 | } |
| 743 | return result; |
| 744 | } |
| 745 | |
| 746 | static PyObject* ast2obj_object(void *o) |
| 747 | { |
| 748 | if (!o) |
| 749 | o = Py_None; |
| 750 | Py_INCREF((PyObject*)o); |
| 751 | return (PyObject*)o; |
| 752 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 753 | #define ast2obj_singleton ast2obj_object |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 754 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 755 | #define ast2obj_identifier ast2obj_object |
| 756 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 757 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 758 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 759 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 760 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 761 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 762 | } |
| 763 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 764 | /* Conversion Python -> AST */ |
| 765 | |
| 766 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 767 | { |
| 768 | if (obj == Py_None) |
| 769 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 770 | if (obj) { |
| 771 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 772 | *out = NULL; |
| 773 | return -1; |
| 774 | } |
| 775 | Py_INCREF(obj); |
| 776 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 777 | *out = obj; |
| 778 | return 0; |
| 779 | } |
| 780 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 781 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 782 | { |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 783 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 784 | *out = NULL; |
| 785 | return -1; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 786 | } |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 787 | Py_INCREF(obj); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 788 | *out = obj; |
| 789 | return 0; |
| 790 | } |
| 791 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 792 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 793 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 794 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 795 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 796 | return 1; |
| 797 | } |
| 798 | return obj2ast_object(obj, out, arena); |
| 799 | } |
| 800 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 801 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 802 | { |
| 803 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
| 804 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 805 | return 1; |
| 806 | } |
| 807 | return obj2ast_object(obj, out, arena); |
| 808 | } |
| 809 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 810 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 811 | { |
| 812 | int i; |
| 813 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 814 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 815 | return 1; |
| 816 | } |
| 817 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 818 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 819 | if (i == -1 && PyErr_Occurred()) |
| 820 | return 1; |
| 821 | *out = i; |
| 822 | return 0; |
| 823 | } |
| 824 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 825 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 826 | { |
| 827 | PyObject *empty_tuple, *d; |
| 828 | if (PyType_Ready(&AST_type) < 0) |
| 829 | return -1; |
| 830 | d = AST_type.tp_dict; |
| 831 | empty_tuple = PyTuple_New(0); |
| 832 | if (!empty_tuple || |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 833 | _PyDict_SetItemId(d, &PyId__fields, empty_tuple) < 0 || |
| 834 | _PyDict_SetItemId(d, &PyId__attributes, empty_tuple) < 0) { |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 835 | Py_XDECREF(empty_tuple); |
| 836 | return -1; |
| 837 | } |
| 838 | Py_DECREF(empty_tuple); |
| 839 | return 0; |
| 840 | } |
| 841 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 842 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 843 | static int init_types(void) |
| 844 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 845 | static int initialized; |
| 846 | if (initialized) return 1; |
| 847 | if (add_ast_fields() < 0) return 0; |
| 848 | mod_type = make_type("mod", &AST_type, NULL, 0); |
| 849 | if (!mod_type) return 0; |
| 850 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 851 | Module_type = make_type("Module", mod_type, Module_fields, 2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 852 | if (!Module_type) return 0; |
| 853 | Interactive_type = make_type("Interactive", mod_type, Interactive_fields, |
| 854 | 1); |
| 855 | if (!Interactive_type) return 0; |
| 856 | Expression_type = make_type("Expression", mod_type, Expression_fields, 1); |
| 857 | if (!Expression_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 858 | FunctionType_type = make_type("FunctionType", mod_type, |
| 859 | FunctionType_fields, 2); |
| 860 | if (!FunctionType_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 861 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
| 862 | if (!Suite_type) return 0; |
| 863 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
| 864 | if (!stmt_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 865 | if (!add_attributes(stmt_type, stmt_attributes, 4)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 866 | FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 867 | 6); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 868 | if (!FunctionDef_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 869 | AsyncFunctionDef_type = make_type("AsyncFunctionDef", stmt_type, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 870 | AsyncFunctionDef_fields, 6); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 871 | if (!AsyncFunctionDef_type) return 0; |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 872 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 5); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 873 | if (!ClassDef_type) return 0; |
| 874 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
| 875 | if (!Return_type) return 0; |
| 876 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
| 877 | if (!Delete_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 878 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 879 | if (!Assign_type) return 0; |
| 880 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
| 881 | if (!AugAssign_type) return 0; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 882 | AnnAssign_type = make_type("AnnAssign", stmt_type, AnnAssign_fields, 4); |
| 883 | if (!AnnAssign_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 884 | For_type = make_type("For", stmt_type, For_fields, 5); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 885 | if (!For_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 886 | AsyncFor_type = make_type("AsyncFor", stmt_type, AsyncFor_fields, 5); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 887 | if (!AsyncFor_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 888 | While_type = make_type("While", stmt_type, While_fields, 3); |
| 889 | if (!While_type) return 0; |
| 890 | If_type = make_type("If", stmt_type, If_fields, 3); |
| 891 | if (!If_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 892 | With_type = make_type("With", stmt_type, With_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 893 | if (!With_type) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 894 | AsyncWith_type = make_type("AsyncWith", stmt_type, AsyncWith_fields, 3); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 895 | if (!AsyncWith_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 896 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
| 897 | if (!Raise_type) return 0; |
| 898 | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
| 899 | if (!Try_type) return 0; |
| 900 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
| 901 | if (!Assert_type) return 0; |
| 902 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
| 903 | if (!Import_type) return 0; |
| 904 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, 3); |
| 905 | if (!ImportFrom_type) return 0; |
| 906 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
| 907 | if (!Global_type) return 0; |
| 908 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 909 | if (!Nonlocal_type) return 0; |
| 910 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
| 911 | if (!Expr_type) return 0; |
| 912 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
| 913 | if (!Pass_type) return 0; |
| 914 | Break_type = make_type("Break", stmt_type, NULL, 0); |
| 915 | if (!Break_type) return 0; |
| 916 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
| 917 | if (!Continue_type) return 0; |
| 918 | expr_type = make_type("expr", &AST_type, NULL, 0); |
| 919 | if (!expr_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 920 | if (!add_attributes(expr_type, expr_attributes, 4)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 921 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
| 922 | if (!BoolOp_type) return 0; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 923 | NamedExpr_type = make_type("NamedExpr", expr_type, NamedExpr_fields, 2); |
| 924 | if (!NamedExpr_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 925 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
| 926 | if (!BinOp_type) return 0; |
| 927 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
| 928 | if (!UnaryOp_type) return 0; |
| 929 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
| 930 | if (!Lambda_type) return 0; |
| 931 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
| 932 | if (!IfExp_type) return 0; |
| 933 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
| 934 | if (!Dict_type) return 0; |
| 935 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 936 | if (!Set_type) return 0; |
| 937 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
| 938 | if (!ListComp_type) return 0; |
| 939 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 940 | if (!SetComp_type) return 0; |
| 941 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 942 | if (!DictComp_type) return 0; |
| 943 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 944 | GeneratorExp_fields, 2); |
| 945 | if (!GeneratorExp_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 946 | Await_type = make_type("Await", expr_type, Await_fields, 1); |
| 947 | if (!Await_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 948 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
| 949 | if (!Yield_type) return 0; |
| 950 | YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); |
| 951 | if (!YieldFrom_type) return 0; |
| 952 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
| 953 | if (!Compare_type) return 0; |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 954 | Call_type = make_type("Call", expr_type, Call_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 955 | if (!Call_type) return 0; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 956 | FormattedValue_type = make_type("FormattedValue", expr_type, |
Eric V. Smith | 9a4135e | 2019-05-08 16:28:48 -0400 | [diff] [blame] | 957 | FormattedValue_fields, 4); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 958 | if (!FormattedValue_type) return 0; |
| 959 | JoinedStr_type = make_type("JoinedStr", expr_type, JoinedStr_fields, 1); |
| 960 | if (!JoinedStr_type) return 0; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 961 | Constant_type = make_type("Constant", expr_type, Constant_fields, 2); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 962 | if (!Constant_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 963 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
| 964 | if (!Attribute_type) return 0; |
| 965 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
| 966 | if (!Subscript_type) return 0; |
| 967 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 968 | if (!Starred_type) return 0; |
| 969 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
| 970 | if (!Name_type) return 0; |
| 971 | List_type = make_type("List", expr_type, List_fields, 2); |
| 972 | if (!List_type) return 0; |
| 973 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
| 974 | if (!Tuple_type) return 0; |
| 975 | expr_context_type = make_type("expr_context", &AST_type, NULL, 0); |
| 976 | if (!expr_context_type) return 0; |
| 977 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
| 978 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
| 979 | if (!Load_type) return 0; |
| 980 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
| 981 | if (!Load_singleton) return 0; |
| 982 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
| 983 | if (!Store_type) return 0; |
| 984 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
| 985 | if (!Store_singleton) return 0; |
| 986 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
| 987 | if (!Del_type) return 0; |
| 988 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
| 989 | if (!Del_singleton) return 0; |
| 990 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
| 991 | if (!AugLoad_type) return 0; |
| 992 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
| 993 | if (!AugLoad_singleton) return 0; |
| 994 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
| 995 | if (!AugStore_type) return 0; |
| 996 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
| 997 | if (!AugStore_singleton) return 0; |
| 998 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
| 999 | if (!Param_type) return 0; |
| 1000 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
| 1001 | if (!Param_singleton) return 0; |
| 1002 | slice_type = make_type("slice", &AST_type, NULL, 0); |
| 1003 | if (!slice_type) return 0; |
| 1004 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
| 1005 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
| 1006 | if (!Slice_type) return 0; |
| 1007 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
| 1008 | if (!ExtSlice_type) return 0; |
| 1009 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
| 1010 | if (!Index_type) return 0; |
| 1011 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
| 1012 | if (!boolop_type) return 0; |
| 1013 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
| 1014 | And_type = make_type("And", boolop_type, NULL, 0); |
| 1015 | if (!And_type) return 0; |
| 1016 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
| 1017 | if (!And_singleton) return 0; |
| 1018 | Or_type = make_type("Or", boolop_type, NULL, 0); |
| 1019 | if (!Or_type) return 0; |
| 1020 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
| 1021 | if (!Or_singleton) return 0; |
| 1022 | operator_type = make_type("operator", &AST_type, NULL, 0); |
| 1023 | if (!operator_type) return 0; |
| 1024 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
| 1025 | Add_type = make_type("Add", operator_type, NULL, 0); |
| 1026 | if (!Add_type) return 0; |
| 1027 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
| 1028 | if (!Add_singleton) return 0; |
| 1029 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
| 1030 | if (!Sub_type) return 0; |
| 1031 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
| 1032 | if (!Sub_singleton) return 0; |
| 1033 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
| 1034 | if (!Mult_type) return 0; |
| 1035 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
| 1036 | if (!Mult_singleton) return 0; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 1037 | MatMult_type = make_type("MatMult", operator_type, NULL, 0); |
| 1038 | if (!MatMult_type) return 0; |
| 1039 | MatMult_singleton = PyType_GenericNew(MatMult_type, NULL, NULL); |
| 1040 | if (!MatMult_singleton) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1041 | Div_type = make_type("Div", operator_type, NULL, 0); |
| 1042 | if (!Div_type) return 0; |
| 1043 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
| 1044 | if (!Div_singleton) return 0; |
| 1045 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
| 1046 | if (!Mod_type) return 0; |
| 1047 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
| 1048 | if (!Mod_singleton) return 0; |
| 1049 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
| 1050 | if (!Pow_type) return 0; |
| 1051 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
| 1052 | if (!Pow_singleton) return 0; |
| 1053 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
| 1054 | if (!LShift_type) return 0; |
| 1055 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
| 1056 | if (!LShift_singleton) return 0; |
| 1057 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
| 1058 | if (!RShift_type) return 0; |
| 1059 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
| 1060 | if (!RShift_singleton) return 0; |
| 1061 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
| 1062 | if (!BitOr_type) return 0; |
| 1063 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
| 1064 | if (!BitOr_singleton) return 0; |
| 1065 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
| 1066 | if (!BitXor_type) return 0; |
| 1067 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
| 1068 | if (!BitXor_singleton) return 0; |
| 1069 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
| 1070 | if (!BitAnd_type) return 0; |
| 1071 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
| 1072 | if (!BitAnd_singleton) return 0; |
| 1073 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
| 1074 | if (!FloorDiv_type) return 0; |
| 1075 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
| 1076 | if (!FloorDiv_singleton) return 0; |
| 1077 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
| 1078 | if (!unaryop_type) return 0; |
| 1079 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
| 1080 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
| 1081 | if (!Invert_type) return 0; |
| 1082 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
| 1083 | if (!Invert_singleton) return 0; |
| 1084 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
| 1085 | if (!Not_type) return 0; |
| 1086 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
| 1087 | if (!Not_singleton) return 0; |
| 1088 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
| 1089 | if (!UAdd_type) return 0; |
| 1090 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
| 1091 | if (!UAdd_singleton) return 0; |
| 1092 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
| 1093 | if (!USub_type) return 0; |
| 1094 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
| 1095 | if (!USub_singleton) return 0; |
| 1096 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
| 1097 | if (!cmpop_type) return 0; |
| 1098 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
| 1099 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
| 1100 | if (!Eq_type) return 0; |
| 1101 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
| 1102 | if (!Eq_singleton) return 0; |
| 1103 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
| 1104 | if (!NotEq_type) return 0; |
| 1105 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
| 1106 | if (!NotEq_singleton) return 0; |
| 1107 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
| 1108 | if (!Lt_type) return 0; |
| 1109 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
| 1110 | if (!Lt_singleton) return 0; |
| 1111 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
| 1112 | if (!LtE_type) return 0; |
| 1113 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
| 1114 | if (!LtE_singleton) return 0; |
| 1115 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
| 1116 | if (!Gt_type) return 0; |
| 1117 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
| 1118 | if (!Gt_singleton) return 0; |
| 1119 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
| 1120 | if (!GtE_type) return 0; |
| 1121 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
| 1122 | if (!GtE_singleton) return 0; |
| 1123 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
| 1124 | if (!Is_type) return 0; |
| 1125 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
| 1126 | if (!Is_singleton) return 0; |
| 1127 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
| 1128 | if (!IsNot_type) return 0; |
| 1129 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
| 1130 | if (!IsNot_singleton) return 0; |
| 1131 | In_type = make_type("In", cmpop_type, NULL, 0); |
| 1132 | if (!In_type) return 0; |
| 1133 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
| 1134 | if (!In_singleton) return 0; |
| 1135 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
| 1136 | if (!NotIn_type) return 0; |
| 1137 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
| 1138 | if (!NotIn_singleton) return 0; |
| 1139 | comprehension_type = make_type("comprehension", &AST_type, |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 1140 | comprehension_fields, 4); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1141 | if (!comprehension_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1142 | if (!add_attributes(comprehension_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1143 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
| 1144 | if (!excepthandler_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1145 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 4)) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1146 | return 0; |
| 1147 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 1148 | ExceptHandler_fields, 3); |
| 1149 | if (!ExceptHandler_type) return 0; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 1150 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 7); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1151 | if (!arguments_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1152 | if (!add_attributes(arguments_type, NULL, 0)) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1153 | arg_type = make_type("arg", &AST_type, arg_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1154 | if (!arg_type) return 0; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1155 | if (!add_attributes(arg_type, arg_attributes, 4)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1156 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
| 1157 | if (!keyword_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1158 | if (!add_attributes(keyword_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1159 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
| 1160 | if (!alias_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1161 | if (!add_attributes(alias_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1162 | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
| 1163 | if (!withitem_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1164 | if (!add_attributes(withitem_type, NULL, 0)) return 0; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1165 | type_ignore_type = make_type("type_ignore", &AST_type, NULL, 0); |
| 1166 | if (!type_ignore_type) return 0; |
| 1167 | if (!add_attributes(type_ignore_type, NULL, 0)) return 0; |
| 1168 | TypeIgnore_type = make_type("TypeIgnore", type_ignore_type, |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 1169 | TypeIgnore_fields, 2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1170 | if (!TypeIgnore_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1171 | initialized = 1; |
| 1172 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1173 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1174 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1175 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1176 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1177 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1178 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1179 | arena); |
| 1180 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1181 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1182 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1183 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1184 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1185 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1186 | arena); |
| 1187 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1188 | arena); |
| 1189 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1190 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1191 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1192 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1193 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1194 | static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* |
| 1195 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1196 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1197 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1198 | Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1199 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1200 | mod_ty p; |
| 1201 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1202 | if (!p) |
| 1203 | return NULL; |
| 1204 | p->kind = Module_kind; |
| 1205 | p->v.Module.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1206 | p->v.Module.type_ignores = type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1207 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1211 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1212 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1213 | mod_ty p; |
| 1214 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1215 | if (!p) |
| 1216 | return NULL; |
| 1217 | p->kind = Interactive_kind; |
| 1218 | p->v.Interactive.body = body; |
| 1219 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1223 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1224 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1225 | mod_ty p; |
| 1226 | if (!body) { |
| 1227 | PyErr_SetString(PyExc_ValueError, |
| 1228 | "field body is required for Expression"); |
| 1229 | return NULL; |
| 1230 | } |
| 1231 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1232 | if (!p) |
| 1233 | return NULL; |
| 1234 | p->kind = Expression_kind; |
| 1235 | p->v.Expression.body = body; |
| 1236 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1240 | FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena) |
| 1241 | { |
| 1242 | mod_ty p; |
| 1243 | if (!returns) { |
| 1244 | PyErr_SetString(PyExc_ValueError, |
| 1245 | "field returns is required for FunctionType"); |
| 1246 | return NULL; |
| 1247 | } |
| 1248 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1249 | if (!p) |
| 1250 | return NULL; |
| 1251 | p->kind = FunctionType_kind; |
| 1252 | p->v.FunctionType.argtypes = argtypes; |
| 1253 | p->v.FunctionType.returns = returns; |
| 1254 | return p; |
| 1255 | } |
| 1256 | |
| 1257 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1258 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1259 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1260 | mod_ty p; |
| 1261 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1262 | if (!p) |
| 1263 | return NULL; |
| 1264 | p->kind = Suite_kind; |
| 1265 | p->v.Suite.body = body; |
| 1266 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | stmt_ty |
| 1270 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1271 | decorator_list, expr_ty returns, string type_comment, int lineno, |
| 1272 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1273 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1274 | stmt_ty p; |
| 1275 | if (!name) { |
| 1276 | PyErr_SetString(PyExc_ValueError, |
| 1277 | "field name is required for FunctionDef"); |
| 1278 | return NULL; |
| 1279 | } |
| 1280 | if (!args) { |
| 1281 | PyErr_SetString(PyExc_ValueError, |
| 1282 | "field args is required for FunctionDef"); |
| 1283 | return NULL; |
| 1284 | } |
| 1285 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1286 | if (!p) |
| 1287 | return NULL; |
| 1288 | p->kind = FunctionDef_kind; |
| 1289 | p->v.FunctionDef.name = name; |
| 1290 | p->v.FunctionDef.args = args; |
| 1291 | p->v.FunctionDef.body = body; |
| 1292 | p->v.FunctionDef.decorator_list = decorator_list; |
| 1293 | p->v.FunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1294 | p->v.FunctionDef.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1295 | p->lineno = lineno; |
| 1296 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1297 | p->end_lineno = end_lineno; |
| 1298 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1299 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1303 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1304 | * decorator_list, expr_ty returns, string type_comment, int |
| 1305 | lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1306 | PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1307 | { |
| 1308 | stmt_ty p; |
| 1309 | if (!name) { |
| 1310 | PyErr_SetString(PyExc_ValueError, |
| 1311 | "field name is required for AsyncFunctionDef"); |
| 1312 | return NULL; |
| 1313 | } |
| 1314 | if (!args) { |
| 1315 | PyErr_SetString(PyExc_ValueError, |
| 1316 | "field args is required for AsyncFunctionDef"); |
| 1317 | return NULL; |
| 1318 | } |
| 1319 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1320 | if (!p) |
| 1321 | return NULL; |
| 1322 | p->kind = AsyncFunctionDef_kind; |
| 1323 | p->v.AsyncFunctionDef.name = name; |
| 1324 | p->v.AsyncFunctionDef.args = args; |
| 1325 | p->v.AsyncFunctionDef.body = body; |
| 1326 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 1327 | p->v.AsyncFunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1328 | p->v.AsyncFunctionDef.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1329 | p->lineno = lineno; |
| 1330 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1331 | p->end_lineno = end_lineno; |
| 1332 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1333 | return p; |
| 1334 | } |
| 1335 | |
| 1336 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 1337 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1338 | body, asdl_seq * decorator_list, int lineno, int col_offset, int |
| 1339 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1340 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1341 | stmt_ty p; |
| 1342 | if (!name) { |
| 1343 | PyErr_SetString(PyExc_ValueError, |
| 1344 | "field name is required for ClassDef"); |
| 1345 | return NULL; |
| 1346 | } |
| 1347 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1348 | if (!p) |
| 1349 | return NULL; |
| 1350 | p->kind = ClassDef_kind; |
| 1351 | p->v.ClassDef.name = name; |
| 1352 | p->v.ClassDef.bases = bases; |
| 1353 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1354 | p->v.ClassDef.body = body; |
| 1355 | p->v.ClassDef.decorator_list = decorator_list; |
| 1356 | p->lineno = lineno; |
| 1357 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1358 | p->end_lineno = end_lineno; |
| 1359 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1360 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1364 | Return(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 1365 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1366 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1367 | stmt_ty p; |
| 1368 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1369 | if (!p) |
| 1370 | return NULL; |
| 1371 | p->kind = Return_kind; |
| 1372 | p->v.Return.value = value; |
| 1373 | p->lineno = lineno; |
| 1374 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1375 | p->end_lineno = end_lineno; |
| 1376 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1377 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1381 | Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int |
| 1382 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1383 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1384 | stmt_ty p; |
| 1385 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1386 | if (!p) |
| 1387 | return NULL; |
| 1388 | p->kind = Delete_kind; |
| 1389 | p->v.Delete.targets = targets; |
| 1390 | p->lineno = lineno; |
| 1391 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1392 | p->end_lineno = end_lineno; |
| 1393 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1394 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1398 | Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int |
| 1399 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1400 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1401 | stmt_ty p; |
| 1402 | if (!value) { |
| 1403 | PyErr_SetString(PyExc_ValueError, |
| 1404 | "field value is required for Assign"); |
| 1405 | return NULL; |
| 1406 | } |
| 1407 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1408 | if (!p) |
| 1409 | return NULL; |
| 1410 | p->kind = Assign_kind; |
| 1411 | p->v.Assign.targets = targets; |
| 1412 | p->v.Assign.value = value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1413 | p->v.Assign.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1414 | p->lineno = lineno; |
| 1415 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1416 | p->end_lineno = end_lineno; |
| 1417 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1418 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1422 | 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] | 1423 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1424 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1425 | stmt_ty p; |
| 1426 | if (!target) { |
| 1427 | PyErr_SetString(PyExc_ValueError, |
| 1428 | "field target is required for AugAssign"); |
| 1429 | return NULL; |
| 1430 | } |
| 1431 | if (!op) { |
| 1432 | PyErr_SetString(PyExc_ValueError, |
| 1433 | "field op is required for AugAssign"); |
| 1434 | return NULL; |
| 1435 | } |
| 1436 | if (!value) { |
| 1437 | PyErr_SetString(PyExc_ValueError, |
| 1438 | "field value is required for AugAssign"); |
| 1439 | return NULL; |
| 1440 | } |
| 1441 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1442 | if (!p) |
| 1443 | return NULL; |
| 1444 | p->kind = AugAssign_kind; |
| 1445 | p->v.AugAssign.target = target; |
| 1446 | p->v.AugAssign.op = op; |
| 1447 | p->v.AugAssign.value = value; |
| 1448 | p->lineno = lineno; |
| 1449 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1450 | p->end_lineno = end_lineno; |
| 1451 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1452 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 1456 | 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] | 1457 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1458 | *arena) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 1459 | { |
| 1460 | stmt_ty p; |
| 1461 | if (!target) { |
| 1462 | PyErr_SetString(PyExc_ValueError, |
| 1463 | "field target is required for AnnAssign"); |
| 1464 | return NULL; |
| 1465 | } |
| 1466 | if (!annotation) { |
| 1467 | PyErr_SetString(PyExc_ValueError, |
| 1468 | "field annotation is required for AnnAssign"); |
| 1469 | return NULL; |
| 1470 | } |
| 1471 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1472 | if (!p) |
| 1473 | return NULL; |
| 1474 | p->kind = AnnAssign_kind; |
| 1475 | p->v.AnnAssign.target = target; |
| 1476 | p->v.AnnAssign.annotation = annotation; |
| 1477 | p->v.AnnAssign.value = value; |
| 1478 | p->v.AnnAssign.simple = simple; |
| 1479 | p->lineno = lineno; |
| 1480 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1481 | p->end_lineno = end_lineno; |
| 1482 | p->end_col_offset = end_col_offset; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 1483 | return p; |
| 1484 | } |
| 1485 | |
| 1486 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1487 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string |
| 1488 | type_comment, int lineno, int col_offset, int end_lineno, int |
| 1489 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1490 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1491 | stmt_ty p; |
| 1492 | if (!target) { |
| 1493 | PyErr_SetString(PyExc_ValueError, |
| 1494 | "field target is required for For"); |
| 1495 | return NULL; |
| 1496 | } |
| 1497 | if (!iter) { |
| 1498 | PyErr_SetString(PyExc_ValueError, |
| 1499 | "field iter is required for For"); |
| 1500 | return NULL; |
| 1501 | } |
| 1502 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1503 | if (!p) |
| 1504 | return NULL; |
| 1505 | p->kind = For_kind; |
| 1506 | p->v.For.target = target; |
| 1507 | p->v.For.iter = iter; |
| 1508 | p->v.For.body = body; |
| 1509 | p->v.For.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1510 | p->v.For.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1511 | p->lineno = lineno; |
| 1512 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1513 | p->end_lineno = end_lineno; |
| 1514 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1515 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1519 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, |
| 1520 | string type_comment, int lineno, int col_offset, int end_lineno, int |
| 1521 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1522 | { |
| 1523 | stmt_ty p; |
| 1524 | if (!target) { |
| 1525 | PyErr_SetString(PyExc_ValueError, |
| 1526 | "field target is required for AsyncFor"); |
| 1527 | return NULL; |
| 1528 | } |
| 1529 | if (!iter) { |
| 1530 | PyErr_SetString(PyExc_ValueError, |
| 1531 | "field iter is required for AsyncFor"); |
| 1532 | return NULL; |
| 1533 | } |
| 1534 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1535 | if (!p) |
| 1536 | return NULL; |
| 1537 | p->kind = AsyncFor_kind; |
| 1538 | p->v.AsyncFor.target = target; |
| 1539 | p->v.AsyncFor.iter = iter; |
| 1540 | p->v.AsyncFor.body = body; |
| 1541 | p->v.AsyncFor.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1542 | p->v.AsyncFor.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1543 | p->lineno = lineno; |
| 1544 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1545 | p->end_lineno = end_lineno; |
| 1546 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1547 | return p; |
| 1548 | } |
| 1549 | |
| 1550 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1551 | 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] | 1552 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1553 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1554 | stmt_ty p; |
| 1555 | if (!test) { |
| 1556 | PyErr_SetString(PyExc_ValueError, |
| 1557 | "field test is required for While"); |
| 1558 | return NULL; |
| 1559 | } |
| 1560 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1561 | if (!p) |
| 1562 | return NULL; |
| 1563 | p->kind = While_kind; |
| 1564 | p->v.While.test = test; |
| 1565 | p->v.While.body = body; |
| 1566 | p->v.While.orelse = orelse; |
| 1567 | p->lineno = lineno; |
| 1568 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1569 | p->end_lineno = end_lineno; |
| 1570 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1571 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1575 | 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] | 1576 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1577 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1578 | stmt_ty p; |
| 1579 | if (!test) { |
| 1580 | PyErr_SetString(PyExc_ValueError, |
| 1581 | "field test is required for If"); |
| 1582 | return NULL; |
| 1583 | } |
| 1584 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1585 | if (!p) |
| 1586 | return NULL; |
| 1587 | p->kind = If_kind; |
| 1588 | p->v.If.test = test; |
| 1589 | p->v.If.body = body; |
| 1590 | p->v.If.orelse = orelse; |
| 1591 | p->lineno = lineno; |
| 1592 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1593 | p->end_lineno = end_lineno; |
| 1594 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1595 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1599 | With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int |
| 1600 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1601 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1602 | stmt_ty p; |
| 1603 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1604 | if (!p) |
| 1605 | return NULL; |
| 1606 | p->kind = With_kind; |
| 1607 | p->v.With.items = items; |
| 1608 | p->v.With.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1609 | p->v.With.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1610 | p->lineno = lineno; |
| 1611 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1612 | p->end_lineno = end_lineno; |
| 1613 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1614 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1618 | AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, |
| 1619 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1620 | { |
| 1621 | stmt_ty p; |
| 1622 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1623 | if (!p) |
| 1624 | return NULL; |
| 1625 | p->kind = AsyncWith_kind; |
| 1626 | p->v.AsyncWith.items = items; |
| 1627 | p->v.AsyncWith.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1628 | p->v.AsyncWith.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1629 | p->lineno = lineno; |
| 1630 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1631 | p->end_lineno = end_lineno; |
| 1632 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1633 | return p; |
| 1634 | } |
| 1635 | |
| 1636 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1637 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, |
| 1638 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1639 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1640 | stmt_ty p; |
| 1641 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1642 | if (!p) |
| 1643 | return NULL; |
| 1644 | p->kind = Raise_kind; |
| 1645 | p->v.Raise.exc = exc; |
| 1646 | p->v.Raise.cause = cause; |
| 1647 | p->lineno = lineno; |
| 1648 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1649 | p->end_lineno = end_lineno; |
| 1650 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1651 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1655 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1656 | finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1657 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1658 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1659 | stmt_ty p; |
| 1660 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1661 | if (!p) |
| 1662 | return NULL; |
| 1663 | p->kind = Try_kind; |
| 1664 | p->v.Try.body = body; |
| 1665 | p->v.Try.handlers = handlers; |
| 1666 | p->v.Try.orelse = orelse; |
| 1667 | p->v.Try.finalbody = finalbody; |
| 1668 | p->lineno = lineno; |
| 1669 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1670 | p->end_lineno = end_lineno; |
| 1671 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1672 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1676 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, |
| 1677 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1678 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1679 | stmt_ty p; |
| 1680 | if (!test) { |
| 1681 | PyErr_SetString(PyExc_ValueError, |
| 1682 | "field test is required for Assert"); |
| 1683 | return NULL; |
| 1684 | } |
| 1685 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1686 | if (!p) |
| 1687 | return NULL; |
| 1688 | p->kind = Assert_kind; |
| 1689 | p->v.Assert.test = test; |
| 1690 | p->v.Assert.msg = msg; |
| 1691 | p->lineno = lineno; |
| 1692 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1693 | p->end_lineno = end_lineno; |
| 1694 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1695 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1699 | Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 1700 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1701 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1702 | stmt_ty p; |
| 1703 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1704 | if (!p) |
| 1705 | return NULL; |
| 1706 | p->kind = Import_kind; |
| 1707 | p->v.Import.names = names; |
| 1708 | p->lineno = lineno; |
| 1709 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1710 | p->end_lineno = end_lineno; |
| 1711 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1712 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1716 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1717 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1718 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1719 | stmt_ty p; |
| 1720 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1721 | if (!p) |
| 1722 | return NULL; |
| 1723 | p->kind = ImportFrom_kind; |
| 1724 | p->v.ImportFrom.module = module; |
| 1725 | p->v.ImportFrom.names = names; |
| 1726 | p->v.ImportFrom.level = level; |
| 1727 | p->lineno = lineno; |
| 1728 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1729 | p->end_lineno = end_lineno; |
| 1730 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1731 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1735 | Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 1736 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1737 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1738 | stmt_ty p; |
| 1739 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1740 | if (!p) |
| 1741 | return NULL; |
| 1742 | p->kind = Global_kind; |
| 1743 | p->v.Global.names = names; |
| 1744 | p->lineno = lineno; |
| 1745 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1746 | p->end_lineno = end_lineno; |
| 1747 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1748 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1752 | Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 1753 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1754 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1755 | stmt_ty p; |
| 1756 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1757 | if (!p) |
| 1758 | return NULL; |
| 1759 | p->kind = Nonlocal_kind; |
| 1760 | p->v.Nonlocal.names = names; |
| 1761 | p->lineno = lineno; |
| 1762 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1763 | p->end_lineno = end_lineno; |
| 1764 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1765 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1769 | Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 1770 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1771 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1772 | stmt_ty p; |
| 1773 | if (!value) { |
| 1774 | PyErr_SetString(PyExc_ValueError, |
| 1775 | "field value is required for Expr"); |
| 1776 | return NULL; |
| 1777 | } |
| 1778 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1779 | if (!p) |
| 1780 | return NULL; |
| 1781 | p->kind = Expr_kind; |
| 1782 | p->v.Expr.value = value; |
| 1783 | p->lineno = lineno; |
| 1784 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1785 | p->end_lineno = end_lineno; |
| 1786 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1787 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1791 | Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1792 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1793 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1794 | stmt_ty p; |
| 1795 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1796 | if (!p) |
| 1797 | return NULL; |
| 1798 | p->kind = Pass_kind; |
| 1799 | p->lineno = lineno; |
| 1800 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1801 | p->end_lineno = end_lineno; |
| 1802 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1803 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1807 | Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 1808 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1809 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1810 | stmt_ty p; |
| 1811 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1812 | if (!p) |
| 1813 | return NULL; |
| 1814 | p->kind = Break_kind; |
| 1815 | p->lineno = lineno; |
| 1816 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1817 | p->end_lineno = end_lineno; |
| 1818 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1819 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1823 | Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1824 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1825 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1826 | stmt_ty p; |
| 1827 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1828 | if (!p) |
| 1829 | return NULL; |
| 1830 | p->kind = Continue_kind; |
| 1831 | p->lineno = lineno; |
| 1832 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1833 | p->end_lineno = end_lineno; |
| 1834 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1835 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1839 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int |
| 1840 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1841 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1842 | expr_ty p; |
| 1843 | if (!op) { |
| 1844 | PyErr_SetString(PyExc_ValueError, |
| 1845 | "field op is required for BoolOp"); |
| 1846 | return NULL; |
| 1847 | } |
| 1848 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1849 | if (!p) |
| 1850 | return NULL; |
| 1851 | p->kind = BoolOp_kind; |
| 1852 | p->v.BoolOp.op = op; |
| 1853 | p->v.BoolOp.values = values; |
| 1854 | p->lineno = lineno; |
| 1855 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1856 | p->end_lineno = end_lineno; |
| 1857 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1858 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | expr_ty |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 1862 | NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int |
| 1863 | end_lineno, int end_col_offset, PyArena *arena) |
| 1864 | { |
| 1865 | expr_ty p; |
| 1866 | if (!target) { |
| 1867 | PyErr_SetString(PyExc_ValueError, |
| 1868 | "field target is required for NamedExpr"); |
| 1869 | return NULL; |
| 1870 | } |
| 1871 | if (!value) { |
| 1872 | PyErr_SetString(PyExc_ValueError, |
| 1873 | "field value is required for NamedExpr"); |
| 1874 | return NULL; |
| 1875 | } |
| 1876 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1877 | if (!p) |
| 1878 | return NULL; |
| 1879 | p->kind = NamedExpr_kind; |
| 1880 | p->v.NamedExpr.target = target; |
| 1881 | p->v.NamedExpr.value = value; |
| 1882 | p->lineno = lineno; |
| 1883 | p->col_offset = col_offset; |
| 1884 | p->end_lineno = end_lineno; |
| 1885 | p->end_col_offset = end_col_offset; |
| 1886 | return p; |
| 1887 | } |
| 1888 | |
| 1889 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1890 | 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] | 1891 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1892 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1893 | expr_ty p; |
| 1894 | if (!left) { |
| 1895 | PyErr_SetString(PyExc_ValueError, |
| 1896 | "field left is required for BinOp"); |
| 1897 | return NULL; |
| 1898 | } |
| 1899 | if (!op) { |
| 1900 | PyErr_SetString(PyExc_ValueError, |
| 1901 | "field op is required for BinOp"); |
| 1902 | return NULL; |
| 1903 | } |
| 1904 | if (!right) { |
| 1905 | PyErr_SetString(PyExc_ValueError, |
| 1906 | "field right is required for BinOp"); |
| 1907 | return NULL; |
| 1908 | } |
| 1909 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1910 | if (!p) |
| 1911 | return NULL; |
| 1912 | p->kind = BinOp_kind; |
| 1913 | p->v.BinOp.left = left; |
| 1914 | p->v.BinOp.op = op; |
| 1915 | p->v.BinOp.right = right; |
| 1916 | p->lineno = lineno; |
| 1917 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1918 | p->end_lineno = end_lineno; |
| 1919 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1920 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1921 | } |
| 1922 | |
| 1923 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1924 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int |
| 1925 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1926 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1927 | expr_ty p; |
| 1928 | if (!op) { |
| 1929 | PyErr_SetString(PyExc_ValueError, |
| 1930 | "field op is required for UnaryOp"); |
| 1931 | return NULL; |
| 1932 | } |
| 1933 | if (!operand) { |
| 1934 | PyErr_SetString(PyExc_ValueError, |
| 1935 | "field operand is required for UnaryOp"); |
| 1936 | return NULL; |
| 1937 | } |
| 1938 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1939 | if (!p) |
| 1940 | return NULL; |
| 1941 | p->kind = UnaryOp_kind; |
| 1942 | p->v.UnaryOp.op = op; |
| 1943 | p->v.UnaryOp.operand = operand; |
| 1944 | p->lineno = lineno; |
| 1945 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1946 | p->end_lineno = end_lineno; |
| 1947 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1948 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1952 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int |
| 1953 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1954 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1955 | expr_ty p; |
| 1956 | if (!args) { |
| 1957 | PyErr_SetString(PyExc_ValueError, |
| 1958 | "field args is required for Lambda"); |
| 1959 | return NULL; |
| 1960 | } |
| 1961 | if (!body) { |
| 1962 | PyErr_SetString(PyExc_ValueError, |
| 1963 | "field body is required for Lambda"); |
| 1964 | return NULL; |
| 1965 | } |
| 1966 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1967 | if (!p) |
| 1968 | return NULL; |
| 1969 | p->kind = Lambda_kind; |
| 1970 | p->v.Lambda.args = args; |
| 1971 | p->v.Lambda.body = body; |
| 1972 | p->lineno = lineno; |
| 1973 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1974 | p->end_lineno = end_lineno; |
| 1975 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1976 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1980 | 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] | 1981 | int end_lineno, int end_col_offset, PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1982 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1983 | expr_ty p; |
| 1984 | if (!test) { |
| 1985 | PyErr_SetString(PyExc_ValueError, |
| 1986 | "field test is required for IfExp"); |
| 1987 | return NULL; |
| 1988 | } |
| 1989 | if (!body) { |
| 1990 | PyErr_SetString(PyExc_ValueError, |
| 1991 | "field body is required for IfExp"); |
| 1992 | return NULL; |
| 1993 | } |
| 1994 | if (!orelse) { |
| 1995 | PyErr_SetString(PyExc_ValueError, |
| 1996 | "field orelse is required for IfExp"); |
| 1997 | return NULL; |
| 1998 | } |
| 1999 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2000 | if (!p) |
| 2001 | return NULL; |
| 2002 | p->kind = IfExp_kind; |
| 2003 | p->v.IfExp.test = test; |
| 2004 | p->v.IfExp.body = body; |
| 2005 | p->v.IfExp.orelse = orelse; |
| 2006 | p->lineno = lineno; |
| 2007 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2008 | p->end_lineno = end_lineno; |
| 2009 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2010 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2014 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int |
| 2015 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2016 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2017 | expr_ty p; |
| 2018 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2019 | if (!p) |
| 2020 | return NULL; |
| 2021 | p->kind = Dict_kind; |
| 2022 | p->v.Dict.keys = keys; |
| 2023 | p->v.Dict.values = values; |
| 2024 | p->lineno = lineno; |
| 2025 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2026 | p->end_lineno = end_lineno; |
| 2027 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2028 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2032 | Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int |
| 2033 | end_col_offset, PyArena *arena) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2034 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2035 | expr_ty p; |
| 2036 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2037 | if (!p) |
| 2038 | return NULL; |
| 2039 | p->kind = Set_kind; |
| 2040 | p->v.Set.elts = elts; |
| 2041 | p->lineno = lineno; |
| 2042 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2043 | p->end_lineno = end_lineno; |
| 2044 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2045 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2049 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2050 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2051 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2052 | expr_ty p; |
| 2053 | if (!elt) { |
| 2054 | PyErr_SetString(PyExc_ValueError, |
| 2055 | "field elt is required for ListComp"); |
| 2056 | return NULL; |
| 2057 | } |
| 2058 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2059 | if (!p) |
| 2060 | return NULL; |
| 2061 | p->kind = ListComp_kind; |
| 2062 | p->v.ListComp.elt = elt; |
| 2063 | p->v.ListComp.generators = generators; |
| 2064 | p->lineno = lineno; |
| 2065 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2066 | p->end_lineno = end_lineno; |
| 2067 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2068 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2072 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2073 | end_lineno, int end_col_offset, PyArena *arena) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2074 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2075 | expr_ty p; |
| 2076 | if (!elt) { |
| 2077 | PyErr_SetString(PyExc_ValueError, |
| 2078 | "field elt is required for SetComp"); |
| 2079 | return NULL; |
| 2080 | } |
| 2081 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2082 | if (!p) |
| 2083 | return NULL; |
| 2084 | p->kind = SetComp_kind; |
| 2085 | p->v.SetComp.elt = elt; |
| 2086 | p->v.SetComp.generators = generators; |
| 2087 | p->lineno = lineno; |
| 2088 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2089 | p->end_lineno = end_lineno; |
| 2090 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2091 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2095 | 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] | 2096 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2097 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2098 | expr_ty p; |
| 2099 | if (!key) { |
| 2100 | PyErr_SetString(PyExc_ValueError, |
| 2101 | "field key is required for DictComp"); |
| 2102 | return NULL; |
| 2103 | } |
| 2104 | if (!value) { |
| 2105 | PyErr_SetString(PyExc_ValueError, |
| 2106 | "field value is required for DictComp"); |
| 2107 | return NULL; |
| 2108 | } |
| 2109 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2110 | if (!p) |
| 2111 | return NULL; |
| 2112 | p->kind = DictComp_kind; |
| 2113 | p->v.DictComp.key = key; |
| 2114 | p->v.DictComp.value = value; |
| 2115 | p->v.DictComp.generators = generators; |
| 2116 | p->lineno = lineno; |
| 2117 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2118 | p->end_lineno = end_lineno; |
| 2119 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2120 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2124 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2125 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2126 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2127 | expr_ty p; |
| 2128 | if (!elt) { |
| 2129 | PyErr_SetString(PyExc_ValueError, |
| 2130 | "field elt is required for GeneratorExp"); |
| 2131 | return NULL; |
| 2132 | } |
| 2133 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2134 | if (!p) |
| 2135 | return NULL; |
| 2136 | p->kind = GeneratorExp_kind; |
| 2137 | p->v.GeneratorExp.elt = elt; |
| 2138 | p->v.GeneratorExp.generators = generators; |
| 2139 | p->lineno = lineno; |
| 2140 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2141 | p->end_lineno = end_lineno; |
| 2142 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2143 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2147 | Await(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2148 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2149 | { |
| 2150 | expr_ty p; |
| 2151 | if (!value) { |
| 2152 | PyErr_SetString(PyExc_ValueError, |
| 2153 | "field value is required for Await"); |
| 2154 | return NULL; |
| 2155 | } |
| 2156 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2157 | if (!p) |
| 2158 | return NULL; |
| 2159 | p->kind = Await_kind; |
| 2160 | p->v.Await.value = value; |
| 2161 | p->lineno = lineno; |
| 2162 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2163 | p->end_lineno = end_lineno; |
| 2164 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2165 | return p; |
| 2166 | } |
| 2167 | |
| 2168 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2169 | Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2170 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2171 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2172 | expr_ty p; |
| 2173 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2174 | if (!p) |
| 2175 | return NULL; |
| 2176 | p->kind = Yield_kind; |
| 2177 | p->v.Yield.value = value; |
| 2178 | p->lineno = lineno; |
| 2179 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2180 | p->end_lineno = end_lineno; |
| 2181 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2182 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2186 | YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2187 | end_col_offset, PyArena *arena) |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2188 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2189 | expr_ty p; |
| 2190 | if (!value) { |
| 2191 | PyErr_SetString(PyExc_ValueError, |
| 2192 | "field value is required for YieldFrom"); |
| 2193 | return NULL; |
| 2194 | } |
| 2195 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2196 | if (!p) |
| 2197 | return NULL; |
| 2198 | p->kind = YieldFrom_kind; |
| 2199 | p->v.YieldFrom.value = value; |
| 2200 | p->lineno = lineno; |
| 2201 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2202 | p->end_lineno = end_lineno; |
| 2203 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2204 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2208 | 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] | 2209 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2210 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2211 | expr_ty p; |
| 2212 | if (!left) { |
| 2213 | PyErr_SetString(PyExc_ValueError, |
| 2214 | "field left is required for Compare"); |
| 2215 | return NULL; |
| 2216 | } |
| 2217 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2218 | if (!p) |
| 2219 | return NULL; |
| 2220 | p->kind = Compare_kind; |
| 2221 | p->v.Compare.left = left; |
| 2222 | p->v.Compare.ops = ops; |
| 2223 | p->v.Compare.comparators = comparators; |
| 2224 | p->lineno = lineno; |
| 2225 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2226 | p->end_lineno = end_lineno; |
| 2227 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2228 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2229 | } |
| 2230 | |
| 2231 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2232 | 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] | 2233 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2234 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2235 | expr_ty p; |
| 2236 | if (!func) { |
| 2237 | PyErr_SetString(PyExc_ValueError, |
| 2238 | "field func is required for Call"); |
| 2239 | return NULL; |
| 2240 | } |
| 2241 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2242 | if (!p) |
| 2243 | return NULL; |
| 2244 | p->kind = Call_kind; |
| 2245 | p->v.Call.func = func; |
| 2246 | p->v.Call.args = args; |
| 2247 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2248 | p->lineno = lineno; |
| 2249 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2250 | p->end_lineno = end_lineno; |
| 2251 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2252 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | expr_ty |
Eric V. Smith | 9a4135e | 2019-05-08 16:28:48 -0400 | [diff] [blame] | 2256 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, string |
| 2257 | expr_text, int lineno, int col_offset, int end_lineno, int |
| 2258 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2259 | { |
| 2260 | expr_ty p; |
| 2261 | if (!value) { |
| 2262 | PyErr_SetString(PyExc_ValueError, |
| 2263 | "field value is required for FormattedValue"); |
| 2264 | return NULL; |
| 2265 | } |
| 2266 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2267 | if (!p) |
| 2268 | return NULL; |
| 2269 | p->kind = FormattedValue_kind; |
| 2270 | p->v.FormattedValue.value = value; |
| 2271 | p->v.FormattedValue.conversion = conversion; |
| 2272 | p->v.FormattedValue.format_spec = format_spec; |
Eric V. Smith | 9a4135e | 2019-05-08 16:28:48 -0400 | [diff] [blame] | 2273 | p->v.FormattedValue.expr_text = expr_text; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2274 | p->lineno = lineno; |
| 2275 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2276 | p->end_lineno = end_lineno; |
| 2277 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2278 | return p; |
| 2279 | } |
| 2280 | |
| 2281 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2282 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 2283 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2284 | { |
| 2285 | expr_ty p; |
| 2286 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2287 | if (!p) |
| 2288 | return NULL; |
| 2289 | p->kind = JoinedStr_kind; |
| 2290 | p->v.JoinedStr.values = values; |
| 2291 | p->lineno = lineno; |
| 2292 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2293 | p->end_lineno = end_lineno; |
| 2294 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2295 | return p; |
| 2296 | } |
| 2297 | |
| 2298 | expr_ty |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 2299 | Constant(constant value, string kind, int lineno, int col_offset, int |
| 2300 | end_lineno, int end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2301 | { |
| 2302 | expr_ty p; |
| 2303 | if (!value) { |
| 2304 | PyErr_SetString(PyExc_ValueError, |
| 2305 | "field value is required for Constant"); |
| 2306 | return NULL; |
| 2307 | } |
| 2308 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2309 | if (!p) |
| 2310 | return NULL; |
| 2311 | p->kind = Constant_kind; |
| 2312 | p->v.Constant.value = value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 2313 | p->v.Constant.kind = kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2314 | p->lineno = lineno; |
| 2315 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2316 | p->end_lineno = end_lineno; |
| 2317 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2318 | return p; |
| 2319 | } |
| 2320 | |
| 2321 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2322 | 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] | 2323 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2324 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2325 | expr_ty p; |
| 2326 | if (!value) { |
| 2327 | PyErr_SetString(PyExc_ValueError, |
| 2328 | "field value is required for Attribute"); |
| 2329 | return NULL; |
| 2330 | } |
| 2331 | if (!attr) { |
| 2332 | PyErr_SetString(PyExc_ValueError, |
| 2333 | "field attr is required for Attribute"); |
| 2334 | return NULL; |
| 2335 | } |
| 2336 | if (!ctx) { |
| 2337 | PyErr_SetString(PyExc_ValueError, |
| 2338 | "field ctx is required for Attribute"); |
| 2339 | return NULL; |
| 2340 | } |
| 2341 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2342 | if (!p) |
| 2343 | return NULL; |
| 2344 | p->kind = Attribute_kind; |
| 2345 | p->v.Attribute.value = value; |
| 2346 | p->v.Attribute.attr = attr; |
| 2347 | p->v.Attribute.ctx = ctx; |
| 2348 | p->lineno = lineno; |
| 2349 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2350 | p->end_lineno = end_lineno; |
| 2351 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2352 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2356 | 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] | 2357 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2358 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2359 | expr_ty p; |
| 2360 | if (!value) { |
| 2361 | PyErr_SetString(PyExc_ValueError, |
| 2362 | "field value is required for Subscript"); |
| 2363 | return NULL; |
| 2364 | } |
| 2365 | if (!slice) { |
| 2366 | PyErr_SetString(PyExc_ValueError, |
| 2367 | "field slice is required for Subscript"); |
| 2368 | return NULL; |
| 2369 | } |
| 2370 | if (!ctx) { |
| 2371 | PyErr_SetString(PyExc_ValueError, |
| 2372 | "field ctx is required for Subscript"); |
| 2373 | return NULL; |
| 2374 | } |
| 2375 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2376 | if (!p) |
| 2377 | return NULL; |
| 2378 | p->kind = Subscript_kind; |
| 2379 | p->v.Subscript.value = value; |
| 2380 | p->v.Subscript.slice = slice; |
| 2381 | p->v.Subscript.ctx = ctx; |
| 2382 | p->lineno = lineno; |
| 2383 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2384 | p->end_lineno = end_lineno; |
| 2385 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2386 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2390 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 2391 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2392 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2393 | expr_ty p; |
| 2394 | if (!value) { |
| 2395 | PyErr_SetString(PyExc_ValueError, |
| 2396 | "field value is required for Starred"); |
| 2397 | return NULL; |
| 2398 | } |
| 2399 | if (!ctx) { |
| 2400 | PyErr_SetString(PyExc_ValueError, |
| 2401 | "field ctx is required for Starred"); |
| 2402 | return NULL; |
| 2403 | } |
| 2404 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2405 | if (!p) |
| 2406 | return NULL; |
| 2407 | p->kind = Starred_kind; |
| 2408 | p->v.Starred.value = value; |
| 2409 | p->v.Starred.ctx = ctx; |
| 2410 | p->lineno = lineno; |
| 2411 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2412 | p->end_lineno = end_lineno; |
| 2413 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2414 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2418 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 2419 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2420 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2421 | expr_ty p; |
| 2422 | if (!id) { |
| 2423 | PyErr_SetString(PyExc_ValueError, |
| 2424 | "field id is required for Name"); |
| 2425 | return NULL; |
| 2426 | } |
| 2427 | if (!ctx) { |
| 2428 | PyErr_SetString(PyExc_ValueError, |
| 2429 | "field ctx is required for Name"); |
| 2430 | return NULL; |
| 2431 | } |
| 2432 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2433 | if (!p) |
| 2434 | return NULL; |
| 2435 | p->kind = Name_kind; |
| 2436 | p->v.Name.id = id; |
| 2437 | p->v.Name.ctx = ctx; |
| 2438 | p->lineno = lineno; |
| 2439 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2440 | p->end_lineno = end_lineno; |
| 2441 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2442 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2443 | } |
| 2444 | |
| 2445 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2446 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 2447 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2448 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2449 | expr_ty p; |
| 2450 | if (!ctx) { |
| 2451 | PyErr_SetString(PyExc_ValueError, |
| 2452 | "field ctx is required for List"); |
| 2453 | return NULL; |
| 2454 | } |
| 2455 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2456 | if (!p) |
| 2457 | return NULL; |
| 2458 | p->kind = List_kind; |
| 2459 | p->v.List.elts = elts; |
| 2460 | p->v.List.ctx = ctx; |
| 2461 | p->lineno = lineno; |
| 2462 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2463 | p->end_lineno = end_lineno; |
| 2464 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2465 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2469 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 2470 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2471 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2472 | expr_ty p; |
| 2473 | if (!ctx) { |
| 2474 | PyErr_SetString(PyExc_ValueError, |
| 2475 | "field ctx is required for Tuple"); |
| 2476 | return NULL; |
| 2477 | } |
| 2478 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2479 | if (!p) |
| 2480 | return NULL; |
| 2481 | p->kind = Tuple_kind; |
| 2482 | p->v.Tuple.elts = elts; |
| 2483 | p->v.Tuple.ctx = ctx; |
| 2484 | p->lineno = lineno; |
| 2485 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2486 | p->end_lineno = end_lineno; |
| 2487 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2488 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2492 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2493 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2494 | slice_ty p; |
| 2495 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2496 | if (!p) |
| 2497 | return NULL; |
| 2498 | p->kind = Slice_kind; |
| 2499 | p->v.Slice.lower = lower; |
| 2500 | p->v.Slice.upper = upper; |
| 2501 | p->v.Slice.step = step; |
| 2502 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2506 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2507 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2508 | slice_ty p; |
| 2509 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2510 | if (!p) |
| 2511 | return NULL; |
| 2512 | p->kind = ExtSlice_kind; |
| 2513 | p->v.ExtSlice.dims = dims; |
| 2514 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2518 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2519 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2520 | slice_ty p; |
| 2521 | if (!value) { |
| 2522 | PyErr_SetString(PyExc_ValueError, |
| 2523 | "field value is required for Index"); |
| 2524 | return NULL; |
| 2525 | } |
| 2526 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2527 | if (!p) |
| 2528 | return NULL; |
| 2529 | p->kind = Index_kind; |
| 2530 | p->v.Index.value = value; |
| 2531 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 2535 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 2536 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2537 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2538 | comprehension_ty p; |
| 2539 | if (!target) { |
| 2540 | PyErr_SetString(PyExc_ValueError, |
| 2541 | "field target is required for comprehension"); |
| 2542 | return NULL; |
| 2543 | } |
| 2544 | if (!iter) { |
| 2545 | PyErr_SetString(PyExc_ValueError, |
| 2546 | "field iter is required for comprehension"); |
| 2547 | return NULL; |
| 2548 | } |
| 2549 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2550 | if (!p) |
| 2551 | return NULL; |
| 2552 | p->target = target; |
| 2553 | p->iter = iter; |
| 2554 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 2555 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2556 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2560 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2561 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2562 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2563 | excepthandler_ty p; |
| 2564 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2565 | if (!p) |
| 2566 | return NULL; |
| 2567 | p->kind = ExceptHandler_kind; |
| 2568 | p->v.ExceptHandler.type = type; |
| 2569 | p->v.ExceptHandler.name = name; |
| 2570 | p->v.ExceptHandler.body = body; |
| 2571 | p->lineno = lineno; |
| 2572 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2573 | p->end_lineno = end_lineno; |
| 2574 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2575 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2576 | } |
| 2577 | |
| 2578 | arguments_ty |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 2579 | arguments(asdl_seq * args, asdl_seq * posonlyargs, arg_ty vararg, asdl_seq * |
| 2580 | kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq * |
| 2581 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2582 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2583 | arguments_ty p; |
| 2584 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2585 | if (!p) |
| 2586 | return NULL; |
| 2587 | p->args = args; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 2588 | p->posonlyargs = posonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2589 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2590 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2591 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 2592 | p->kwarg = kwarg; |
| 2593 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2594 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2595 | } |
| 2596 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2597 | arg_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2598 | arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int |
| 2599 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2600 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2601 | arg_ty p; |
| 2602 | if (!arg) { |
| 2603 | PyErr_SetString(PyExc_ValueError, |
| 2604 | "field arg is required for arg"); |
| 2605 | return NULL; |
| 2606 | } |
| 2607 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2608 | if (!p) |
| 2609 | return NULL; |
| 2610 | p->arg = arg; |
| 2611 | p->annotation = annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2612 | p->type_comment = type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 2613 | p->lineno = lineno; |
| 2614 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2615 | p->end_lineno = end_lineno; |
| 2616 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2617 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2618 | } |
| 2619 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2620 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2621 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2622 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2623 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2624 | if (!value) { |
| 2625 | PyErr_SetString(PyExc_ValueError, |
| 2626 | "field value is required for keyword"); |
| 2627 | return NULL; |
| 2628 | } |
| 2629 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2630 | if (!p) |
| 2631 | return NULL; |
| 2632 | p->arg = arg; |
| 2633 | p->value = value; |
| 2634 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2638 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2639 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2640 | alias_ty p; |
| 2641 | if (!name) { |
| 2642 | PyErr_SetString(PyExc_ValueError, |
| 2643 | "field name is required for alias"); |
| 2644 | return NULL; |
| 2645 | } |
| 2646 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2647 | if (!p) |
| 2648 | return NULL; |
| 2649 | p->name = name; |
| 2650 | p->asname = asname; |
| 2651 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2652 | } |
| 2653 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2654 | withitem_ty |
| 2655 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2656 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2657 | withitem_ty p; |
| 2658 | if (!context_expr) { |
| 2659 | PyErr_SetString(PyExc_ValueError, |
| 2660 | "field context_expr is required for withitem"); |
| 2661 | return NULL; |
| 2662 | } |
| 2663 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2664 | if (!p) |
| 2665 | return NULL; |
| 2666 | p->context_expr = context_expr; |
| 2667 | p->optional_vars = optional_vars; |
| 2668 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2669 | } |
| 2670 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2671 | type_ignore_ty |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 2672 | TypeIgnore(int lineno, string tag, PyArena *arena) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2673 | { |
| 2674 | type_ignore_ty p; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 2675 | if (!tag) { |
| 2676 | PyErr_SetString(PyExc_ValueError, |
| 2677 | "field tag is required for TypeIgnore"); |
| 2678 | return NULL; |
| 2679 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2680 | p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2681 | if (!p) |
| 2682 | return NULL; |
| 2683 | p->kind = TypeIgnore_kind; |
| 2684 | p->v.TypeIgnore.lineno = lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 2685 | p->v.TypeIgnore.tag = tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2686 | return p; |
| 2687 | } |
| 2688 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2689 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2690 | PyObject* |
| 2691 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2692 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2693 | mod_ty o = (mod_ty)_o; |
| 2694 | PyObject *result = NULL, *value = NULL; |
| 2695 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 2696 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2697 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2698 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2699 | switch (o->kind) { |
| 2700 | case Module_kind: |
| 2701 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2702 | if (!result) goto failed; |
| 2703 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2704 | if (!value) goto failed; |
| 2705 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2706 | goto failed; |
| 2707 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2708 | value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); |
| 2709 | if (!value) goto failed; |
| 2710 | if (_PyObject_SetAttrId(result, &PyId_type_ignores, value) == -1) |
| 2711 | goto failed; |
| 2712 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2713 | break; |
| 2714 | case Interactive_kind: |
| 2715 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2716 | if (!result) goto failed; |
| 2717 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2718 | if (!value) goto failed; |
| 2719 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2720 | goto failed; |
| 2721 | Py_DECREF(value); |
| 2722 | break; |
| 2723 | case Expression_kind: |
| 2724 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2725 | if (!result) goto failed; |
| 2726 | value = ast2obj_expr(o->v.Expression.body); |
| 2727 | if (!value) goto failed; |
| 2728 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2729 | goto failed; |
| 2730 | Py_DECREF(value); |
| 2731 | break; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2732 | case FunctionType_kind: |
| 2733 | result = PyType_GenericNew(FunctionType_type, NULL, NULL); |
| 2734 | if (!result) goto failed; |
| 2735 | value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); |
| 2736 | if (!value) goto failed; |
| 2737 | if (_PyObject_SetAttrId(result, &PyId_argtypes, value) == -1) |
| 2738 | goto failed; |
| 2739 | Py_DECREF(value); |
| 2740 | value = ast2obj_expr(o->v.FunctionType.returns); |
| 2741 | if (!value) goto failed; |
| 2742 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2743 | goto failed; |
| 2744 | Py_DECREF(value); |
| 2745 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2746 | case Suite_kind: |
| 2747 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2748 | if (!result) goto failed; |
| 2749 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2750 | if (!value) goto failed; |
| 2751 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2752 | goto failed; |
| 2753 | Py_DECREF(value); |
| 2754 | break; |
| 2755 | } |
| 2756 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2757 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2758 | Py_XDECREF(value); |
| 2759 | Py_XDECREF(result); |
| 2760 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2761 | } |
| 2762 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2763 | PyObject* |
| 2764 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2765 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2766 | stmt_ty o = (stmt_ty)_o; |
| 2767 | PyObject *result = NULL, *value = NULL; |
| 2768 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 2769 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2770 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2771 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2772 | switch (o->kind) { |
| 2773 | case FunctionDef_kind: |
| 2774 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2775 | if (!result) goto failed; |
| 2776 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2777 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2778 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2779 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2780 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2781 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2782 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2783 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2784 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2785 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2786 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2787 | if (!value) goto failed; |
| 2788 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2789 | goto failed; |
| 2790 | Py_DECREF(value); |
| 2791 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 2792 | if (!value) goto failed; |
| 2793 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2794 | goto failed; |
| 2795 | Py_DECREF(value); |
| 2796 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2797 | if (!value) goto failed; |
| 2798 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2799 | goto failed; |
| 2800 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2801 | value = ast2obj_string(o->v.FunctionDef.type_comment); |
| 2802 | if (!value) goto failed; |
| 2803 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2804 | goto failed; |
| 2805 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2806 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2807 | case AsyncFunctionDef_kind: |
| 2808 | result = PyType_GenericNew(AsyncFunctionDef_type, NULL, NULL); |
| 2809 | if (!result) goto failed; |
| 2810 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 2811 | if (!value) goto failed; |
| 2812 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2813 | goto failed; |
| 2814 | Py_DECREF(value); |
| 2815 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 2816 | if (!value) goto failed; |
| 2817 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2818 | goto failed; |
| 2819 | Py_DECREF(value); |
| 2820 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 2821 | if (!value) goto failed; |
| 2822 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2823 | goto failed; |
| 2824 | Py_DECREF(value); |
| 2825 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 2826 | ast2obj_expr); |
| 2827 | if (!value) goto failed; |
| 2828 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2829 | goto failed; |
| 2830 | Py_DECREF(value); |
| 2831 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 2832 | if (!value) goto failed; |
| 2833 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2834 | goto failed; |
| 2835 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2836 | value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); |
| 2837 | if (!value) goto failed; |
| 2838 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2839 | goto failed; |
| 2840 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2841 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2842 | case ClassDef_kind: |
| 2843 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2844 | if (!result) goto failed; |
| 2845 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2846 | if (!value) goto failed; |
| 2847 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2848 | goto failed; |
| 2849 | Py_DECREF(value); |
| 2850 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2851 | if (!value) goto failed; |
| 2852 | if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) |
| 2853 | goto failed; |
| 2854 | Py_DECREF(value); |
| 2855 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2856 | if (!value) goto failed; |
| 2857 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 2858 | goto failed; |
| 2859 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2860 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2861 | if (!value) goto failed; |
| 2862 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2863 | goto failed; |
| 2864 | Py_DECREF(value); |
| 2865 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 2866 | if (!value) goto failed; |
| 2867 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2868 | goto failed; |
| 2869 | Py_DECREF(value); |
| 2870 | break; |
| 2871 | case Return_kind: |
| 2872 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2873 | if (!result) goto failed; |
| 2874 | value = ast2obj_expr(o->v.Return.value); |
| 2875 | if (!value) goto failed; |
| 2876 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2877 | goto failed; |
| 2878 | Py_DECREF(value); |
| 2879 | break; |
| 2880 | case Delete_kind: |
| 2881 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2882 | if (!result) goto failed; |
| 2883 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2884 | if (!value) goto failed; |
| 2885 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2886 | goto failed; |
| 2887 | Py_DECREF(value); |
| 2888 | break; |
| 2889 | case Assign_kind: |
| 2890 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2891 | if (!result) goto failed; |
| 2892 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2893 | if (!value) goto failed; |
| 2894 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2895 | goto failed; |
| 2896 | Py_DECREF(value); |
| 2897 | value = ast2obj_expr(o->v.Assign.value); |
| 2898 | if (!value) goto failed; |
| 2899 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2900 | goto failed; |
| 2901 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2902 | value = ast2obj_string(o->v.Assign.type_comment); |
| 2903 | if (!value) goto failed; |
| 2904 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2905 | goto failed; |
| 2906 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2907 | break; |
| 2908 | case AugAssign_kind: |
| 2909 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2910 | if (!result) goto failed; |
| 2911 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2912 | if (!value) goto failed; |
| 2913 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2914 | goto failed; |
| 2915 | Py_DECREF(value); |
| 2916 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2917 | if (!value) goto failed; |
| 2918 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2919 | goto failed; |
| 2920 | Py_DECREF(value); |
| 2921 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2922 | if (!value) goto failed; |
| 2923 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2924 | goto failed; |
| 2925 | Py_DECREF(value); |
| 2926 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2927 | case AnnAssign_kind: |
| 2928 | result = PyType_GenericNew(AnnAssign_type, NULL, NULL); |
| 2929 | if (!result) goto failed; |
| 2930 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 2931 | if (!value) goto failed; |
| 2932 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2933 | goto failed; |
| 2934 | Py_DECREF(value); |
| 2935 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 2936 | if (!value) goto failed; |
| 2937 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 2938 | goto failed; |
| 2939 | Py_DECREF(value); |
| 2940 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 2941 | if (!value) goto failed; |
| 2942 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2943 | goto failed; |
| 2944 | Py_DECREF(value); |
| 2945 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 2946 | if (!value) goto failed; |
| 2947 | if (_PyObject_SetAttrId(result, &PyId_simple, value) == -1) |
| 2948 | goto failed; |
| 2949 | Py_DECREF(value); |
| 2950 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2951 | case For_kind: |
| 2952 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2953 | if (!result) goto failed; |
| 2954 | value = ast2obj_expr(o->v.For.target); |
| 2955 | if (!value) goto failed; |
| 2956 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2957 | goto failed; |
| 2958 | Py_DECREF(value); |
| 2959 | value = ast2obj_expr(o->v.For.iter); |
| 2960 | if (!value) goto failed; |
| 2961 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2962 | goto failed; |
| 2963 | Py_DECREF(value); |
| 2964 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2965 | if (!value) goto failed; |
| 2966 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2967 | goto failed; |
| 2968 | Py_DECREF(value); |
| 2969 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2970 | if (!value) goto failed; |
| 2971 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2972 | goto failed; |
| 2973 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2974 | value = ast2obj_string(o->v.For.type_comment); |
| 2975 | if (!value) goto failed; |
| 2976 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2977 | goto failed; |
| 2978 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2979 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2980 | case AsyncFor_kind: |
| 2981 | result = PyType_GenericNew(AsyncFor_type, NULL, NULL); |
| 2982 | if (!result) goto failed; |
| 2983 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 2984 | if (!value) goto failed; |
| 2985 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2986 | goto failed; |
| 2987 | Py_DECREF(value); |
| 2988 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 2989 | if (!value) goto failed; |
| 2990 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2991 | goto failed; |
| 2992 | Py_DECREF(value); |
| 2993 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 2994 | if (!value) goto failed; |
| 2995 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2996 | goto failed; |
| 2997 | Py_DECREF(value); |
| 2998 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 2999 | if (!value) goto failed; |
| 3000 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3001 | goto failed; |
| 3002 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3003 | value = ast2obj_string(o->v.AsyncFor.type_comment); |
| 3004 | if (!value) goto failed; |
| 3005 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 3006 | goto failed; |
| 3007 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3008 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3009 | case While_kind: |
| 3010 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 3011 | if (!result) goto failed; |
| 3012 | value = ast2obj_expr(o->v.While.test); |
| 3013 | if (!value) goto failed; |
| 3014 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3015 | goto failed; |
| 3016 | Py_DECREF(value); |
| 3017 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 3018 | if (!value) goto failed; |
| 3019 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3020 | goto failed; |
| 3021 | Py_DECREF(value); |
| 3022 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 3023 | if (!value) goto failed; |
| 3024 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3025 | goto failed; |
| 3026 | Py_DECREF(value); |
| 3027 | break; |
| 3028 | case If_kind: |
| 3029 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 3030 | if (!result) goto failed; |
| 3031 | value = ast2obj_expr(o->v.If.test); |
| 3032 | if (!value) goto failed; |
| 3033 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3034 | goto failed; |
| 3035 | Py_DECREF(value); |
| 3036 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 3037 | if (!value) goto failed; |
| 3038 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3039 | goto failed; |
| 3040 | Py_DECREF(value); |
| 3041 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 3042 | if (!value) goto failed; |
| 3043 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3044 | goto failed; |
| 3045 | Py_DECREF(value); |
| 3046 | break; |
| 3047 | case With_kind: |
| 3048 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 3049 | if (!result) goto failed; |
| 3050 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 3051 | if (!value) goto failed; |
| 3052 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 3053 | goto failed; |
| 3054 | Py_DECREF(value); |
| 3055 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 3056 | if (!value) goto failed; |
| 3057 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3058 | goto failed; |
| 3059 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3060 | value = ast2obj_string(o->v.With.type_comment); |
| 3061 | if (!value) goto failed; |
| 3062 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 3063 | goto failed; |
| 3064 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3065 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3066 | case AsyncWith_kind: |
| 3067 | result = PyType_GenericNew(AsyncWith_type, NULL, NULL); |
| 3068 | if (!result) goto failed; |
| 3069 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 3070 | if (!value) goto failed; |
| 3071 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 3072 | goto failed; |
| 3073 | Py_DECREF(value); |
| 3074 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 3075 | if (!value) goto failed; |
| 3076 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3077 | goto failed; |
| 3078 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3079 | value = ast2obj_string(o->v.AsyncWith.type_comment); |
| 3080 | if (!value) goto failed; |
| 3081 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 3082 | goto failed; |
| 3083 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3084 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3085 | case Raise_kind: |
| 3086 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 3087 | if (!result) goto failed; |
| 3088 | value = ast2obj_expr(o->v.Raise.exc); |
| 3089 | if (!value) goto failed; |
| 3090 | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
| 3091 | goto failed; |
| 3092 | Py_DECREF(value); |
| 3093 | value = ast2obj_expr(o->v.Raise.cause); |
| 3094 | if (!value) goto failed; |
| 3095 | if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) |
| 3096 | goto failed; |
| 3097 | Py_DECREF(value); |
| 3098 | break; |
| 3099 | case Try_kind: |
| 3100 | result = PyType_GenericNew(Try_type, NULL, NULL); |
| 3101 | if (!result) goto failed; |
| 3102 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 3103 | if (!value) goto failed; |
| 3104 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3105 | goto failed; |
| 3106 | Py_DECREF(value); |
| 3107 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 3108 | if (!value) goto failed; |
| 3109 | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
| 3110 | goto failed; |
| 3111 | Py_DECREF(value); |
| 3112 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 3113 | if (!value) goto failed; |
| 3114 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3115 | goto failed; |
| 3116 | Py_DECREF(value); |
| 3117 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 3118 | if (!value) goto failed; |
| 3119 | if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) |
| 3120 | goto failed; |
| 3121 | Py_DECREF(value); |
| 3122 | break; |
| 3123 | case Assert_kind: |
| 3124 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 3125 | if (!result) goto failed; |
| 3126 | value = ast2obj_expr(o->v.Assert.test); |
| 3127 | if (!value) goto failed; |
| 3128 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3129 | goto failed; |
| 3130 | Py_DECREF(value); |
| 3131 | value = ast2obj_expr(o->v.Assert.msg); |
| 3132 | if (!value) goto failed; |
| 3133 | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
| 3134 | goto failed; |
| 3135 | Py_DECREF(value); |
| 3136 | break; |
| 3137 | case Import_kind: |
| 3138 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 3139 | if (!result) goto failed; |
| 3140 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 3141 | if (!value) goto failed; |
| 3142 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3143 | goto failed; |
| 3144 | Py_DECREF(value); |
| 3145 | break; |
| 3146 | case ImportFrom_kind: |
| 3147 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 3148 | if (!result) goto failed; |
| 3149 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 3150 | if (!value) goto failed; |
| 3151 | if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) |
| 3152 | goto failed; |
| 3153 | Py_DECREF(value); |
| 3154 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 3155 | if (!value) goto failed; |
| 3156 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3157 | goto failed; |
| 3158 | Py_DECREF(value); |
| 3159 | value = ast2obj_int(o->v.ImportFrom.level); |
| 3160 | if (!value) goto failed; |
| 3161 | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
| 3162 | goto failed; |
| 3163 | Py_DECREF(value); |
| 3164 | break; |
| 3165 | case Global_kind: |
| 3166 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 3167 | if (!result) goto failed; |
| 3168 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 3169 | if (!value) goto failed; |
| 3170 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3171 | goto failed; |
| 3172 | Py_DECREF(value); |
| 3173 | break; |
| 3174 | case Nonlocal_kind: |
| 3175 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 3176 | if (!result) goto failed; |
| 3177 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 3178 | if (!value) goto failed; |
| 3179 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3180 | goto failed; |
| 3181 | Py_DECREF(value); |
| 3182 | break; |
| 3183 | case Expr_kind: |
| 3184 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 3185 | if (!result) goto failed; |
| 3186 | value = ast2obj_expr(o->v.Expr.value); |
| 3187 | if (!value) goto failed; |
| 3188 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3189 | goto failed; |
| 3190 | Py_DECREF(value); |
| 3191 | break; |
| 3192 | case Pass_kind: |
| 3193 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 3194 | if (!result) goto failed; |
| 3195 | break; |
| 3196 | case Break_kind: |
| 3197 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 3198 | if (!result) goto failed; |
| 3199 | break; |
| 3200 | case Continue_kind: |
| 3201 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 3202 | if (!result) goto failed; |
| 3203 | break; |
| 3204 | } |
| 3205 | value = ast2obj_int(o->lineno); |
| 3206 | if (!value) goto failed; |
| 3207 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3208 | goto failed; |
| 3209 | Py_DECREF(value); |
| 3210 | value = ast2obj_int(o->col_offset); |
| 3211 | if (!value) goto failed; |
| 3212 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3213 | goto failed; |
| 3214 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3215 | value = ast2obj_int(o->end_lineno); |
| 3216 | if (!value) goto failed; |
| 3217 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3218 | goto failed; |
| 3219 | Py_DECREF(value); |
| 3220 | value = ast2obj_int(o->end_col_offset); |
| 3221 | if (!value) goto failed; |
| 3222 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3223 | goto failed; |
| 3224 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3225 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3226 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3227 | Py_XDECREF(value); |
| 3228 | Py_XDECREF(result); |
| 3229 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3230 | } |
| 3231 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3232 | PyObject* |
| 3233 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3234 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3235 | expr_ty o = (expr_ty)_o; |
| 3236 | PyObject *result = NULL, *value = NULL; |
| 3237 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3238 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3239 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3240 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3241 | switch (o->kind) { |
| 3242 | case BoolOp_kind: |
| 3243 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 3244 | if (!result) goto failed; |
| 3245 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 3246 | if (!value) goto failed; |
| 3247 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3248 | goto failed; |
| 3249 | Py_DECREF(value); |
| 3250 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 3251 | if (!value) goto failed; |
| 3252 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3253 | goto failed; |
| 3254 | Py_DECREF(value); |
| 3255 | break; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3256 | case NamedExpr_kind: |
| 3257 | result = PyType_GenericNew(NamedExpr_type, NULL, NULL); |
| 3258 | if (!result) goto failed; |
| 3259 | value = ast2obj_expr(o->v.NamedExpr.target); |
| 3260 | if (!value) goto failed; |
| 3261 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 3262 | goto failed; |
| 3263 | Py_DECREF(value); |
| 3264 | value = ast2obj_expr(o->v.NamedExpr.value); |
| 3265 | if (!value) goto failed; |
| 3266 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3267 | goto failed; |
| 3268 | Py_DECREF(value); |
| 3269 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3270 | case BinOp_kind: |
| 3271 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 3272 | if (!result) goto failed; |
| 3273 | value = ast2obj_expr(o->v.BinOp.left); |
| 3274 | if (!value) goto failed; |
| 3275 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3276 | goto failed; |
| 3277 | Py_DECREF(value); |
| 3278 | value = ast2obj_operator(o->v.BinOp.op); |
| 3279 | if (!value) goto failed; |
| 3280 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3281 | goto failed; |
| 3282 | Py_DECREF(value); |
| 3283 | value = ast2obj_expr(o->v.BinOp.right); |
| 3284 | if (!value) goto failed; |
| 3285 | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
| 3286 | goto failed; |
| 3287 | Py_DECREF(value); |
| 3288 | break; |
| 3289 | case UnaryOp_kind: |
| 3290 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 3291 | if (!result) goto failed; |
| 3292 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 3293 | if (!value) goto failed; |
| 3294 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3295 | goto failed; |
| 3296 | Py_DECREF(value); |
| 3297 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 3298 | if (!value) goto failed; |
| 3299 | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
| 3300 | goto failed; |
| 3301 | Py_DECREF(value); |
| 3302 | break; |
| 3303 | case Lambda_kind: |
| 3304 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 3305 | if (!result) goto failed; |
| 3306 | value = ast2obj_arguments(o->v.Lambda.args); |
| 3307 | if (!value) goto failed; |
| 3308 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3309 | goto failed; |
| 3310 | Py_DECREF(value); |
| 3311 | value = ast2obj_expr(o->v.Lambda.body); |
| 3312 | if (!value) goto failed; |
| 3313 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3314 | goto failed; |
| 3315 | Py_DECREF(value); |
| 3316 | break; |
| 3317 | case IfExp_kind: |
| 3318 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 3319 | if (!result) goto failed; |
| 3320 | value = ast2obj_expr(o->v.IfExp.test); |
| 3321 | if (!value) goto failed; |
| 3322 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3323 | goto failed; |
| 3324 | Py_DECREF(value); |
| 3325 | value = ast2obj_expr(o->v.IfExp.body); |
| 3326 | if (!value) goto failed; |
| 3327 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3328 | goto failed; |
| 3329 | Py_DECREF(value); |
| 3330 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 3331 | if (!value) goto failed; |
| 3332 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3333 | goto failed; |
| 3334 | Py_DECREF(value); |
| 3335 | break; |
| 3336 | case Dict_kind: |
| 3337 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 3338 | if (!result) goto failed; |
| 3339 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 3340 | if (!value) goto failed; |
| 3341 | if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) |
| 3342 | goto failed; |
| 3343 | Py_DECREF(value); |
| 3344 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 3345 | if (!value) goto failed; |
| 3346 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3347 | goto failed; |
| 3348 | Py_DECREF(value); |
| 3349 | break; |
| 3350 | case Set_kind: |
| 3351 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 3352 | if (!result) goto failed; |
| 3353 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 3354 | if (!value) goto failed; |
| 3355 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3356 | goto failed; |
| 3357 | Py_DECREF(value); |
| 3358 | break; |
| 3359 | case ListComp_kind: |
| 3360 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 3361 | if (!result) goto failed; |
| 3362 | value = ast2obj_expr(o->v.ListComp.elt); |
| 3363 | if (!value) goto failed; |
| 3364 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3365 | goto failed; |
| 3366 | Py_DECREF(value); |
| 3367 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 3368 | if (!value) goto failed; |
| 3369 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3370 | goto failed; |
| 3371 | Py_DECREF(value); |
| 3372 | break; |
| 3373 | case SetComp_kind: |
| 3374 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 3375 | if (!result) goto failed; |
| 3376 | value = ast2obj_expr(o->v.SetComp.elt); |
| 3377 | if (!value) goto failed; |
| 3378 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3379 | goto failed; |
| 3380 | Py_DECREF(value); |
| 3381 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 3382 | if (!value) goto failed; |
| 3383 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3384 | goto failed; |
| 3385 | Py_DECREF(value); |
| 3386 | break; |
| 3387 | case DictComp_kind: |
| 3388 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 3389 | if (!result) goto failed; |
| 3390 | value = ast2obj_expr(o->v.DictComp.key); |
| 3391 | if (!value) goto failed; |
| 3392 | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
| 3393 | goto failed; |
| 3394 | Py_DECREF(value); |
| 3395 | value = ast2obj_expr(o->v.DictComp.value); |
| 3396 | if (!value) goto failed; |
| 3397 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3398 | goto failed; |
| 3399 | Py_DECREF(value); |
| 3400 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 3401 | if (!value) goto failed; |
| 3402 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3403 | goto failed; |
| 3404 | Py_DECREF(value); |
| 3405 | break; |
| 3406 | case GeneratorExp_kind: |
| 3407 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 3408 | if (!result) goto failed; |
| 3409 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 3410 | if (!value) goto failed; |
| 3411 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3412 | goto failed; |
| 3413 | Py_DECREF(value); |
| 3414 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 3415 | ast2obj_comprehension); |
| 3416 | if (!value) goto failed; |
| 3417 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3418 | goto failed; |
| 3419 | Py_DECREF(value); |
| 3420 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3421 | case Await_kind: |
| 3422 | result = PyType_GenericNew(Await_type, NULL, NULL); |
| 3423 | if (!result) goto failed; |
| 3424 | value = ast2obj_expr(o->v.Await.value); |
| 3425 | if (!value) goto failed; |
| 3426 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3427 | goto failed; |
| 3428 | Py_DECREF(value); |
| 3429 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3430 | case Yield_kind: |
| 3431 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 3432 | if (!result) goto failed; |
| 3433 | value = ast2obj_expr(o->v.Yield.value); |
| 3434 | if (!value) goto failed; |
| 3435 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3436 | goto failed; |
| 3437 | Py_DECREF(value); |
| 3438 | break; |
| 3439 | case YieldFrom_kind: |
| 3440 | result = PyType_GenericNew(YieldFrom_type, NULL, NULL); |
| 3441 | if (!result) goto failed; |
| 3442 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 3443 | if (!value) goto failed; |
| 3444 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3445 | goto failed; |
| 3446 | Py_DECREF(value); |
| 3447 | break; |
| 3448 | case Compare_kind: |
| 3449 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 3450 | if (!result) goto failed; |
| 3451 | value = ast2obj_expr(o->v.Compare.left); |
| 3452 | if (!value) goto failed; |
| 3453 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3454 | goto failed; |
| 3455 | Py_DECREF(value); |
| 3456 | { |
| 3457 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 3458 | value = PyList_New(n); |
| 3459 | if (!value) goto failed; |
| 3460 | for(i = 0; i < n; i++) |
| 3461 | 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] | 3462 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3463 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3464 | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
| 3465 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3466 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3467 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3468 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3469 | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
| 3470 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3471 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3472 | break; |
| 3473 | case Call_kind: |
| 3474 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 3475 | if (!result) goto failed; |
| 3476 | value = ast2obj_expr(o->v.Call.func); |
| 3477 | if (!value) goto failed; |
| 3478 | if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) |
| 3479 | goto failed; |
| 3480 | Py_DECREF(value); |
| 3481 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 3482 | if (!value) goto failed; |
| 3483 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3484 | goto failed; |
| 3485 | Py_DECREF(value); |
| 3486 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 3487 | if (!value) goto failed; |
| 3488 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 3489 | goto failed; |
| 3490 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3491 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3492 | case FormattedValue_kind: |
| 3493 | result = PyType_GenericNew(FormattedValue_type, NULL, NULL); |
| 3494 | if (!result) goto failed; |
| 3495 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 3496 | if (!value) goto failed; |
| 3497 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3498 | goto failed; |
| 3499 | Py_DECREF(value); |
| 3500 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 3501 | if (!value) goto failed; |
| 3502 | if (_PyObject_SetAttrId(result, &PyId_conversion, value) == -1) |
| 3503 | goto failed; |
| 3504 | Py_DECREF(value); |
| 3505 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 3506 | if (!value) goto failed; |
| 3507 | if (_PyObject_SetAttrId(result, &PyId_format_spec, value) == -1) |
| 3508 | goto failed; |
| 3509 | Py_DECREF(value); |
Eric V. Smith | 9a4135e | 2019-05-08 16:28:48 -0400 | [diff] [blame] | 3510 | value = ast2obj_string(o->v.FormattedValue.expr_text); |
| 3511 | if (!value) goto failed; |
| 3512 | if (_PyObject_SetAttrId(result, &PyId_expr_text, value) == -1) |
| 3513 | goto failed; |
| 3514 | Py_DECREF(value); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3515 | break; |
| 3516 | case JoinedStr_kind: |
| 3517 | result = PyType_GenericNew(JoinedStr_type, NULL, NULL); |
| 3518 | if (!result) goto failed; |
| 3519 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 3520 | if (!value) goto failed; |
| 3521 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3522 | goto failed; |
| 3523 | Py_DECREF(value); |
| 3524 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3525 | case Constant_kind: |
| 3526 | result = PyType_GenericNew(Constant_type, NULL, NULL); |
| 3527 | if (!result) goto failed; |
| 3528 | value = ast2obj_constant(o->v.Constant.value); |
| 3529 | if (!value) goto failed; |
| 3530 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3531 | goto failed; |
| 3532 | Py_DECREF(value); |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 3533 | value = ast2obj_string(o->v.Constant.kind); |
| 3534 | if (!value) goto failed; |
| 3535 | if (_PyObject_SetAttrId(result, &PyId_kind, value) == -1) |
| 3536 | goto failed; |
| 3537 | Py_DECREF(value); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3538 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3539 | case Attribute_kind: |
| 3540 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 3541 | if (!result) goto failed; |
| 3542 | value = ast2obj_expr(o->v.Attribute.value); |
| 3543 | if (!value) goto failed; |
| 3544 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3545 | goto failed; |
| 3546 | Py_DECREF(value); |
| 3547 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 3548 | if (!value) goto failed; |
| 3549 | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
| 3550 | goto failed; |
| 3551 | Py_DECREF(value); |
| 3552 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 3553 | if (!value) goto failed; |
| 3554 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3555 | goto failed; |
| 3556 | Py_DECREF(value); |
| 3557 | break; |
| 3558 | case Subscript_kind: |
| 3559 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 3560 | if (!result) goto failed; |
| 3561 | value = ast2obj_expr(o->v.Subscript.value); |
| 3562 | if (!value) goto failed; |
| 3563 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3564 | goto failed; |
| 3565 | Py_DECREF(value); |
| 3566 | value = ast2obj_slice(o->v.Subscript.slice); |
| 3567 | if (!value) goto failed; |
| 3568 | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
| 3569 | goto failed; |
| 3570 | Py_DECREF(value); |
| 3571 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 3572 | if (!value) goto failed; |
| 3573 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3574 | goto failed; |
| 3575 | Py_DECREF(value); |
| 3576 | break; |
| 3577 | case Starred_kind: |
| 3578 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 3579 | if (!result) goto failed; |
| 3580 | value = ast2obj_expr(o->v.Starred.value); |
| 3581 | if (!value) goto failed; |
| 3582 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3583 | goto failed; |
| 3584 | Py_DECREF(value); |
| 3585 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 3586 | if (!value) goto failed; |
| 3587 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3588 | goto failed; |
| 3589 | Py_DECREF(value); |
| 3590 | break; |
| 3591 | case Name_kind: |
| 3592 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 3593 | if (!result) goto failed; |
| 3594 | value = ast2obj_identifier(o->v.Name.id); |
| 3595 | if (!value) goto failed; |
| 3596 | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
| 3597 | goto failed; |
| 3598 | Py_DECREF(value); |
| 3599 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 3600 | if (!value) goto failed; |
| 3601 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3602 | goto failed; |
| 3603 | Py_DECREF(value); |
| 3604 | break; |
| 3605 | case List_kind: |
| 3606 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 3607 | if (!result) goto failed; |
| 3608 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 3609 | if (!value) goto failed; |
| 3610 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3611 | goto failed; |
| 3612 | Py_DECREF(value); |
| 3613 | value = ast2obj_expr_context(o->v.List.ctx); |
| 3614 | if (!value) goto failed; |
| 3615 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3616 | goto failed; |
| 3617 | Py_DECREF(value); |
| 3618 | break; |
| 3619 | case Tuple_kind: |
| 3620 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 3621 | if (!result) goto failed; |
| 3622 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 3623 | if (!value) goto failed; |
| 3624 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3625 | goto failed; |
| 3626 | Py_DECREF(value); |
| 3627 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 3628 | if (!value) goto failed; |
| 3629 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3630 | goto failed; |
| 3631 | Py_DECREF(value); |
| 3632 | break; |
| 3633 | } |
| 3634 | value = ast2obj_int(o->lineno); |
| 3635 | if (!value) goto failed; |
| 3636 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3637 | goto failed; |
| 3638 | Py_DECREF(value); |
| 3639 | value = ast2obj_int(o->col_offset); |
| 3640 | if (!value) goto failed; |
| 3641 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3642 | goto failed; |
| 3643 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3644 | value = ast2obj_int(o->end_lineno); |
| 3645 | if (!value) goto failed; |
| 3646 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3647 | goto failed; |
| 3648 | Py_DECREF(value); |
| 3649 | value = ast2obj_int(o->end_col_offset); |
| 3650 | if (!value) goto failed; |
| 3651 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3652 | goto failed; |
| 3653 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3654 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3655 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3656 | Py_XDECREF(value); |
| 3657 | Py_XDECREF(result); |
| 3658 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3659 | } |
| 3660 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3661 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3662 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3663 | switch(o) { |
| 3664 | case Load: |
| 3665 | Py_INCREF(Load_singleton); |
| 3666 | return Load_singleton; |
| 3667 | case Store: |
| 3668 | Py_INCREF(Store_singleton); |
| 3669 | return Store_singleton; |
| 3670 | case Del: |
| 3671 | Py_INCREF(Del_singleton); |
| 3672 | return Del_singleton; |
| 3673 | case AugLoad: |
| 3674 | Py_INCREF(AugLoad_singleton); |
| 3675 | return AugLoad_singleton; |
| 3676 | case AugStore: |
| 3677 | Py_INCREF(AugStore_singleton); |
| 3678 | return AugStore_singleton; |
| 3679 | case Param: |
| 3680 | Py_INCREF(Param_singleton); |
| 3681 | return Param_singleton; |
| 3682 | default: |
| 3683 | /* should never happen, but just in case ... */ |
| 3684 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 3685 | return NULL; |
| 3686 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3687 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3688 | PyObject* |
| 3689 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3690 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3691 | slice_ty o = (slice_ty)_o; |
| 3692 | PyObject *result = NULL, *value = NULL; |
| 3693 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3694 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3695 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3696 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3697 | switch (o->kind) { |
| 3698 | case Slice_kind: |
| 3699 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 3700 | if (!result) goto failed; |
| 3701 | value = ast2obj_expr(o->v.Slice.lower); |
| 3702 | if (!value) goto failed; |
| 3703 | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
| 3704 | goto failed; |
| 3705 | Py_DECREF(value); |
| 3706 | value = ast2obj_expr(o->v.Slice.upper); |
| 3707 | if (!value) goto failed; |
| 3708 | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
| 3709 | goto failed; |
| 3710 | Py_DECREF(value); |
| 3711 | value = ast2obj_expr(o->v.Slice.step); |
| 3712 | if (!value) goto failed; |
| 3713 | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
| 3714 | goto failed; |
| 3715 | Py_DECREF(value); |
| 3716 | break; |
| 3717 | case ExtSlice_kind: |
| 3718 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3719 | if (!result) goto failed; |
| 3720 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3721 | if (!value) goto failed; |
| 3722 | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
| 3723 | goto failed; |
| 3724 | Py_DECREF(value); |
| 3725 | break; |
| 3726 | case Index_kind: |
| 3727 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3728 | if (!result) goto failed; |
| 3729 | value = ast2obj_expr(o->v.Index.value); |
| 3730 | if (!value) goto failed; |
| 3731 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3732 | goto failed; |
| 3733 | Py_DECREF(value); |
| 3734 | break; |
| 3735 | } |
| 3736 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3737 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3738 | Py_XDECREF(value); |
| 3739 | Py_XDECREF(result); |
| 3740 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3741 | } |
| 3742 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3743 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3744 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3745 | switch(o) { |
| 3746 | case And: |
| 3747 | Py_INCREF(And_singleton); |
| 3748 | return And_singleton; |
| 3749 | case Or: |
| 3750 | Py_INCREF(Or_singleton); |
| 3751 | return Or_singleton; |
| 3752 | default: |
| 3753 | /* should never happen, but just in case ... */ |
| 3754 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3755 | return NULL; |
| 3756 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3757 | } |
| 3758 | PyObject* ast2obj_operator(operator_ty o) |
| 3759 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3760 | switch(o) { |
| 3761 | case Add: |
| 3762 | Py_INCREF(Add_singleton); |
| 3763 | return Add_singleton; |
| 3764 | case Sub: |
| 3765 | Py_INCREF(Sub_singleton); |
| 3766 | return Sub_singleton; |
| 3767 | case Mult: |
| 3768 | Py_INCREF(Mult_singleton); |
| 3769 | return Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 3770 | case MatMult: |
| 3771 | Py_INCREF(MatMult_singleton); |
| 3772 | return MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3773 | case Div: |
| 3774 | Py_INCREF(Div_singleton); |
| 3775 | return Div_singleton; |
| 3776 | case Mod: |
| 3777 | Py_INCREF(Mod_singleton); |
| 3778 | return Mod_singleton; |
| 3779 | case Pow: |
| 3780 | Py_INCREF(Pow_singleton); |
| 3781 | return Pow_singleton; |
| 3782 | case LShift: |
| 3783 | Py_INCREF(LShift_singleton); |
| 3784 | return LShift_singleton; |
| 3785 | case RShift: |
| 3786 | Py_INCREF(RShift_singleton); |
| 3787 | return RShift_singleton; |
| 3788 | case BitOr: |
| 3789 | Py_INCREF(BitOr_singleton); |
| 3790 | return BitOr_singleton; |
| 3791 | case BitXor: |
| 3792 | Py_INCREF(BitXor_singleton); |
| 3793 | return BitXor_singleton; |
| 3794 | case BitAnd: |
| 3795 | Py_INCREF(BitAnd_singleton); |
| 3796 | return BitAnd_singleton; |
| 3797 | case FloorDiv: |
| 3798 | Py_INCREF(FloorDiv_singleton); |
| 3799 | return FloorDiv_singleton; |
| 3800 | default: |
| 3801 | /* should never happen, but just in case ... */ |
| 3802 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3803 | return NULL; |
| 3804 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3805 | } |
| 3806 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3807 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3808 | switch(o) { |
| 3809 | case Invert: |
| 3810 | Py_INCREF(Invert_singleton); |
| 3811 | return Invert_singleton; |
| 3812 | case Not: |
| 3813 | Py_INCREF(Not_singleton); |
| 3814 | return Not_singleton; |
| 3815 | case UAdd: |
| 3816 | Py_INCREF(UAdd_singleton); |
| 3817 | return UAdd_singleton; |
| 3818 | case USub: |
| 3819 | Py_INCREF(USub_singleton); |
| 3820 | return USub_singleton; |
| 3821 | default: |
| 3822 | /* should never happen, but just in case ... */ |
| 3823 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3824 | return NULL; |
| 3825 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3826 | } |
| 3827 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3828 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3829 | switch(o) { |
| 3830 | case Eq: |
| 3831 | Py_INCREF(Eq_singleton); |
| 3832 | return Eq_singleton; |
| 3833 | case NotEq: |
| 3834 | Py_INCREF(NotEq_singleton); |
| 3835 | return NotEq_singleton; |
| 3836 | case Lt: |
| 3837 | Py_INCREF(Lt_singleton); |
| 3838 | return Lt_singleton; |
| 3839 | case LtE: |
| 3840 | Py_INCREF(LtE_singleton); |
| 3841 | return LtE_singleton; |
| 3842 | case Gt: |
| 3843 | Py_INCREF(Gt_singleton); |
| 3844 | return Gt_singleton; |
| 3845 | case GtE: |
| 3846 | Py_INCREF(GtE_singleton); |
| 3847 | return GtE_singleton; |
| 3848 | case Is: |
| 3849 | Py_INCREF(Is_singleton); |
| 3850 | return Is_singleton; |
| 3851 | case IsNot: |
| 3852 | Py_INCREF(IsNot_singleton); |
| 3853 | return IsNot_singleton; |
| 3854 | case In: |
| 3855 | Py_INCREF(In_singleton); |
| 3856 | return In_singleton; |
| 3857 | case NotIn: |
| 3858 | Py_INCREF(NotIn_singleton); |
| 3859 | return NotIn_singleton; |
| 3860 | default: |
| 3861 | /* should never happen, but just in case ... */ |
| 3862 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3863 | return NULL; |
| 3864 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3865 | } |
| 3866 | PyObject* |
| 3867 | ast2obj_comprehension(void* _o) |
| 3868 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3869 | comprehension_ty o = (comprehension_ty)_o; |
| 3870 | PyObject *result = NULL, *value = NULL; |
| 3871 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3872 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3873 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3874 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3875 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3876 | if (!result) return NULL; |
| 3877 | value = ast2obj_expr(o->target); |
| 3878 | if (!value) goto failed; |
| 3879 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 3880 | goto failed; |
| 3881 | Py_DECREF(value); |
| 3882 | value = ast2obj_expr(o->iter); |
| 3883 | if (!value) goto failed; |
| 3884 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 3885 | goto failed; |
| 3886 | Py_DECREF(value); |
| 3887 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3888 | if (!value) goto failed; |
| 3889 | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
| 3890 | goto failed; |
| 3891 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3892 | value = ast2obj_int(o->is_async); |
| 3893 | if (!value) goto failed; |
| 3894 | if (_PyObject_SetAttrId(result, &PyId_is_async, value) == -1) |
| 3895 | goto failed; |
| 3896 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3897 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3898 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3899 | Py_XDECREF(value); |
| 3900 | Py_XDECREF(result); |
| 3901 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3902 | } |
| 3903 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3904 | PyObject* |
| 3905 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3906 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3907 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3908 | PyObject *result = NULL, *value = NULL; |
| 3909 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3910 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3911 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3912 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3913 | switch (o->kind) { |
| 3914 | case ExceptHandler_kind: |
| 3915 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3916 | if (!result) goto failed; |
| 3917 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3918 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3919 | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
| 3920 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3921 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3922 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3923 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3924 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3925 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3926 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3927 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3928 | if (!value) goto failed; |
| 3929 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3930 | goto failed; |
| 3931 | Py_DECREF(value); |
| 3932 | break; |
| 3933 | } |
| 3934 | value = ast2obj_int(o->lineno); |
| 3935 | if (!value) goto failed; |
| 3936 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3937 | goto failed; |
| 3938 | Py_DECREF(value); |
| 3939 | value = ast2obj_int(o->col_offset); |
| 3940 | if (!value) goto failed; |
| 3941 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3942 | goto failed; |
| 3943 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3944 | value = ast2obj_int(o->end_lineno); |
| 3945 | if (!value) goto failed; |
| 3946 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3947 | goto failed; |
| 3948 | Py_DECREF(value); |
| 3949 | value = ast2obj_int(o->end_col_offset); |
| 3950 | if (!value) goto failed; |
| 3951 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3952 | goto failed; |
| 3953 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3954 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3955 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3956 | Py_XDECREF(value); |
| 3957 | Py_XDECREF(result); |
| 3958 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3959 | } |
| 3960 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3961 | PyObject* |
| 3962 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3963 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3964 | arguments_ty o = (arguments_ty)_o; |
| 3965 | PyObject *result = NULL, *value = NULL; |
| 3966 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3967 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3968 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3969 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3970 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3971 | if (!result) return NULL; |
| 3972 | value = ast2obj_list(o->args, ast2obj_arg); |
| 3973 | if (!value) goto failed; |
| 3974 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3975 | goto failed; |
| 3976 | Py_DECREF(value); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3977 | value = ast2obj_list(o->posonlyargs, ast2obj_arg); |
| 3978 | if (!value) goto failed; |
| 3979 | if (_PyObject_SetAttrId(result, &PyId_posonlyargs, value) == -1) |
| 3980 | goto failed; |
| 3981 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3982 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3983 | if (!value) goto failed; |
| 3984 | if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) |
| 3985 | goto failed; |
| 3986 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3987 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 3988 | if (!value) goto failed; |
| 3989 | if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) |
| 3990 | goto failed; |
| 3991 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3992 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3993 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3994 | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3995 | goto failed; |
| 3996 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3997 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3998 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3999 | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4000 | goto failed; |
| 4001 | Py_DECREF(value); |
| 4002 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 4003 | if (!value) goto failed; |
| 4004 | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
| 4005 | goto failed; |
| 4006 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4007 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4008 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4009 | Py_XDECREF(value); |
| 4010 | Py_XDECREF(result); |
| 4011 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4012 | } |
| 4013 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4014 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4015 | ast2obj_arg(void* _o) |
| 4016 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4017 | arg_ty o = (arg_ty)_o; |
| 4018 | PyObject *result = NULL, *value = NULL; |
| 4019 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4020 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4021 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4022 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4023 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 4024 | if (!result) return NULL; |
| 4025 | value = ast2obj_identifier(o->arg); |
| 4026 | if (!value) goto failed; |
| 4027 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 4028 | goto failed; |
| 4029 | Py_DECREF(value); |
| 4030 | value = ast2obj_expr(o->annotation); |
| 4031 | if (!value) goto failed; |
| 4032 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 4033 | goto failed; |
| 4034 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4035 | value = ast2obj_string(o->type_comment); |
| 4036 | if (!value) goto failed; |
| 4037 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 4038 | goto failed; |
| 4039 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4040 | value = ast2obj_int(o->lineno); |
| 4041 | if (!value) goto failed; |
| 4042 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 4043 | goto failed; |
| 4044 | Py_DECREF(value); |
| 4045 | value = ast2obj_int(o->col_offset); |
| 4046 | if (!value) goto failed; |
| 4047 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 4048 | goto failed; |
| 4049 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4050 | value = ast2obj_int(o->end_lineno); |
| 4051 | if (!value) goto failed; |
| 4052 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 4053 | goto failed; |
| 4054 | Py_DECREF(value); |
| 4055 | value = ast2obj_int(o->end_col_offset); |
| 4056 | if (!value) goto failed; |
| 4057 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 4058 | goto failed; |
| 4059 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4060 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4061 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4062 | Py_XDECREF(value); |
| 4063 | Py_XDECREF(result); |
| 4064 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4068 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4069 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4070 | keyword_ty o = (keyword_ty)_o; |
| 4071 | PyObject *result = NULL, *value = NULL; |
| 4072 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4073 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4074 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4075 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4076 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 4077 | if (!result) return NULL; |
| 4078 | value = ast2obj_identifier(o->arg); |
| 4079 | if (!value) goto failed; |
| 4080 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 4081 | goto failed; |
| 4082 | Py_DECREF(value); |
| 4083 | value = ast2obj_expr(o->value); |
| 4084 | if (!value) goto failed; |
| 4085 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 4086 | goto failed; |
| 4087 | Py_DECREF(value); |
| 4088 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4089 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4090 | Py_XDECREF(value); |
| 4091 | Py_XDECREF(result); |
| 4092 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4093 | } |
| 4094 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4095 | PyObject* |
| 4096 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4097 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4098 | alias_ty o = (alias_ty)_o; |
| 4099 | PyObject *result = NULL, *value = NULL; |
| 4100 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4101 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4102 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4103 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4104 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 4105 | if (!result) return NULL; |
| 4106 | value = ast2obj_identifier(o->name); |
| 4107 | if (!value) goto failed; |
| 4108 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 4109 | goto failed; |
| 4110 | Py_DECREF(value); |
| 4111 | value = ast2obj_identifier(o->asname); |
| 4112 | if (!value) goto failed; |
| 4113 | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
| 4114 | goto failed; |
| 4115 | Py_DECREF(value); |
| 4116 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4117 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4118 | Py_XDECREF(value); |
| 4119 | Py_XDECREF(result); |
| 4120 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4121 | } |
| 4122 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4123 | PyObject* |
| 4124 | ast2obj_withitem(void* _o) |
| 4125 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4126 | withitem_ty o = (withitem_ty)_o; |
| 4127 | PyObject *result = NULL, *value = NULL; |
| 4128 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4129 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4130 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4131 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4132 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 4133 | if (!result) return NULL; |
| 4134 | value = ast2obj_expr(o->context_expr); |
| 4135 | if (!value) goto failed; |
| 4136 | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
| 4137 | goto failed; |
| 4138 | Py_DECREF(value); |
| 4139 | value = ast2obj_expr(o->optional_vars); |
| 4140 | if (!value) goto failed; |
| 4141 | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
| 4142 | goto failed; |
| 4143 | Py_DECREF(value); |
| 4144 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4145 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4146 | Py_XDECREF(value); |
| 4147 | Py_XDECREF(result); |
| 4148 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4149 | } |
| 4150 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4151 | PyObject* |
| 4152 | ast2obj_type_ignore(void* _o) |
| 4153 | { |
| 4154 | type_ignore_ty o = (type_ignore_ty)_o; |
| 4155 | PyObject *result = NULL, *value = NULL; |
| 4156 | if (!o) { |
| 4157 | Py_RETURN_NONE; |
| 4158 | } |
| 4159 | |
| 4160 | switch (o->kind) { |
| 4161 | case TypeIgnore_kind: |
| 4162 | result = PyType_GenericNew(TypeIgnore_type, NULL, NULL); |
| 4163 | if (!result) goto failed; |
| 4164 | value = ast2obj_int(o->v.TypeIgnore.lineno); |
| 4165 | if (!value) goto failed; |
| 4166 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) == -1) |
| 4167 | goto failed; |
| 4168 | Py_DECREF(value); |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 4169 | value = ast2obj_string(o->v.TypeIgnore.tag); |
| 4170 | if (!value) goto failed; |
| 4171 | if (_PyObject_SetAttrId(result, &PyId_tag, value) == -1) |
| 4172 | goto failed; |
| 4173 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4174 | break; |
| 4175 | } |
| 4176 | return result; |
| 4177 | failed: |
| 4178 | Py_XDECREF(value); |
| 4179 | Py_XDECREF(result); |
| 4180 | return NULL; |
| 4181 | } |
| 4182 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4183 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4184 | int |
| 4185 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 4186 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4187 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4188 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4189 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4190 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4191 | if (obj == Py_None) { |
| 4192 | *out = NULL; |
| 4193 | return 0; |
| 4194 | } |
| 4195 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 4196 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4197 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4198 | } |
| 4199 | if (isinstance) { |
| 4200 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4201 | asdl_seq* type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4202 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4203 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4204 | return 1; |
| 4205 | } |
| 4206 | if (tmp == NULL) { |
| 4207 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 4208 | return 1; |
| 4209 | } |
| 4210 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4211 | int res; |
| 4212 | Py_ssize_t len; |
| 4213 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4214 | if (!PyList_Check(tmp)) { |
| 4215 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4216 | goto failed; |
| 4217 | } |
| 4218 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4219 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4220 | if (body == NULL) goto failed; |
| 4221 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4222 | stmt_ty val; |
| 4223 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4224 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4225 | if (len != PyList_GET_SIZE(tmp)) { |
| 4226 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 4227 | goto failed; |
| 4228 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4229 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4230 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4231 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4232 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4233 | if (_PyObject_LookupAttrId(obj, &PyId_type_ignores, &tmp) < 0) { |
| 4234 | return 1; |
| 4235 | } |
| 4236 | if (tmp == NULL) { |
| 4237 | PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module"); |
| 4238 | return 1; |
| 4239 | } |
| 4240 | else { |
| 4241 | int res; |
| 4242 | Py_ssize_t len; |
| 4243 | Py_ssize_t i; |
| 4244 | if (!PyList_Check(tmp)) { |
| 4245 | PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4246 | goto failed; |
| 4247 | } |
| 4248 | len = PyList_GET_SIZE(tmp); |
| 4249 | type_ignores = _Py_asdl_seq_new(len, arena); |
| 4250 | if (type_ignores == NULL) goto failed; |
| 4251 | for (i = 0; i < len; i++) { |
| 4252 | type_ignore_ty val; |
| 4253 | res = obj2ast_type_ignore(PyList_GET_ITEM(tmp, i), &val, arena); |
| 4254 | if (res != 0) goto failed; |
| 4255 | if (len != PyList_GET_SIZE(tmp)) { |
| 4256 | PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration"); |
| 4257 | goto failed; |
| 4258 | } |
| 4259 | asdl_seq_SET(type_ignores, i, val); |
| 4260 | } |
| 4261 | Py_CLEAR(tmp); |
| 4262 | } |
| 4263 | *out = Module(body, type_ignores, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4264 | if (*out == NULL) goto failed; |
| 4265 | return 0; |
| 4266 | } |
| 4267 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 4268 | if (isinstance == -1) { |
| 4269 | return 1; |
| 4270 | } |
| 4271 | if (isinstance) { |
| 4272 | asdl_seq* body; |
| 4273 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4274 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4275 | return 1; |
| 4276 | } |
| 4277 | if (tmp == NULL) { |
| 4278 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 4279 | return 1; |
| 4280 | } |
| 4281 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4282 | int res; |
| 4283 | Py_ssize_t len; |
| 4284 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4285 | if (!PyList_Check(tmp)) { |
| 4286 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4287 | goto failed; |
| 4288 | } |
| 4289 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4290 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4291 | if (body == NULL) goto failed; |
| 4292 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4293 | stmt_ty val; |
| 4294 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4295 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4296 | if (len != PyList_GET_SIZE(tmp)) { |
| 4297 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 4298 | goto failed; |
| 4299 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4300 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4301 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4302 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4303 | } |
| 4304 | *out = Interactive(body, arena); |
| 4305 | if (*out == NULL) goto failed; |
| 4306 | return 0; |
| 4307 | } |
| 4308 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 4309 | if (isinstance == -1) { |
| 4310 | return 1; |
| 4311 | } |
| 4312 | if (isinstance) { |
| 4313 | expr_ty body; |
| 4314 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4315 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4316 | return 1; |
| 4317 | } |
| 4318 | if (tmp == NULL) { |
| 4319 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 4320 | return 1; |
| 4321 | } |
| 4322 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4323 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4324 | res = obj2ast_expr(tmp, &body, arena); |
| 4325 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4326 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4327 | } |
| 4328 | *out = Expression(body, arena); |
| 4329 | if (*out == NULL) goto failed; |
| 4330 | return 0; |
| 4331 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4332 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionType_type); |
| 4333 | if (isinstance == -1) { |
| 4334 | return 1; |
| 4335 | } |
| 4336 | if (isinstance) { |
| 4337 | asdl_seq* argtypes; |
| 4338 | expr_ty returns; |
| 4339 | |
| 4340 | if (_PyObject_LookupAttrId(obj, &PyId_argtypes, &tmp) < 0) { |
| 4341 | return 1; |
| 4342 | } |
| 4343 | if (tmp == NULL) { |
| 4344 | PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType"); |
| 4345 | return 1; |
| 4346 | } |
| 4347 | else { |
| 4348 | int res; |
| 4349 | Py_ssize_t len; |
| 4350 | Py_ssize_t i; |
| 4351 | if (!PyList_Check(tmp)) { |
| 4352 | PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4353 | goto failed; |
| 4354 | } |
| 4355 | len = PyList_GET_SIZE(tmp); |
| 4356 | argtypes = _Py_asdl_seq_new(len, arena); |
| 4357 | if (argtypes == NULL) goto failed; |
| 4358 | for (i = 0; i < len; i++) { |
| 4359 | expr_ty val; |
| 4360 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
| 4361 | if (res != 0) goto failed; |
| 4362 | if (len != PyList_GET_SIZE(tmp)) { |
| 4363 | PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration"); |
| 4364 | goto failed; |
| 4365 | } |
| 4366 | asdl_seq_SET(argtypes, i, val); |
| 4367 | } |
| 4368 | Py_CLEAR(tmp); |
| 4369 | } |
| 4370 | if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) { |
| 4371 | return 1; |
| 4372 | } |
| 4373 | if (tmp == NULL) { |
| 4374 | PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType"); |
| 4375 | return 1; |
| 4376 | } |
| 4377 | else { |
| 4378 | int res; |
| 4379 | res = obj2ast_expr(tmp, &returns, arena); |
| 4380 | if (res != 0) goto failed; |
| 4381 | Py_CLEAR(tmp); |
| 4382 | } |
| 4383 | *out = FunctionType(argtypes, returns, arena); |
| 4384 | if (*out == NULL) goto failed; |
| 4385 | return 0; |
| 4386 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4387 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 4388 | if (isinstance == -1) { |
| 4389 | return 1; |
| 4390 | } |
| 4391 | if (isinstance) { |
| 4392 | asdl_seq* body; |
| 4393 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4394 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4395 | return 1; |
| 4396 | } |
| 4397 | if (tmp == NULL) { |
| 4398 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 4399 | return 1; |
| 4400 | } |
| 4401 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4402 | int res; |
| 4403 | Py_ssize_t len; |
| 4404 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4405 | if (!PyList_Check(tmp)) { |
| 4406 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4407 | goto failed; |
| 4408 | } |
| 4409 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4410 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4411 | if (body == NULL) goto failed; |
| 4412 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4413 | stmt_ty val; |
| 4414 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4415 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4416 | if (len != PyList_GET_SIZE(tmp)) { |
| 4417 | PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration"); |
| 4418 | goto failed; |
| 4419 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4420 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4421 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4422 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4423 | } |
| 4424 | *out = Suite(body, arena); |
| 4425 | if (*out == NULL) goto failed; |
| 4426 | return 0; |
| 4427 | } |
| 4428 | |
| 4429 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 4430 | failed: |
| 4431 | Py_XDECREF(tmp); |
| 4432 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4433 | } |
| 4434 | |
| 4435 | int |
| 4436 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 4437 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4438 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4439 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4440 | PyObject *tmp = NULL; |
| 4441 | int lineno; |
| 4442 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4443 | int end_lineno; |
| 4444 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4445 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4446 | if (obj == Py_None) { |
| 4447 | *out = NULL; |
| 4448 | return 0; |
| 4449 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4450 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 4451 | return 1; |
| 4452 | } |
| 4453 | if (tmp == NULL) { |
| 4454 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 4455 | return 1; |
| 4456 | } |
| 4457 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4458 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4459 | res = obj2ast_int(tmp, &lineno, arena); |
| 4460 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4461 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4462 | } |
| 4463 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4464 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4465 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4466 | if (tmp == NULL) { |
| 4467 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 4468 | return 1; |
| 4469 | } |
| 4470 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4471 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4472 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4473 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4474 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4475 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4476 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 4477 | return 1; |
| 4478 | } |
| 4479 | if (tmp == NULL || tmp == Py_None) { |
| 4480 | Py_CLEAR(tmp); |
| 4481 | end_lineno = 0; |
| 4482 | } |
| 4483 | else { |
| 4484 | int res; |
| 4485 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 4486 | if (res != 0) goto failed; |
| 4487 | Py_CLEAR(tmp); |
| 4488 | } |
| 4489 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 4490 | return 1; |
| 4491 | } |
| 4492 | if (tmp == NULL || tmp == Py_None) { |
| 4493 | Py_CLEAR(tmp); |
| 4494 | end_col_offset = 0; |
| 4495 | } |
| 4496 | else { |
| 4497 | int res; |
| 4498 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 4499 | if (res != 0) goto failed; |
| 4500 | Py_CLEAR(tmp); |
| 4501 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4502 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 4503 | if (isinstance == -1) { |
| 4504 | return 1; |
| 4505 | } |
| 4506 | if (isinstance) { |
| 4507 | identifier name; |
| 4508 | arguments_ty args; |
| 4509 | asdl_seq* body; |
| 4510 | asdl_seq* decorator_list; |
| 4511 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4512 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4513 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4514 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4515 | return 1; |
| 4516 | } |
| 4517 | if (tmp == NULL) { |
| 4518 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 4519 | return 1; |
| 4520 | } |
| 4521 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4522 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4523 | res = obj2ast_identifier(tmp, &name, arena); |
| 4524 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4525 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4526 | } |
| 4527 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4528 | return 1; |
| 4529 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4530 | if (tmp == NULL) { |
| 4531 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 4532 | return 1; |
| 4533 | } |
| 4534 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4535 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4536 | res = obj2ast_arguments(tmp, &args, arena); |
| 4537 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4538 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4539 | } |
| 4540 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4541 | return 1; |
| 4542 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4543 | if (tmp == NULL) { |
| 4544 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 4545 | return 1; |
| 4546 | } |
| 4547 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4548 | int res; |
| 4549 | Py_ssize_t len; |
| 4550 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4551 | if (!PyList_Check(tmp)) { |
| 4552 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4553 | goto failed; |
| 4554 | } |
| 4555 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4556 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4557 | if (body == NULL) goto failed; |
| 4558 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4559 | stmt_ty val; |
| 4560 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4561 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4562 | if (len != PyList_GET_SIZE(tmp)) { |
| 4563 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 4564 | goto failed; |
| 4565 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4566 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4567 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4568 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4569 | } |
| 4570 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4571 | return 1; |
| 4572 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4573 | if (tmp == NULL) { |
| 4574 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 4575 | return 1; |
| 4576 | } |
| 4577 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4578 | int res; |
| 4579 | Py_ssize_t len; |
| 4580 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4581 | if (!PyList_Check(tmp)) { |
| 4582 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4583 | goto failed; |
| 4584 | } |
| 4585 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4586 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4587 | if (decorator_list == NULL) goto failed; |
| 4588 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4589 | expr_ty val; |
| 4590 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4591 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4592 | if (len != PyList_GET_SIZE(tmp)) { |
| 4593 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 4594 | goto failed; |
| 4595 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4596 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4597 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4598 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4599 | } |
| 4600 | if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4601 | return 1; |
| 4602 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4603 | if (tmp == NULL || tmp == Py_None) { |
| 4604 | Py_CLEAR(tmp); |
| 4605 | returns = NULL; |
| 4606 | } |
| 4607 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4608 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4609 | res = obj2ast_expr(tmp, &returns, arena); |
| 4610 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4611 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4612 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4613 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 4614 | return 1; |
| 4615 | } |
| 4616 | if (tmp == NULL || tmp == Py_None) { |
| 4617 | Py_CLEAR(tmp); |
| 4618 | type_comment = NULL; |
| 4619 | } |
| 4620 | else { |
| 4621 | int res; |
| 4622 | res = obj2ast_string(tmp, &type_comment, arena); |
| 4623 | if (res != 0) goto failed; |
| 4624 | Py_CLEAR(tmp); |
| 4625 | } |
| 4626 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 4627 | type_comment, lineno, col_offset, end_lineno, |
| 4628 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4629 | if (*out == NULL) goto failed; |
| 4630 | return 0; |
| 4631 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4632 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFunctionDef_type); |
| 4633 | if (isinstance == -1) { |
| 4634 | return 1; |
| 4635 | } |
| 4636 | if (isinstance) { |
| 4637 | identifier name; |
| 4638 | arguments_ty args; |
| 4639 | asdl_seq* body; |
| 4640 | asdl_seq* decorator_list; |
| 4641 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4642 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4643 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4644 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4645 | return 1; |
| 4646 | } |
| 4647 | if (tmp == NULL) { |
| 4648 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 4649 | return 1; |
| 4650 | } |
| 4651 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4652 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4653 | res = obj2ast_identifier(tmp, &name, arena); |
| 4654 | if (res != 0) goto failed; |
| 4655 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4656 | } |
| 4657 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4658 | return 1; |
| 4659 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4660 | if (tmp == NULL) { |
| 4661 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 4662 | return 1; |
| 4663 | } |
| 4664 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4665 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4666 | res = obj2ast_arguments(tmp, &args, arena); |
| 4667 | if (res != 0) goto failed; |
| 4668 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4669 | } |
| 4670 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4671 | return 1; |
| 4672 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4673 | if (tmp == NULL) { |
| 4674 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 4675 | return 1; |
| 4676 | } |
| 4677 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4678 | int res; |
| 4679 | Py_ssize_t len; |
| 4680 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4681 | if (!PyList_Check(tmp)) { |
| 4682 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4683 | goto failed; |
| 4684 | } |
| 4685 | len = PyList_GET_SIZE(tmp); |
| 4686 | body = _Py_asdl_seq_new(len, arena); |
| 4687 | if (body == NULL) goto failed; |
| 4688 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4689 | stmt_ty val; |
| 4690 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4691 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4692 | if (len != PyList_GET_SIZE(tmp)) { |
| 4693 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 4694 | goto failed; |
| 4695 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4696 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4697 | } |
| 4698 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4699 | } |
| 4700 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4701 | return 1; |
| 4702 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4703 | if (tmp == NULL) { |
| 4704 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 4705 | return 1; |
| 4706 | } |
| 4707 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4708 | int res; |
| 4709 | Py_ssize_t len; |
| 4710 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4711 | if (!PyList_Check(tmp)) { |
| 4712 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4713 | goto failed; |
| 4714 | } |
| 4715 | len = PyList_GET_SIZE(tmp); |
| 4716 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 4717 | if (decorator_list == NULL) goto failed; |
| 4718 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4719 | expr_ty val; |
| 4720 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4721 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4722 | if (len != PyList_GET_SIZE(tmp)) { |
| 4723 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 4724 | goto failed; |
| 4725 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4726 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4727 | } |
| 4728 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4729 | } |
| 4730 | if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4731 | return 1; |
| 4732 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4733 | if (tmp == NULL || tmp == Py_None) { |
| 4734 | Py_CLEAR(tmp); |
| 4735 | returns = NULL; |
| 4736 | } |
| 4737 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4738 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4739 | res = obj2ast_expr(tmp, &returns, arena); |
| 4740 | if (res != 0) goto failed; |
| 4741 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4742 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4743 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 4744 | return 1; |
| 4745 | } |
| 4746 | if (tmp == NULL || tmp == Py_None) { |
| 4747 | Py_CLEAR(tmp); |
| 4748 | type_comment = NULL; |
| 4749 | } |
| 4750 | else { |
| 4751 | int res; |
| 4752 | res = obj2ast_string(tmp, &type_comment, arena); |
| 4753 | if (res != 0) goto failed; |
| 4754 | Py_CLEAR(tmp); |
| 4755 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4756 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4757 | type_comment, lineno, col_offset, end_lineno, |
| 4758 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4759 | if (*out == NULL) goto failed; |
| 4760 | return 0; |
| 4761 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4762 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 4763 | if (isinstance == -1) { |
| 4764 | return 1; |
| 4765 | } |
| 4766 | if (isinstance) { |
| 4767 | identifier name; |
| 4768 | asdl_seq* bases; |
| 4769 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4770 | asdl_seq* body; |
| 4771 | asdl_seq* decorator_list; |
| 4772 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4773 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4774 | return 1; |
| 4775 | } |
| 4776 | if (tmp == NULL) { |
| 4777 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 4778 | return 1; |
| 4779 | } |
| 4780 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4781 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4782 | res = obj2ast_identifier(tmp, &name, arena); |
| 4783 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4784 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4785 | } |
| 4786 | if (_PyObject_LookupAttrId(obj, &PyId_bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4787 | return 1; |
| 4788 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4789 | if (tmp == NULL) { |
| 4790 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 4791 | return 1; |
| 4792 | } |
| 4793 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4794 | int res; |
| 4795 | Py_ssize_t len; |
| 4796 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4797 | if (!PyList_Check(tmp)) { |
| 4798 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4799 | goto failed; |
| 4800 | } |
| 4801 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4802 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4803 | if (bases == NULL) goto failed; |
| 4804 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4805 | expr_ty val; |
| 4806 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4807 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4808 | if (len != PyList_GET_SIZE(tmp)) { |
| 4809 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 4810 | goto failed; |
| 4811 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4812 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4813 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4814 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4815 | } |
| 4816 | if (_PyObject_LookupAttrId(obj, &PyId_keywords, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4817 | return 1; |
| 4818 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4819 | if (tmp == NULL) { |
| 4820 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 4821 | return 1; |
| 4822 | } |
| 4823 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4824 | int res; |
| 4825 | Py_ssize_t len; |
| 4826 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4827 | if (!PyList_Check(tmp)) { |
| 4828 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4829 | goto failed; |
| 4830 | } |
| 4831 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4832 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4833 | if (keywords == NULL) goto failed; |
| 4834 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4835 | keyword_ty val; |
| 4836 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4837 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4838 | if (len != PyList_GET_SIZE(tmp)) { |
| 4839 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 4840 | goto failed; |
| 4841 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4842 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4843 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4844 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4845 | } |
| 4846 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4847 | return 1; |
| 4848 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4849 | if (tmp == NULL) { |
| 4850 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 4851 | return 1; |
| 4852 | } |
| 4853 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4854 | int res; |
| 4855 | Py_ssize_t len; |
| 4856 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4857 | if (!PyList_Check(tmp)) { |
| 4858 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4859 | goto failed; |
| 4860 | } |
| 4861 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4862 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4863 | if (body == NULL) goto failed; |
| 4864 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4865 | stmt_ty val; |
| 4866 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4867 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4868 | if (len != PyList_GET_SIZE(tmp)) { |
| 4869 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 4870 | goto failed; |
| 4871 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4872 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4873 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4874 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4875 | } |
| 4876 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4877 | return 1; |
| 4878 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4879 | if (tmp == NULL) { |
| 4880 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 4881 | return 1; |
| 4882 | } |
| 4883 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4884 | int res; |
| 4885 | Py_ssize_t len; |
| 4886 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4887 | if (!PyList_Check(tmp)) { |
| 4888 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4889 | goto failed; |
| 4890 | } |
| 4891 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4892 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4893 | if (decorator_list == NULL) goto failed; |
| 4894 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4895 | expr_ty val; |
| 4896 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4897 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4898 | if (len != PyList_GET_SIZE(tmp)) { |
| 4899 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
| 4900 | goto failed; |
| 4901 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4902 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4903 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4904 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4905 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 4906 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4907 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4908 | if (*out == NULL) goto failed; |
| 4909 | return 0; |
| 4910 | } |
| 4911 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 4912 | if (isinstance == -1) { |
| 4913 | return 1; |
| 4914 | } |
| 4915 | if (isinstance) { |
| 4916 | expr_ty value; |
| 4917 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4918 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 4919 | return 1; |
| 4920 | } |
| 4921 | if (tmp == NULL || tmp == Py_None) { |
| 4922 | Py_CLEAR(tmp); |
| 4923 | value = NULL; |
| 4924 | } |
| 4925 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4926 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4927 | res = obj2ast_expr(tmp, &value, arena); |
| 4928 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4929 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4930 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4931 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 4932 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4933 | if (*out == NULL) goto failed; |
| 4934 | return 0; |
| 4935 | } |
| 4936 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 4937 | if (isinstance == -1) { |
| 4938 | return 1; |
| 4939 | } |
| 4940 | if (isinstance) { |
| 4941 | asdl_seq* targets; |
| 4942 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4943 | if (_PyObject_LookupAttrId(obj, &PyId_targets, &tmp) < 0) { |
| 4944 | return 1; |
| 4945 | } |
| 4946 | if (tmp == NULL) { |
| 4947 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 4948 | return 1; |
| 4949 | } |
| 4950 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4951 | int res; |
| 4952 | Py_ssize_t len; |
| 4953 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4954 | if (!PyList_Check(tmp)) { |
| 4955 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4956 | goto failed; |
| 4957 | } |
| 4958 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4959 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4960 | if (targets == NULL) goto failed; |
| 4961 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4962 | expr_ty val; |
| 4963 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4964 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4965 | if (len != PyList_GET_SIZE(tmp)) { |
| 4966 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 4967 | goto failed; |
| 4968 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4969 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4970 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4971 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4972 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4973 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 4974 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4975 | if (*out == NULL) goto failed; |
| 4976 | return 0; |
| 4977 | } |
| 4978 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 4979 | if (isinstance == -1) { |
| 4980 | return 1; |
| 4981 | } |
| 4982 | if (isinstance) { |
| 4983 | asdl_seq* targets; |
| 4984 | expr_ty value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4985 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4986 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4987 | if (_PyObject_LookupAttrId(obj, &PyId_targets, &tmp) < 0) { |
| 4988 | return 1; |
| 4989 | } |
| 4990 | if (tmp == NULL) { |
| 4991 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 4992 | return 1; |
| 4993 | } |
| 4994 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4995 | int res; |
| 4996 | Py_ssize_t len; |
| 4997 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4998 | if (!PyList_Check(tmp)) { |
| 4999 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5000 | goto failed; |
| 5001 | } |
| 5002 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5003 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5004 | if (targets == NULL) goto failed; |
| 5005 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5006 | expr_ty val; |
| 5007 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5008 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5009 | if (len != PyList_GET_SIZE(tmp)) { |
| 5010 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 5011 | goto failed; |
| 5012 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5013 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5014 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5015 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5016 | } |
| 5017 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5018 | return 1; |
| 5019 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5020 | if (tmp == NULL) { |
| 5021 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 5022 | return 1; |
| 5023 | } |
| 5024 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5025 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5026 | res = obj2ast_expr(tmp, &value, arena); |
| 5027 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5028 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5029 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5030 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5031 | return 1; |
| 5032 | } |
| 5033 | if (tmp == NULL || tmp == Py_None) { |
| 5034 | Py_CLEAR(tmp); |
| 5035 | type_comment = NULL; |
| 5036 | } |
| 5037 | else { |
| 5038 | int res; |
| 5039 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5040 | if (res != 0) goto failed; |
| 5041 | Py_CLEAR(tmp); |
| 5042 | } |
| 5043 | *out = Assign(targets, value, type_comment, lineno, col_offset, |
| 5044 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5045 | if (*out == NULL) goto failed; |
| 5046 | return 0; |
| 5047 | } |
| 5048 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 5049 | if (isinstance == -1) { |
| 5050 | return 1; |
| 5051 | } |
| 5052 | if (isinstance) { |
| 5053 | expr_ty target; |
| 5054 | operator_ty op; |
| 5055 | expr_ty value; |
| 5056 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5057 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5058 | return 1; |
| 5059 | } |
| 5060 | if (tmp == NULL) { |
| 5061 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 5062 | return 1; |
| 5063 | } |
| 5064 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5065 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5066 | res = obj2ast_expr(tmp, &target, arena); |
| 5067 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5068 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5069 | } |
| 5070 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5071 | return 1; |
| 5072 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5073 | if (tmp == NULL) { |
| 5074 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 5075 | return 1; |
| 5076 | } |
| 5077 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5078 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5079 | res = obj2ast_operator(tmp, &op, arena); |
| 5080 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5081 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5082 | } |
| 5083 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5084 | return 1; |
| 5085 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5086 | if (tmp == NULL) { |
| 5087 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 5088 | return 1; |
| 5089 | } |
| 5090 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5091 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5092 | res = obj2ast_expr(tmp, &value, arena); |
| 5093 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5094 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5095 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5096 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 5097 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5098 | if (*out == NULL) goto failed; |
| 5099 | return 0; |
| 5100 | } |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5101 | isinstance = PyObject_IsInstance(obj, (PyObject*)AnnAssign_type); |
| 5102 | if (isinstance == -1) { |
| 5103 | return 1; |
| 5104 | } |
| 5105 | if (isinstance) { |
| 5106 | expr_ty target; |
| 5107 | expr_ty annotation; |
| 5108 | expr_ty value; |
| 5109 | int simple; |
| 5110 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5111 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5112 | return 1; |
| 5113 | } |
| 5114 | if (tmp == NULL) { |
| 5115 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 5116 | return 1; |
| 5117 | } |
| 5118 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5119 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5120 | res = obj2ast_expr(tmp, &target, arena); |
| 5121 | if (res != 0) goto failed; |
| 5122 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5123 | } |
| 5124 | if (_PyObject_LookupAttrId(obj, &PyId_annotation, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5125 | return 1; |
| 5126 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5127 | if (tmp == NULL) { |
| 5128 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 5129 | return 1; |
| 5130 | } |
| 5131 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5132 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5133 | res = obj2ast_expr(tmp, &annotation, arena); |
| 5134 | if (res != 0) goto failed; |
| 5135 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5136 | } |
| 5137 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5138 | return 1; |
| 5139 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5140 | if (tmp == NULL || tmp == Py_None) { |
| 5141 | Py_CLEAR(tmp); |
| 5142 | value = NULL; |
| 5143 | } |
| 5144 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5145 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5146 | res = obj2ast_expr(tmp, &value, arena); |
| 5147 | if (res != 0) goto failed; |
| 5148 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5149 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5150 | if (_PyObject_LookupAttrId(obj, &PyId_simple, &tmp) < 0) { |
| 5151 | return 1; |
| 5152 | } |
| 5153 | if (tmp == NULL) { |
| 5154 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 5155 | return 1; |
| 5156 | } |
| 5157 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5158 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5159 | res = obj2ast_int(tmp, &simple, arena); |
| 5160 | if (res != 0) goto failed; |
| 5161 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5162 | } |
| 5163 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5164 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5165 | if (*out == NULL) goto failed; |
| 5166 | return 0; |
| 5167 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5168 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 5169 | if (isinstance == -1) { |
| 5170 | return 1; |
| 5171 | } |
| 5172 | if (isinstance) { |
| 5173 | expr_ty target; |
| 5174 | expr_ty iter; |
| 5175 | asdl_seq* body; |
| 5176 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5177 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5178 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5179 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5180 | return 1; |
| 5181 | } |
| 5182 | if (tmp == NULL) { |
| 5183 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 5184 | return 1; |
| 5185 | } |
| 5186 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5187 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5188 | res = obj2ast_expr(tmp, &target, arena); |
| 5189 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5190 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5191 | } |
| 5192 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5193 | return 1; |
| 5194 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5195 | if (tmp == NULL) { |
| 5196 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 5197 | return 1; |
| 5198 | } |
| 5199 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5200 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5201 | res = obj2ast_expr(tmp, &iter, arena); |
| 5202 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5203 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5204 | } |
| 5205 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5206 | return 1; |
| 5207 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5208 | if (tmp == NULL) { |
| 5209 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 5210 | return 1; |
| 5211 | } |
| 5212 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5213 | int res; |
| 5214 | Py_ssize_t len; |
| 5215 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5216 | if (!PyList_Check(tmp)) { |
| 5217 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5218 | goto failed; |
| 5219 | } |
| 5220 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5221 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5222 | if (body == NULL) goto failed; |
| 5223 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5224 | stmt_ty val; |
| 5225 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5226 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5227 | if (len != PyList_GET_SIZE(tmp)) { |
| 5228 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 5229 | goto failed; |
| 5230 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5231 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5232 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5233 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5234 | } |
| 5235 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5236 | return 1; |
| 5237 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5238 | if (tmp == NULL) { |
| 5239 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 5240 | return 1; |
| 5241 | } |
| 5242 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5243 | int res; |
| 5244 | Py_ssize_t len; |
| 5245 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5246 | if (!PyList_Check(tmp)) { |
| 5247 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5248 | goto failed; |
| 5249 | } |
| 5250 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5251 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5252 | if (orelse == NULL) goto failed; |
| 5253 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5254 | stmt_ty val; |
| 5255 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5256 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5257 | if (len != PyList_GET_SIZE(tmp)) { |
| 5258 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 5259 | goto failed; |
| 5260 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5261 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5262 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5263 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5264 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5265 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5266 | return 1; |
| 5267 | } |
| 5268 | if (tmp == NULL || tmp == Py_None) { |
| 5269 | Py_CLEAR(tmp); |
| 5270 | type_comment = NULL; |
| 5271 | } |
| 5272 | else { |
| 5273 | int res; |
| 5274 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5275 | if (res != 0) goto failed; |
| 5276 | Py_CLEAR(tmp); |
| 5277 | } |
| 5278 | *out = For(target, iter, body, orelse, type_comment, lineno, |
| 5279 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5280 | if (*out == NULL) goto failed; |
| 5281 | return 0; |
| 5282 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5283 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFor_type); |
| 5284 | if (isinstance == -1) { |
| 5285 | return 1; |
| 5286 | } |
| 5287 | if (isinstance) { |
| 5288 | expr_ty target; |
| 5289 | expr_ty iter; |
| 5290 | asdl_seq* body; |
| 5291 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5292 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5293 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5294 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5295 | return 1; |
| 5296 | } |
| 5297 | if (tmp == NULL) { |
| 5298 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 5299 | return 1; |
| 5300 | } |
| 5301 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5302 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5303 | res = obj2ast_expr(tmp, &target, arena); |
| 5304 | if (res != 0) goto failed; |
| 5305 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5306 | } |
| 5307 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5308 | return 1; |
| 5309 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5310 | if (tmp == NULL) { |
| 5311 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 5312 | return 1; |
| 5313 | } |
| 5314 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5315 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5316 | res = obj2ast_expr(tmp, &iter, arena); |
| 5317 | if (res != 0) goto failed; |
| 5318 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5319 | } |
| 5320 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5321 | return 1; |
| 5322 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5323 | if (tmp == NULL) { |
| 5324 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 5325 | return 1; |
| 5326 | } |
| 5327 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5328 | int res; |
| 5329 | Py_ssize_t len; |
| 5330 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5331 | if (!PyList_Check(tmp)) { |
| 5332 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5333 | goto failed; |
| 5334 | } |
| 5335 | len = PyList_GET_SIZE(tmp); |
| 5336 | body = _Py_asdl_seq_new(len, arena); |
| 5337 | if (body == NULL) goto failed; |
| 5338 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5339 | stmt_ty val; |
| 5340 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5341 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5342 | if (len != PyList_GET_SIZE(tmp)) { |
| 5343 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 5344 | goto failed; |
| 5345 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5346 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5347 | } |
| 5348 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5349 | } |
| 5350 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5351 | return 1; |
| 5352 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5353 | if (tmp == NULL) { |
| 5354 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 5355 | return 1; |
| 5356 | } |
| 5357 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5358 | int res; |
| 5359 | Py_ssize_t len; |
| 5360 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5361 | if (!PyList_Check(tmp)) { |
| 5362 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5363 | goto failed; |
| 5364 | } |
| 5365 | len = PyList_GET_SIZE(tmp); |
| 5366 | orelse = _Py_asdl_seq_new(len, arena); |
| 5367 | if (orelse == NULL) goto failed; |
| 5368 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5369 | stmt_ty val; |
| 5370 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5371 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5372 | if (len != PyList_GET_SIZE(tmp)) { |
| 5373 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 5374 | goto failed; |
| 5375 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5376 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5377 | } |
| 5378 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5379 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5380 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5381 | return 1; |
| 5382 | } |
| 5383 | if (tmp == NULL || tmp == Py_None) { |
| 5384 | Py_CLEAR(tmp); |
| 5385 | type_comment = NULL; |
| 5386 | } |
| 5387 | else { |
| 5388 | int res; |
| 5389 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5390 | if (res != 0) goto failed; |
| 5391 | Py_CLEAR(tmp); |
| 5392 | } |
| 5393 | *out = AsyncFor(target, iter, body, orelse, type_comment, lineno, |
| 5394 | col_offset, end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5395 | if (*out == NULL) goto failed; |
| 5396 | return 0; |
| 5397 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5398 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 5399 | if (isinstance == -1) { |
| 5400 | return 1; |
| 5401 | } |
| 5402 | if (isinstance) { |
| 5403 | expr_ty test; |
| 5404 | asdl_seq* body; |
| 5405 | asdl_seq* orelse; |
| 5406 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5407 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 5408 | return 1; |
| 5409 | } |
| 5410 | if (tmp == NULL) { |
| 5411 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 5412 | return 1; |
| 5413 | } |
| 5414 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5415 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5416 | res = obj2ast_expr(tmp, &test, arena); |
| 5417 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5418 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5419 | } |
| 5420 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5421 | return 1; |
| 5422 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5423 | if (tmp == NULL) { |
| 5424 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 5425 | return 1; |
| 5426 | } |
| 5427 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5428 | int res; |
| 5429 | Py_ssize_t len; |
| 5430 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5431 | if (!PyList_Check(tmp)) { |
| 5432 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5433 | goto failed; |
| 5434 | } |
| 5435 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5436 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5437 | if (body == NULL) goto failed; |
| 5438 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5439 | stmt_ty val; |
| 5440 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5441 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5442 | if (len != PyList_GET_SIZE(tmp)) { |
| 5443 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 5444 | goto failed; |
| 5445 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5446 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5447 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5448 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5449 | } |
| 5450 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5451 | return 1; |
| 5452 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5453 | if (tmp == NULL) { |
| 5454 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 5455 | return 1; |
| 5456 | } |
| 5457 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5458 | int res; |
| 5459 | Py_ssize_t len; |
| 5460 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5461 | if (!PyList_Check(tmp)) { |
| 5462 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5463 | goto failed; |
| 5464 | } |
| 5465 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5466 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5467 | if (orelse == NULL) goto failed; |
| 5468 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5469 | stmt_ty val; |
| 5470 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5471 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5472 | if (len != PyList_GET_SIZE(tmp)) { |
| 5473 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 5474 | goto failed; |
| 5475 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5476 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5477 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5478 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5479 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5480 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 5481 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5482 | if (*out == NULL) goto failed; |
| 5483 | return 0; |
| 5484 | } |
| 5485 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 5486 | if (isinstance == -1) { |
| 5487 | return 1; |
| 5488 | } |
| 5489 | if (isinstance) { |
| 5490 | expr_ty test; |
| 5491 | asdl_seq* body; |
| 5492 | asdl_seq* orelse; |
| 5493 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5494 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 5495 | return 1; |
| 5496 | } |
| 5497 | if (tmp == NULL) { |
| 5498 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 5499 | return 1; |
| 5500 | } |
| 5501 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5502 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5503 | res = obj2ast_expr(tmp, &test, arena); |
| 5504 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5505 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5506 | } |
| 5507 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5508 | return 1; |
| 5509 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5510 | if (tmp == NULL) { |
| 5511 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 5512 | return 1; |
| 5513 | } |
| 5514 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5515 | int res; |
| 5516 | Py_ssize_t len; |
| 5517 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5518 | if (!PyList_Check(tmp)) { |
| 5519 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5520 | goto failed; |
| 5521 | } |
| 5522 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5523 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5524 | if (body == NULL) goto failed; |
| 5525 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5526 | stmt_ty val; |
| 5527 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5528 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5529 | if (len != PyList_GET_SIZE(tmp)) { |
| 5530 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 5531 | goto failed; |
| 5532 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5533 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5534 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5535 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5536 | } |
| 5537 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5538 | return 1; |
| 5539 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5540 | if (tmp == NULL) { |
| 5541 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 5542 | return 1; |
| 5543 | } |
| 5544 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5545 | int res; |
| 5546 | Py_ssize_t len; |
| 5547 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5548 | if (!PyList_Check(tmp)) { |
| 5549 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5550 | goto failed; |
| 5551 | } |
| 5552 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5553 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5554 | if (orelse == NULL) goto failed; |
| 5555 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5556 | stmt_ty val; |
| 5557 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5558 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5559 | if (len != PyList_GET_SIZE(tmp)) { |
| 5560 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 5561 | goto failed; |
| 5562 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5563 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5564 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5565 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5566 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5567 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 5568 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5569 | if (*out == NULL) goto failed; |
| 5570 | return 0; |
| 5571 | } |
| 5572 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 5573 | if (isinstance == -1) { |
| 5574 | return 1; |
| 5575 | } |
| 5576 | if (isinstance) { |
| 5577 | asdl_seq* items; |
| 5578 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5579 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5580 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5581 | if (_PyObject_LookupAttrId(obj, &PyId_items, &tmp) < 0) { |
| 5582 | return 1; |
| 5583 | } |
| 5584 | if (tmp == NULL) { |
| 5585 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 5586 | return 1; |
| 5587 | } |
| 5588 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5589 | int res; |
| 5590 | Py_ssize_t len; |
| 5591 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5592 | if (!PyList_Check(tmp)) { |
| 5593 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5594 | goto failed; |
| 5595 | } |
| 5596 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5597 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5598 | if (items == NULL) goto failed; |
| 5599 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5600 | withitem_ty val; |
| 5601 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5602 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5603 | if (len != PyList_GET_SIZE(tmp)) { |
| 5604 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 5605 | goto failed; |
| 5606 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5607 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5608 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5609 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5610 | } |
| 5611 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5612 | return 1; |
| 5613 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5614 | if (tmp == NULL) { |
| 5615 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 5616 | return 1; |
| 5617 | } |
| 5618 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5619 | int res; |
| 5620 | Py_ssize_t len; |
| 5621 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5622 | if (!PyList_Check(tmp)) { |
| 5623 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5624 | goto failed; |
| 5625 | } |
| 5626 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5627 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5628 | if (body == NULL) goto failed; |
| 5629 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5630 | stmt_ty val; |
| 5631 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5632 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5633 | if (len != PyList_GET_SIZE(tmp)) { |
| 5634 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 5635 | goto failed; |
| 5636 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5637 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5638 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5639 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5640 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5641 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5642 | return 1; |
| 5643 | } |
| 5644 | if (tmp == NULL || tmp == Py_None) { |
| 5645 | Py_CLEAR(tmp); |
| 5646 | type_comment = NULL; |
| 5647 | } |
| 5648 | else { |
| 5649 | int res; |
| 5650 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5651 | if (res != 0) goto failed; |
| 5652 | Py_CLEAR(tmp); |
| 5653 | } |
| 5654 | *out = With(items, body, type_comment, lineno, col_offset, end_lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5655 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5656 | if (*out == NULL) goto failed; |
| 5657 | return 0; |
| 5658 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5659 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncWith_type); |
| 5660 | if (isinstance == -1) { |
| 5661 | return 1; |
| 5662 | } |
| 5663 | if (isinstance) { |
| 5664 | asdl_seq* items; |
| 5665 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5666 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5667 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5668 | if (_PyObject_LookupAttrId(obj, &PyId_items, &tmp) < 0) { |
| 5669 | return 1; |
| 5670 | } |
| 5671 | if (tmp == NULL) { |
| 5672 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 5673 | return 1; |
| 5674 | } |
| 5675 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5676 | int res; |
| 5677 | Py_ssize_t len; |
| 5678 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5679 | if (!PyList_Check(tmp)) { |
| 5680 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5681 | goto failed; |
| 5682 | } |
| 5683 | len = PyList_GET_SIZE(tmp); |
| 5684 | items = _Py_asdl_seq_new(len, arena); |
| 5685 | if (items == NULL) goto failed; |
| 5686 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5687 | withitem_ty val; |
| 5688 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5689 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5690 | if (len != PyList_GET_SIZE(tmp)) { |
| 5691 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 5692 | goto failed; |
| 5693 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5694 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5695 | } |
| 5696 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5697 | } |
| 5698 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5699 | return 1; |
| 5700 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5701 | if (tmp == NULL) { |
| 5702 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 5703 | return 1; |
| 5704 | } |
| 5705 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5706 | int res; |
| 5707 | Py_ssize_t len; |
| 5708 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5709 | if (!PyList_Check(tmp)) { |
| 5710 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5711 | goto failed; |
| 5712 | } |
| 5713 | len = PyList_GET_SIZE(tmp); |
| 5714 | body = _Py_asdl_seq_new(len, arena); |
| 5715 | if (body == NULL) goto failed; |
| 5716 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5717 | stmt_ty val; |
| 5718 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5719 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5720 | if (len != PyList_GET_SIZE(tmp)) { |
| 5721 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 5722 | goto failed; |
| 5723 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5724 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5725 | } |
| 5726 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5727 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5728 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5729 | return 1; |
| 5730 | } |
| 5731 | if (tmp == NULL || tmp == Py_None) { |
| 5732 | Py_CLEAR(tmp); |
| 5733 | type_comment = NULL; |
| 5734 | } |
| 5735 | else { |
| 5736 | int res; |
| 5737 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5738 | if (res != 0) goto failed; |
| 5739 | Py_CLEAR(tmp); |
| 5740 | } |
| 5741 | *out = AsyncWith(items, body, type_comment, lineno, col_offset, |
| 5742 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5743 | if (*out == NULL) goto failed; |
| 5744 | return 0; |
| 5745 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5746 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 5747 | if (isinstance == -1) { |
| 5748 | return 1; |
| 5749 | } |
| 5750 | if (isinstance) { |
| 5751 | expr_ty exc; |
| 5752 | expr_ty cause; |
| 5753 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5754 | if (_PyObject_LookupAttrId(obj, &PyId_exc, &tmp) < 0) { |
| 5755 | return 1; |
| 5756 | } |
| 5757 | if (tmp == NULL || tmp == Py_None) { |
| 5758 | Py_CLEAR(tmp); |
| 5759 | exc = NULL; |
| 5760 | } |
| 5761 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5762 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5763 | res = obj2ast_expr(tmp, &exc, arena); |
| 5764 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5765 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5766 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5767 | if (_PyObject_LookupAttrId(obj, &PyId_cause, &tmp) < 0) { |
| 5768 | return 1; |
| 5769 | } |
| 5770 | if (tmp == NULL || tmp == Py_None) { |
| 5771 | Py_CLEAR(tmp); |
| 5772 | cause = NULL; |
| 5773 | } |
| 5774 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5775 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5776 | res = obj2ast_expr(tmp, &cause, arena); |
| 5777 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5778 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5779 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5780 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 5781 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5782 | if (*out == NULL) goto failed; |
| 5783 | return 0; |
| 5784 | } |
| 5785 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
| 5786 | if (isinstance == -1) { |
| 5787 | return 1; |
| 5788 | } |
| 5789 | if (isinstance) { |
| 5790 | asdl_seq* body; |
| 5791 | asdl_seq* handlers; |
| 5792 | asdl_seq* orelse; |
| 5793 | asdl_seq* finalbody; |
| 5794 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5795 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 5796 | return 1; |
| 5797 | } |
| 5798 | if (tmp == NULL) { |
| 5799 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 5800 | return 1; |
| 5801 | } |
| 5802 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5803 | int res; |
| 5804 | Py_ssize_t len; |
| 5805 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5806 | if (!PyList_Check(tmp)) { |
| 5807 | PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5808 | goto failed; |
| 5809 | } |
| 5810 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5811 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5812 | if (body == NULL) goto failed; |
| 5813 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5814 | stmt_ty val; |
| 5815 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5816 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5817 | if (len != PyList_GET_SIZE(tmp)) { |
| 5818 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 5819 | goto failed; |
| 5820 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5821 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5822 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5823 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5824 | } |
| 5825 | if (_PyObject_LookupAttrId(obj, &PyId_handlers, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5826 | return 1; |
| 5827 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5828 | if (tmp == NULL) { |
| 5829 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 5830 | return 1; |
| 5831 | } |
| 5832 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5833 | int res; |
| 5834 | Py_ssize_t len; |
| 5835 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5836 | if (!PyList_Check(tmp)) { |
| 5837 | PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5838 | goto failed; |
| 5839 | } |
| 5840 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5841 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5842 | if (handlers == NULL) goto failed; |
| 5843 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5844 | excepthandler_ty val; |
| 5845 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5846 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5847 | if (len != PyList_GET_SIZE(tmp)) { |
| 5848 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 5849 | goto failed; |
| 5850 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5851 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5852 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5853 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5854 | } |
| 5855 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5856 | return 1; |
| 5857 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5858 | if (tmp == NULL) { |
| 5859 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 5860 | return 1; |
| 5861 | } |
| 5862 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5863 | int res; |
| 5864 | Py_ssize_t len; |
| 5865 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5866 | if (!PyList_Check(tmp)) { |
| 5867 | PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5868 | goto failed; |
| 5869 | } |
| 5870 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5871 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5872 | if (orelse == NULL) goto failed; |
| 5873 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5874 | stmt_ty val; |
| 5875 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5876 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5877 | if (len != PyList_GET_SIZE(tmp)) { |
| 5878 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 5879 | goto failed; |
| 5880 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5881 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5882 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5883 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5884 | } |
| 5885 | if (_PyObject_LookupAttrId(obj, &PyId_finalbody, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5886 | return 1; |
| 5887 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5888 | if (tmp == NULL) { |
| 5889 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 5890 | return 1; |
| 5891 | } |
| 5892 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5893 | int res; |
| 5894 | Py_ssize_t len; |
| 5895 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5896 | if (!PyList_Check(tmp)) { |
| 5897 | PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5898 | goto failed; |
| 5899 | } |
| 5900 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5901 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5902 | if (finalbody == NULL) goto failed; |
| 5903 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5904 | stmt_ty val; |
| 5905 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5906 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5907 | if (len != PyList_GET_SIZE(tmp)) { |
| 5908 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 5909 | goto failed; |
| 5910 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5911 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5912 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5913 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5914 | } |
| 5915 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5916 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5917 | if (*out == NULL) goto failed; |
| 5918 | return 0; |
| 5919 | } |
| 5920 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 5921 | if (isinstance == -1) { |
| 5922 | return 1; |
| 5923 | } |
| 5924 | if (isinstance) { |
| 5925 | expr_ty test; |
| 5926 | expr_ty msg; |
| 5927 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5928 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 5929 | return 1; |
| 5930 | } |
| 5931 | if (tmp == NULL) { |
| 5932 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 5933 | return 1; |
| 5934 | } |
| 5935 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5936 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5937 | res = obj2ast_expr(tmp, &test, arena); |
| 5938 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5939 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5940 | } |
| 5941 | if (_PyObject_LookupAttrId(obj, &PyId_msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5942 | return 1; |
| 5943 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5944 | if (tmp == NULL || tmp == Py_None) { |
| 5945 | Py_CLEAR(tmp); |
| 5946 | msg = NULL; |
| 5947 | } |
| 5948 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5949 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5950 | res = obj2ast_expr(tmp, &msg, arena); |
| 5951 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5952 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5953 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5954 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 5955 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5956 | if (*out == NULL) goto failed; |
| 5957 | return 0; |
| 5958 | } |
| 5959 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 5960 | if (isinstance == -1) { |
| 5961 | return 1; |
| 5962 | } |
| 5963 | if (isinstance) { |
| 5964 | asdl_seq* names; |
| 5965 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5966 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 5967 | return 1; |
| 5968 | } |
| 5969 | if (tmp == NULL) { |
| 5970 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 5971 | return 1; |
| 5972 | } |
| 5973 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5974 | int res; |
| 5975 | Py_ssize_t len; |
| 5976 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5977 | if (!PyList_Check(tmp)) { |
| 5978 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5979 | goto failed; |
| 5980 | } |
| 5981 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5982 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5983 | if (names == NULL) goto failed; |
| 5984 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5985 | alias_ty val; |
| 5986 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5987 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5988 | if (len != PyList_GET_SIZE(tmp)) { |
| 5989 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 5990 | goto failed; |
| 5991 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5992 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5993 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5994 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5995 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5996 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 5997 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5998 | if (*out == NULL) goto failed; |
| 5999 | return 0; |
| 6000 | } |
| 6001 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 6002 | if (isinstance == -1) { |
| 6003 | return 1; |
| 6004 | } |
| 6005 | if (isinstance) { |
| 6006 | identifier module; |
| 6007 | asdl_seq* names; |
| 6008 | int level; |
| 6009 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6010 | if (_PyObject_LookupAttrId(obj, &PyId_module, &tmp) < 0) { |
| 6011 | return 1; |
| 6012 | } |
| 6013 | if (tmp == NULL || tmp == Py_None) { |
| 6014 | Py_CLEAR(tmp); |
| 6015 | module = NULL; |
| 6016 | } |
| 6017 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6018 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6019 | res = obj2ast_identifier(tmp, &module, arena); |
| 6020 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6021 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6022 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6023 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 6024 | return 1; |
| 6025 | } |
| 6026 | if (tmp == NULL) { |
| 6027 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 6028 | return 1; |
| 6029 | } |
| 6030 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6031 | int res; |
| 6032 | Py_ssize_t len; |
| 6033 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6034 | if (!PyList_Check(tmp)) { |
| 6035 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6036 | goto failed; |
| 6037 | } |
| 6038 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6039 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6040 | if (names == NULL) goto failed; |
| 6041 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6042 | alias_ty val; |
| 6043 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6044 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6045 | if (len != PyList_GET_SIZE(tmp)) { |
| 6046 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 6047 | goto failed; |
| 6048 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6049 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6050 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6051 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6052 | } |
| 6053 | if (_PyObject_LookupAttrId(obj, &PyId_level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6054 | return 1; |
| 6055 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6056 | if (tmp == NULL || tmp == Py_None) { |
| 6057 | Py_CLEAR(tmp); |
| 6058 | level = 0; |
| 6059 | } |
| 6060 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6061 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6062 | res = obj2ast_int(tmp, &level, arena); |
| 6063 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6064 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6065 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6066 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 6067 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6068 | if (*out == NULL) goto failed; |
| 6069 | return 0; |
| 6070 | } |
| 6071 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 6072 | if (isinstance == -1) { |
| 6073 | return 1; |
| 6074 | } |
| 6075 | if (isinstance) { |
| 6076 | asdl_seq* names; |
| 6077 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6078 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 6079 | return 1; |
| 6080 | } |
| 6081 | if (tmp == NULL) { |
| 6082 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 6083 | return 1; |
| 6084 | } |
| 6085 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6086 | int res; |
| 6087 | Py_ssize_t len; |
| 6088 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6089 | if (!PyList_Check(tmp)) { |
| 6090 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6091 | goto failed; |
| 6092 | } |
| 6093 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6094 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6095 | if (names == NULL) goto failed; |
| 6096 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6097 | identifier val; |
| 6098 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6099 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6100 | if (len != PyList_GET_SIZE(tmp)) { |
| 6101 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 6102 | goto failed; |
| 6103 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6104 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6105 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6106 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6107 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6108 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6109 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6110 | if (*out == NULL) goto failed; |
| 6111 | return 0; |
| 6112 | } |
| 6113 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 6114 | if (isinstance == -1) { |
| 6115 | return 1; |
| 6116 | } |
| 6117 | if (isinstance) { |
| 6118 | asdl_seq* names; |
| 6119 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6120 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 6121 | return 1; |
| 6122 | } |
| 6123 | if (tmp == NULL) { |
| 6124 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 6125 | return 1; |
| 6126 | } |
| 6127 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6128 | int res; |
| 6129 | Py_ssize_t len; |
| 6130 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6131 | if (!PyList_Check(tmp)) { |
| 6132 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6133 | goto failed; |
| 6134 | } |
| 6135 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6136 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6137 | if (names == NULL) goto failed; |
| 6138 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6139 | identifier val; |
| 6140 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6141 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6142 | if (len != PyList_GET_SIZE(tmp)) { |
| 6143 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 6144 | goto failed; |
| 6145 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6146 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6147 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6148 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6149 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6150 | *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6151 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6152 | if (*out == NULL) goto failed; |
| 6153 | return 0; |
| 6154 | } |
| 6155 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 6156 | if (isinstance == -1) { |
| 6157 | return 1; |
| 6158 | } |
| 6159 | if (isinstance) { |
| 6160 | expr_ty value; |
| 6161 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6162 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6163 | return 1; |
| 6164 | } |
| 6165 | if (tmp == NULL) { |
| 6166 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 6167 | return 1; |
| 6168 | } |
| 6169 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6170 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6171 | res = obj2ast_expr(tmp, &value, arena); |
| 6172 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6173 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6174 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6175 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6176 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6177 | if (*out == NULL) goto failed; |
| 6178 | return 0; |
| 6179 | } |
| 6180 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 6181 | if (isinstance == -1) { |
| 6182 | return 1; |
| 6183 | } |
| 6184 | if (isinstance) { |
| 6185 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6186 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6187 | if (*out == NULL) goto failed; |
| 6188 | return 0; |
| 6189 | } |
| 6190 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 6191 | if (isinstance == -1) { |
| 6192 | return 1; |
| 6193 | } |
| 6194 | if (isinstance) { |
| 6195 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6196 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6197 | if (*out == NULL) goto failed; |
| 6198 | return 0; |
| 6199 | } |
| 6200 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 6201 | if (isinstance == -1) { |
| 6202 | return 1; |
| 6203 | } |
| 6204 | if (isinstance) { |
| 6205 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6206 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6207 | if (*out == NULL) goto failed; |
| 6208 | return 0; |
| 6209 | } |
| 6210 | |
| 6211 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 6212 | failed: |
| 6213 | Py_XDECREF(tmp); |
| 6214 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6215 | } |
| 6216 | |
| 6217 | int |
| 6218 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 6219 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6220 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6221 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6222 | PyObject *tmp = NULL; |
| 6223 | int lineno; |
| 6224 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6225 | int end_lineno; |
| 6226 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6227 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6228 | if (obj == Py_None) { |
| 6229 | *out = NULL; |
| 6230 | return 0; |
| 6231 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6232 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 6233 | return 1; |
| 6234 | } |
| 6235 | if (tmp == NULL) { |
| 6236 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 6237 | return 1; |
| 6238 | } |
| 6239 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6240 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6241 | res = obj2ast_int(tmp, &lineno, arena); |
| 6242 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6243 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6244 | } |
| 6245 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6246 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6247 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6248 | if (tmp == NULL) { |
| 6249 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 6250 | return 1; |
| 6251 | } |
| 6252 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6253 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6254 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6255 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6256 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6257 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6258 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 6259 | return 1; |
| 6260 | } |
| 6261 | if (tmp == NULL || tmp == Py_None) { |
| 6262 | Py_CLEAR(tmp); |
| 6263 | end_lineno = 0; |
| 6264 | } |
| 6265 | else { |
| 6266 | int res; |
| 6267 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 6268 | if (res != 0) goto failed; |
| 6269 | Py_CLEAR(tmp); |
| 6270 | } |
| 6271 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 6272 | return 1; |
| 6273 | } |
| 6274 | if (tmp == NULL || tmp == Py_None) { |
| 6275 | Py_CLEAR(tmp); |
| 6276 | end_col_offset = 0; |
| 6277 | } |
| 6278 | else { |
| 6279 | int res; |
| 6280 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 6281 | if (res != 0) goto failed; |
| 6282 | Py_CLEAR(tmp); |
| 6283 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6284 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 6285 | if (isinstance == -1) { |
| 6286 | return 1; |
| 6287 | } |
| 6288 | if (isinstance) { |
| 6289 | boolop_ty op; |
| 6290 | asdl_seq* values; |
| 6291 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6292 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
| 6293 | return 1; |
| 6294 | } |
| 6295 | if (tmp == NULL) { |
| 6296 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 6297 | return 1; |
| 6298 | } |
| 6299 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6300 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6301 | res = obj2ast_boolop(tmp, &op, arena); |
| 6302 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6303 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6304 | } |
| 6305 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6306 | return 1; |
| 6307 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6308 | if (tmp == NULL) { |
| 6309 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 6310 | return 1; |
| 6311 | } |
| 6312 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6313 | int res; |
| 6314 | Py_ssize_t len; |
| 6315 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6316 | if (!PyList_Check(tmp)) { |
| 6317 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6318 | goto failed; |
| 6319 | } |
| 6320 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6321 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6322 | if (values == NULL) goto failed; |
| 6323 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6324 | expr_ty val; |
| 6325 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6326 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6327 | if (len != PyList_GET_SIZE(tmp)) { |
| 6328 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 6329 | goto failed; |
| 6330 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6331 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6332 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6333 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6334 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6335 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 6336 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6337 | if (*out == NULL) goto failed; |
| 6338 | return 0; |
| 6339 | } |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 6340 | isinstance = PyObject_IsInstance(obj, (PyObject*)NamedExpr_type); |
| 6341 | if (isinstance == -1) { |
| 6342 | return 1; |
| 6343 | } |
| 6344 | if (isinstance) { |
| 6345 | expr_ty target; |
| 6346 | expr_ty value; |
| 6347 | |
| 6348 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 6349 | return 1; |
| 6350 | } |
| 6351 | if (tmp == NULL) { |
| 6352 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); |
| 6353 | return 1; |
| 6354 | } |
| 6355 | else { |
| 6356 | int res; |
| 6357 | res = obj2ast_expr(tmp, &target, arena); |
| 6358 | if (res != 0) goto failed; |
| 6359 | Py_CLEAR(tmp); |
| 6360 | } |
| 6361 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6362 | return 1; |
| 6363 | } |
| 6364 | if (tmp == NULL) { |
| 6365 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); |
| 6366 | return 1; |
| 6367 | } |
| 6368 | else { |
| 6369 | int res; |
| 6370 | res = obj2ast_expr(tmp, &value, arena); |
| 6371 | if (res != 0) goto failed; |
| 6372 | Py_CLEAR(tmp); |
| 6373 | } |
| 6374 | *out = NamedExpr(target, value, lineno, col_offset, end_lineno, |
| 6375 | end_col_offset, arena); |
| 6376 | if (*out == NULL) goto failed; |
| 6377 | return 0; |
| 6378 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6379 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 6380 | if (isinstance == -1) { |
| 6381 | return 1; |
| 6382 | } |
| 6383 | if (isinstance) { |
| 6384 | expr_ty left; |
| 6385 | operator_ty op; |
| 6386 | expr_ty right; |
| 6387 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6388 | if (_PyObject_LookupAttrId(obj, &PyId_left, &tmp) < 0) { |
| 6389 | return 1; |
| 6390 | } |
| 6391 | if (tmp == NULL) { |
| 6392 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 6393 | return 1; |
| 6394 | } |
| 6395 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6396 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6397 | res = obj2ast_expr(tmp, &left, arena); |
| 6398 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6399 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6400 | } |
| 6401 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6402 | return 1; |
| 6403 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6404 | if (tmp == NULL) { |
| 6405 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 6406 | return 1; |
| 6407 | } |
| 6408 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6409 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6410 | res = obj2ast_operator(tmp, &op, arena); |
| 6411 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6412 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6413 | } |
| 6414 | if (_PyObject_LookupAttrId(obj, &PyId_right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6415 | return 1; |
| 6416 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6417 | if (tmp == NULL) { |
| 6418 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 6419 | return 1; |
| 6420 | } |
| 6421 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6422 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6423 | res = obj2ast_expr(tmp, &right, arena); |
| 6424 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6425 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6426 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6427 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 6428 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6429 | if (*out == NULL) goto failed; |
| 6430 | return 0; |
| 6431 | } |
| 6432 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 6433 | if (isinstance == -1) { |
| 6434 | return 1; |
| 6435 | } |
| 6436 | if (isinstance) { |
| 6437 | unaryop_ty op; |
| 6438 | expr_ty operand; |
| 6439 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6440 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
| 6441 | return 1; |
| 6442 | } |
| 6443 | if (tmp == NULL) { |
| 6444 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 6445 | return 1; |
| 6446 | } |
| 6447 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6448 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6449 | res = obj2ast_unaryop(tmp, &op, arena); |
| 6450 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6451 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6452 | } |
| 6453 | if (_PyObject_LookupAttrId(obj, &PyId_operand, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6454 | return 1; |
| 6455 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6456 | if (tmp == NULL) { |
| 6457 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 6458 | return 1; |
| 6459 | } |
| 6460 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6461 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6462 | res = obj2ast_expr(tmp, &operand, arena); |
| 6463 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6464 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6465 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6466 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 6467 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6468 | if (*out == NULL) goto failed; |
| 6469 | return 0; |
| 6470 | } |
| 6471 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 6472 | if (isinstance == -1) { |
| 6473 | return 1; |
| 6474 | } |
| 6475 | if (isinstance) { |
| 6476 | arguments_ty args; |
| 6477 | expr_ty body; |
| 6478 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6479 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
| 6480 | return 1; |
| 6481 | } |
| 6482 | if (tmp == NULL) { |
| 6483 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 6484 | return 1; |
| 6485 | } |
| 6486 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6487 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6488 | res = obj2ast_arguments(tmp, &args, arena); |
| 6489 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6490 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6491 | } |
| 6492 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6493 | return 1; |
| 6494 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6495 | if (tmp == NULL) { |
| 6496 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 6497 | return 1; |
| 6498 | } |
| 6499 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6500 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6501 | res = obj2ast_expr(tmp, &body, arena); |
| 6502 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6503 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6504 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6505 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 6506 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6507 | if (*out == NULL) goto failed; |
| 6508 | return 0; |
| 6509 | } |
| 6510 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 6511 | if (isinstance == -1) { |
| 6512 | return 1; |
| 6513 | } |
| 6514 | if (isinstance) { |
| 6515 | expr_ty test; |
| 6516 | expr_ty body; |
| 6517 | expr_ty orelse; |
| 6518 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6519 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 6520 | return 1; |
| 6521 | } |
| 6522 | if (tmp == NULL) { |
| 6523 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 6524 | return 1; |
| 6525 | } |
| 6526 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6527 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6528 | res = obj2ast_expr(tmp, &test, arena); |
| 6529 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6530 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6531 | } |
| 6532 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6533 | return 1; |
| 6534 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6535 | if (tmp == NULL) { |
| 6536 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 6537 | return 1; |
| 6538 | } |
| 6539 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6540 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6541 | res = obj2ast_expr(tmp, &body, arena); |
| 6542 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6543 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6544 | } |
| 6545 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6546 | return 1; |
| 6547 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6548 | if (tmp == NULL) { |
| 6549 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 6550 | return 1; |
| 6551 | } |
| 6552 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6553 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6554 | res = obj2ast_expr(tmp, &orelse, arena); |
| 6555 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6556 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6557 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6558 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 6559 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6560 | if (*out == NULL) goto failed; |
| 6561 | return 0; |
| 6562 | } |
| 6563 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 6564 | if (isinstance == -1) { |
| 6565 | return 1; |
| 6566 | } |
| 6567 | if (isinstance) { |
| 6568 | asdl_seq* keys; |
| 6569 | asdl_seq* values; |
| 6570 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6571 | if (_PyObject_LookupAttrId(obj, &PyId_keys, &tmp) < 0) { |
| 6572 | return 1; |
| 6573 | } |
| 6574 | if (tmp == NULL) { |
| 6575 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 6576 | return 1; |
| 6577 | } |
| 6578 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6579 | int res; |
| 6580 | Py_ssize_t len; |
| 6581 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6582 | if (!PyList_Check(tmp)) { |
| 6583 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6584 | goto failed; |
| 6585 | } |
| 6586 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6587 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6588 | if (keys == NULL) goto failed; |
| 6589 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6590 | expr_ty val; |
| 6591 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6592 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6593 | if (len != PyList_GET_SIZE(tmp)) { |
| 6594 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 6595 | goto failed; |
| 6596 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6597 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6598 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6599 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6600 | } |
| 6601 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6602 | return 1; |
| 6603 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6604 | if (tmp == NULL) { |
| 6605 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 6606 | return 1; |
| 6607 | } |
| 6608 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6609 | int res; |
| 6610 | Py_ssize_t len; |
| 6611 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6612 | if (!PyList_Check(tmp)) { |
| 6613 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6614 | goto failed; |
| 6615 | } |
| 6616 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6617 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6618 | if (values == NULL) goto failed; |
| 6619 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6620 | expr_ty val; |
| 6621 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6622 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6623 | if (len != PyList_GET_SIZE(tmp)) { |
| 6624 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 6625 | goto failed; |
| 6626 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6627 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6628 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6629 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6630 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6631 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 6632 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6633 | if (*out == NULL) goto failed; |
| 6634 | return 0; |
| 6635 | } |
| 6636 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 6637 | if (isinstance == -1) { |
| 6638 | return 1; |
| 6639 | } |
| 6640 | if (isinstance) { |
| 6641 | asdl_seq* elts; |
| 6642 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6643 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 6644 | return 1; |
| 6645 | } |
| 6646 | if (tmp == NULL) { |
| 6647 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 6648 | return 1; |
| 6649 | } |
| 6650 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6651 | int res; |
| 6652 | Py_ssize_t len; |
| 6653 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6654 | if (!PyList_Check(tmp)) { |
| 6655 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6656 | goto failed; |
| 6657 | } |
| 6658 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6659 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6660 | if (elts == NULL) goto failed; |
| 6661 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6662 | expr_ty val; |
| 6663 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6664 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6665 | if (len != PyList_GET_SIZE(tmp)) { |
| 6666 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 6667 | goto failed; |
| 6668 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6669 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6670 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6671 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6672 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6673 | *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6674 | if (*out == NULL) goto failed; |
| 6675 | return 0; |
| 6676 | } |
| 6677 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 6678 | if (isinstance == -1) { |
| 6679 | return 1; |
| 6680 | } |
| 6681 | if (isinstance) { |
| 6682 | expr_ty elt; |
| 6683 | asdl_seq* generators; |
| 6684 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6685 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6686 | return 1; |
| 6687 | } |
| 6688 | if (tmp == NULL) { |
| 6689 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 6690 | return 1; |
| 6691 | } |
| 6692 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6693 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6694 | res = obj2ast_expr(tmp, &elt, arena); |
| 6695 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6696 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6697 | } |
| 6698 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6699 | return 1; |
| 6700 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6701 | if (tmp == NULL) { |
| 6702 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 6703 | return 1; |
| 6704 | } |
| 6705 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6706 | int res; |
| 6707 | Py_ssize_t len; |
| 6708 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6709 | if (!PyList_Check(tmp)) { |
| 6710 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6711 | goto failed; |
| 6712 | } |
| 6713 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6714 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6715 | if (generators == NULL) goto failed; |
| 6716 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6717 | comprehension_ty val; |
| 6718 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6719 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6720 | if (len != PyList_GET_SIZE(tmp)) { |
| 6721 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 6722 | goto failed; |
| 6723 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6724 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6725 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6726 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6727 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6728 | *out = ListComp(elt, generators, lineno, col_offset, end_lineno, |
| 6729 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6730 | if (*out == NULL) goto failed; |
| 6731 | return 0; |
| 6732 | } |
| 6733 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 6734 | if (isinstance == -1) { |
| 6735 | return 1; |
| 6736 | } |
| 6737 | if (isinstance) { |
| 6738 | expr_ty elt; |
| 6739 | asdl_seq* generators; |
| 6740 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6741 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6742 | return 1; |
| 6743 | } |
| 6744 | if (tmp == NULL) { |
| 6745 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 6746 | return 1; |
| 6747 | } |
| 6748 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6749 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6750 | res = obj2ast_expr(tmp, &elt, arena); |
| 6751 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6752 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6753 | } |
| 6754 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6755 | return 1; |
| 6756 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6757 | if (tmp == NULL) { |
| 6758 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 6759 | return 1; |
| 6760 | } |
| 6761 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6762 | int res; |
| 6763 | Py_ssize_t len; |
| 6764 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6765 | if (!PyList_Check(tmp)) { |
| 6766 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6767 | goto failed; |
| 6768 | } |
| 6769 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6770 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6771 | if (generators == NULL) goto failed; |
| 6772 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6773 | comprehension_ty val; |
| 6774 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6775 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6776 | if (len != PyList_GET_SIZE(tmp)) { |
| 6777 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 6778 | goto failed; |
| 6779 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6780 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6781 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6782 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6783 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6784 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 6785 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6786 | if (*out == NULL) goto failed; |
| 6787 | return 0; |
| 6788 | } |
| 6789 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 6790 | if (isinstance == -1) { |
| 6791 | return 1; |
| 6792 | } |
| 6793 | if (isinstance) { |
| 6794 | expr_ty key; |
| 6795 | expr_ty value; |
| 6796 | asdl_seq* generators; |
| 6797 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6798 | if (_PyObject_LookupAttrId(obj, &PyId_key, &tmp) < 0) { |
| 6799 | return 1; |
| 6800 | } |
| 6801 | if (tmp == NULL) { |
| 6802 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 6803 | return 1; |
| 6804 | } |
| 6805 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6806 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6807 | res = obj2ast_expr(tmp, &key, arena); |
| 6808 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6809 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6810 | } |
| 6811 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6812 | return 1; |
| 6813 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6814 | if (tmp == NULL) { |
| 6815 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 6816 | return 1; |
| 6817 | } |
| 6818 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6819 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6820 | res = obj2ast_expr(tmp, &value, arena); |
| 6821 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6822 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6823 | } |
| 6824 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6825 | return 1; |
| 6826 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6827 | if (tmp == NULL) { |
| 6828 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 6829 | return 1; |
| 6830 | } |
| 6831 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6832 | int res; |
| 6833 | Py_ssize_t len; |
| 6834 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6835 | if (!PyList_Check(tmp)) { |
| 6836 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6837 | goto failed; |
| 6838 | } |
| 6839 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6840 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6841 | if (generators == NULL) goto failed; |
| 6842 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6843 | comprehension_ty val; |
| 6844 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6845 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6846 | if (len != PyList_GET_SIZE(tmp)) { |
| 6847 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 6848 | goto failed; |
| 6849 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6850 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6851 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6852 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6853 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6854 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 6855 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6856 | if (*out == NULL) goto failed; |
| 6857 | return 0; |
| 6858 | } |
| 6859 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 6860 | if (isinstance == -1) { |
| 6861 | return 1; |
| 6862 | } |
| 6863 | if (isinstance) { |
| 6864 | expr_ty elt; |
| 6865 | asdl_seq* generators; |
| 6866 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6867 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6868 | return 1; |
| 6869 | } |
| 6870 | if (tmp == NULL) { |
| 6871 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 6872 | return 1; |
| 6873 | } |
| 6874 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6875 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6876 | res = obj2ast_expr(tmp, &elt, arena); |
| 6877 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6878 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6879 | } |
| 6880 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6881 | return 1; |
| 6882 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6883 | if (tmp == NULL) { |
| 6884 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 6885 | return 1; |
| 6886 | } |
| 6887 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6888 | int res; |
| 6889 | Py_ssize_t len; |
| 6890 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6891 | if (!PyList_Check(tmp)) { |
| 6892 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6893 | goto failed; |
| 6894 | } |
| 6895 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6896 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6897 | if (generators == NULL) goto failed; |
| 6898 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6899 | comprehension_ty val; |
| 6900 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6901 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6902 | if (len != PyList_GET_SIZE(tmp)) { |
| 6903 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 6904 | goto failed; |
| 6905 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6906 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6907 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6908 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6909 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6910 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 6911 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6912 | if (*out == NULL) goto failed; |
| 6913 | return 0; |
| 6914 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6915 | isinstance = PyObject_IsInstance(obj, (PyObject*)Await_type); |
| 6916 | if (isinstance == -1) { |
| 6917 | return 1; |
| 6918 | } |
| 6919 | if (isinstance) { |
| 6920 | expr_ty value; |
| 6921 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6922 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6923 | return 1; |
| 6924 | } |
| 6925 | if (tmp == NULL) { |
| 6926 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 6927 | return 1; |
| 6928 | } |
| 6929 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6930 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6931 | res = obj2ast_expr(tmp, &value, arena); |
| 6932 | if (res != 0) goto failed; |
| 6933 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6934 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6935 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6936 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6937 | if (*out == NULL) goto failed; |
| 6938 | return 0; |
| 6939 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6940 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 6941 | if (isinstance == -1) { |
| 6942 | return 1; |
| 6943 | } |
| 6944 | if (isinstance) { |
| 6945 | expr_ty value; |
| 6946 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6947 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6948 | return 1; |
| 6949 | } |
| 6950 | if (tmp == NULL || tmp == Py_None) { |
| 6951 | Py_CLEAR(tmp); |
| 6952 | value = NULL; |
| 6953 | } |
| 6954 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6955 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6956 | res = obj2ast_expr(tmp, &value, arena); |
| 6957 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6958 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6959 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6960 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6961 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6962 | if (*out == NULL) goto failed; |
| 6963 | return 0; |
| 6964 | } |
| 6965 | isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); |
| 6966 | if (isinstance == -1) { |
| 6967 | return 1; |
| 6968 | } |
| 6969 | if (isinstance) { |
| 6970 | expr_ty value; |
| 6971 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6972 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6973 | return 1; |
| 6974 | } |
| 6975 | if (tmp == NULL) { |
| 6976 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 6977 | return 1; |
| 6978 | } |
| 6979 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6980 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6981 | res = obj2ast_expr(tmp, &value, arena); |
| 6982 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6983 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6984 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6985 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6986 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6987 | if (*out == NULL) goto failed; |
| 6988 | return 0; |
| 6989 | } |
| 6990 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 6991 | if (isinstance == -1) { |
| 6992 | return 1; |
| 6993 | } |
| 6994 | if (isinstance) { |
| 6995 | expr_ty left; |
| 6996 | asdl_int_seq* ops; |
| 6997 | asdl_seq* comparators; |
| 6998 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6999 | if (_PyObject_LookupAttrId(obj, &PyId_left, &tmp) < 0) { |
| 7000 | return 1; |
| 7001 | } |
| 7002 | if (tmp == NULL) { |
| 7003 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 7004 | return 1; |
| 7005 | } |
| 7006 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7007 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7008 | res = obj2ast_expr(tmp, &left, arena); |
| 7009 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7010 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7011 | } |
| 7012 | if (_PyObject_LookupAttrId(obj, &PyId_ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7013 | return 1; |
| 7014 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7015 | if (tmp == NULL) { |
| 7016 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 7017 | return 1; |
| 7018 | } |
| 7019 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7020 | int res; |
| 7021 | Py_ssize_t len; |
| 7022 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7023 | if (!PyList_Check(tmp)) { |
| 7024 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7025 | goto failed; |
| 7026 | } |
| 7027 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7028 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7029 | if (ops == NULL) goto failed; |
| 7030 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7031 | cmpop_ty val; |
| 7032 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7033 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7034 | if (len != PyList_GET_SIZE(tmp)) { |
| 7035 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 7036 | goto failed; |
| 7037 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7038 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7039 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7040 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7041 | } |
| 7042 | if (_PyObject_LookupAttrId(obj, &PyId_comparators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7043 | return 1; |
| 7044 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7045 | if (tmp == NULL) { |
| 7046 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 7047 | return 1; |
| 7048 | } |
| 7049 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7050 | int res; |
| 7051 | Py_ssize_t len; |
| 7052 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7053 | if (!PyList_Check(tmp)) { |
| 7054 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7055 | goto failed; |
| 7056 | } |
| 7057 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7058 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7059 | if (comparators == NULL) goto failed; |
| 7060 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7061 | expr_ty val; |
| 7062 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7063 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7064 | if (len != PyList_GET_SIZE(tmp)) { |
| 7065 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 7066 | goto failed; |
| 7067 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7068 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7069 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7070 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7071 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7072 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 7073 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7074 | if (*out == NULL) goto failed; |
| 7075 | return 0; |
| 7076 | } |
| 7077 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 7078 | if (isinstance == -1) { |
| 7079 | return 1; |
| 7080 | } |
| 7081 | if (isinstance) { |
| 7082 | expr_ty func; |
| 7083 | asdl_seq* args; |
| 7084 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7085 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7086 | if (_PyObject_LookupAttrId(obj, &PyId_func, &tmp) < 0) { |
| 7087 | return 1; |
| 7088 | } |
| 7089 | if (tmp == NULL) { |
| 7090 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 7091 | return 1; |
| 7092 | } |
| 7093 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7094 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7095 | res = obj2ast_expr(tmp, &func, arena); |
| 7096 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7097 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7098 | } |
| 7099 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7100 | return 1; |
| 7101 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7102 | if (tmp == NULL) { |
| 7103 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 7104 | return 1; |
| 7105 | } |
| 7106 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7107 | int res; |
| 7108 | Py_ssize_t len; |
| 7109 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7110 | if (!PyList_Check(tmp)) { |
| 7111 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7112 | goto failed; |
| 7113 | } |
| 7114 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7115 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7116 | if (args == NULL) goto failed; |
| 7117 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7118 | expr_ty val; |
| 7119 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7120 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7121 | if (len != PyList_GET_SIZE(tmp)) { |
| 7122 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 7123 | goto failed; |
| 7124 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7125 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7126 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7127 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7128 | } |
| 7129 | if (_PyObject_LookupAttrId(obj, &PyId_keywords, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7130 | return 1; |
| 7131 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7132 | if (tmp == NULL) { |
| 7133 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 7134 | return 1; |
| 7135 | } |
| 7136 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7137 | int res; |
| 7138 | Py_ssize_t len; |
| 7139 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7140 | if (!PyList_Check(tmp)) { |
| 7141 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7142 | goto failed; |
| 7143 | } |
| 7144 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7145 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7146 | if (keywords == NULL) goto failed; |
| 7147 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7148 | keyword_ty val; |
| 7149 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7150 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7151 | if (len != PyList_GET_SIZE(tmp)) { |
| 7152 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 7153 | goto failed; |
| 7154 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7155 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7156 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7157 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7158 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7159 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 7160 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7161 | if (*out == NULL) goto failed; |
| 7162 | return 0; |
| 7163 | } |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7164 | isinstance = PyObject_IsInstance(obj, (PyObject*)FormattedValue_type); |
| 7165 | if (isinstance == -1) { |
| 7166 | return 1; |
| 7167 | } |
| 7168 | if (isinstance) { |
| 7169 | expr_ty value; |
| 7170 | int conversion; |
| 7171 | expr_ty format_spec; |
Eric V. Smith | 9a4135e | 2019-05-08 16:28:48 -0400 | [diff] [blame] | 7172 | string expr_text; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7173 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7174 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7175 | return 1; |
| 7176 | } |
| 7177 | if (tmp == NULL) { |
| 7178 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 7179 | return 1; |
| 7180 | } |
| 7181 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7182 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7183 | res = obj2ast_expr(tmp, &value, arena); |
| 7184 | if (res != 0) goto failed; |
| 7185 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7186 | } |
| 7187 | if (_PyObject_LookupAttrId(obj, &PyId_conversion, &tmp) < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7188 | return 1; |
| 7189 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7190 | if (tmp == NULL || tmp == Py_None) { |
| 7191 | Py_CLEAR(tmp); |
| 7192 | conversion = 0; |
| 7193 | } |
| 7194 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7195 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7196 | res = obj2ast_int(tmp, &conversion, arena); |
| 7197 | if (res != 0) goto failed; |
| 7198 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7199 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7200 | if (_PyObject_LookupAttrId(obj, &PyId_format_spec, &tmp) < 0) { |
| 7201 | return 1; |
| 7202 | } |
| 7203 | if (tmp == NULL || tmp == Py_None) { |
| 7204 | Py_CLEAR(tmp); |
| 7205 | format_spec = NULL; |
| 7206 | } |
| 7207 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7208 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7209 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 7210 | if (res != 0) goto failed; |
| 7211 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7212 | } |
Eric V. Smith | 9a4135e | 2019-05-08 16:28:48 -0400 | [diff] [blame] | 7213 | if (_PyObject_LookupAttrId(obj, &PyId_expr_text, &tmp) < 0) { |
| 7214 | return 1; |
| 7215 | } |
| 7216 | if (tmp == NULL || tmp == Py_None) { |
| 7217 | Py_CLEAR(tmp); |
| 7218 | expr_text = NULL; |
| 7219 | } |
| 7220 | else { |
| 7221 | int res; |
| 7222 | res = obj2ast_string(tmp, &expr_text, arena); |
| 7223 | if (res != 0) goto failed; |
| 7224 | Py_CLEAR(tmp); |
| 7225 | } |
| 7226 | *out = FormattedValue(value, conversion, format_spec, expr_text, |
| 7227 | lineno, col_offset, end_lineno, end_col_offset, |
| 7228 | arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7229 | if (*out == NULL) goto failed; |
| 7230 | return 0; |
| 7231 | } |
| 7232 | isinstance = PyObject_IsInstance(obj, (PyObject*)JoinedStr_type); |
| 7233 | if (isinstance == -1) { |
| 7234 | return 1; |
| 7235 | } |
| 7236 | if (isinstance) { |
| 7237 | asdl_seq* values; |
| 7238 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7239 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
| 7240 | return 1; |
| 7241 | } |
| 7242 | if (tmp == NULL) { |
| 7243 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 7244 | return 1; |
| 7245 | } |
| 7246 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7247 | int res; |
| 7248 | Py_ssize_t len; |
| 7249 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7250 | if (!PyList_Check(tmp)) { |
| 7251 | PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7252 | goto failed; |
| 7253 | } |
| 7254 | len = PyList_GET_SIZE(tmp); |
| 7255 | values = _Py_asdl_seq_new(len, arena); |
| 7256 | if (values == NULL) goto failed; |
| 7257 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7258 | expr_ty val; |
| 7259 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7260 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 7261 | if (len != PyList_GET_SIZE(tmp)) { |
| 7262 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 7263 | goto failed; |
| 7264 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7265 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7266 | } |
| 7267 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7268 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7269 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 7270 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7271 | if (*out == NULL) goto failed; |
| 7272 | return 0; |
| 7273 | } |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7274 | isinstance = PyObject_IsInstance(obj, (PyObject*)Constant_type); |
| 7275 | if (isinstance == -1) { |
| 7276 | return 1; |
| 7277 | } |
| 7278 | if (isinstance) { |
| 7279 | constant value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 7280 | string kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7281 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7282 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7283 | return 1; |
| 7284 | } |
| 7285 | if (tmp == NULL) { |
| 7286 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 7287 | return 1; |
| 7288 | } |
| 7289 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7290 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7291 | res = obj2ast_constant(tmp, &value, arena); |
| 7292 | if (res != 0) goto failed; |
| 7293 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7294 | } |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 7295 | if (_PyObject_LookupAttrId(obj, &PyId_kind, &tmp) < 0) { |
| 7296 | return 1; |
| 7297 | } |
| 7298 | if (tmp == NULL || tmp == Py_None) { |
| 7299 | Py_CLEAR(tmp); |
| 7300 | kind = NULL; |
| 7301 | } |
| 7302 | else { |
| 7303 | int res; |
| 7304 | res = obj2ast_string(tmp, &kind, arena); |
| 7305 | if (res != 0) goto failed; |
| 7306 | Py_CLEAR(tmp); |
| 7307 | } |
| 7308 | *out = Constant(value, kind, lineno, col_offset, end_lineno, |
| 7309 | end_col_offset, arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7310 | if (*out == NULL) goto failed; |
| 7311 | return 0; |
| 7312 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7313 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 7314 | if (isinstance == -1) { |
| 7315 | return 1; |
| 7316 | } |
| 7317 | if (isinstance) { |
| 7318 | expr_ty value; |
| 7319 | identifier attr; |
| 7320 | expr_context_ty ctx; |
| 7321 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7322 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7323 | return 1; |
| 7324 | } |
| 7325 | if (tmp == NULL) { |
| 7326 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 7327 | return 1; |
| 7328 | } |
| 7329 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7330 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7331 | res = obj2ast_expr(tmp, &value, arena); |
| 7332 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7333 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7334 | } |
| 7335 | if (_PyObject_LookupAttrId(obj, &PyId_attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7336 | return 1; |
| 7337 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7338 | if (tmp == NULL) { |
| 7339 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 7340 | return 1; |
| 7341 | } |
| 7342 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7343 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7344 | res = obj2ast_identifier(tmp, &attr, arena); |
| 7345 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7346 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7347 | } |
| 7348 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7349 | return 1; |
| 7350 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7351 | if (tmp == NULL) { |
| 7352 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 7353 | return 1; |
| 7354 | } |
| 7355 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7356 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7357 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7358 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7359 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7360 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7361 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 7362 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7363 | if (*out == NULL) goto failed; |
| 7364 | return 0; |
| 7365 | } |
| 7366 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 7367 | if (isinstance == -1) { |
| 7368 | return 1; |
| 7369 | } |
| 7370 | if (isinstance) { |
| 7371 | expr_ty value; |
| 7372 | slice_ty slice; |
| 7373 | expr_context_ty ctx; |
| 7374 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7375 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7376 | return 1; |
| 7377 | } |
| 7378 | if (tmp == NULL) { |
| 7379 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 7380 | return 1; |
| 7381 | } |
| 7382 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7383 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7384 | res = obj2ast_expr(tmp, &value, arena); |
| 7385 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7386 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7387 | } |
| 7388 | if (_PyObject_LookupAttrId(obj, &PyId_slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7389 | return 1; |
| 7390 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7391 | if (tmp == NULL) { |
| 7392 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 7393 | return 1; |
| 7394 | } |
| 7395 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7396 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7397 | res = obj2ast_slice(tmp, &slice, arena); |
| 7398 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7399 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7400 | } |
| 7401 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7402 | return 1; |
| 7403 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7404 | if (tmp == NULL) { |
| 7405 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 7406 | return 1; |
| 7407 | } |
| 7408 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7409 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7410 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7411 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7412 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7413 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7414 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 7415 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7416 | if (*out == NULL) goto failed; |
| 7417 | return 0; |
| 7418 | } |
| 7419 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 7420 | if (isinstance == -1) { |
| 7421 | return 1; |
| 7422 | } |
| 7423 | if (isinstance) { |
| 7424 | expr_ty value; |
| 7425 | expr_context_ty ctx; |
| 7426 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7427 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7428 | return 1; |
| 7429 | } |
| 7430 | if (tmp == NULL) { |
| 7431 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 7432 | return 1; |
| 7433 | } |
| 7434 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7435 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7436 | res = obj2ast_expr(tmp, &value, arena); |
| 7437 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7438 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7439 | } |
| 7440 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7441 | return 1; |
| 7442 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7443 | if (tmp == NULL) { |
| 7444 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 7445 | return 1; |
| 7446 | } |
| 7447 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7448 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7449 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7450 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7451 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7452 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7453 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 7454 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7455 | if (*out == NULL) goto failed; |
| 7456 | return 0; |
| 7457 | } |
| 7458 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 7459 | if (isinstance == -1) { |
| 7460 | return 1; |
| 7461 | } |
| 7462 | if (isinstance) { |
| 7463 | identifier id; |
| 7464 | expr_context_ty ctx; |
| 7465 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7466 | if (_PyObject_LookupAttrId(obj, &PyId_id, &tmp) < 0) { |
| 7467 | return 1; |
| 7468 | } |
| 7469 | if (tmp == NULL) { |
| 7470 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 7471 | return 1; |
| 7472 | } |
| 7473 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7474 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7475 | res = obj2ast_identifier(tmp, &id, arena); |
| 7476 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7477 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7478 | } |
| 7479 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7480 | return 1; |
| 7481 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7482 | if (tmp == NULL) { |
| 7483 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 7484 | return 1; |
| 7485 | } |
| 7486 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7487 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7488 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7489 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7490 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7491 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7492 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7493 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7494 | if (*out == NULL) goto failed; |
| 7495 | return 0; |
| 7496 | } |
| 7497 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 7498 | if (isinstance == -1) { |
| 7499 | return 1; |
| 7500 | } |
| 7501 | if (isinstance) { |
| 7502 | asdl_seq* elts; |
| 7503 | expr_context_ty ctx; |
| 7504 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7505 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 7506 | return 1; |
| 7507 | } |
| 7508 | if (tmp == NULL) { |
| 7509 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 7510 | return 1; |
| 7511 | } |
| 7512 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7513 | int res; |
| 7514 | Py_ssize_t len; |
| 7515 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7516 | if (!PyList_Check(tmp)) { |
| 7517 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7518 | goto failed; |
| 7519 | } |
| 7520 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7521 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7522 | if (elts == NULL) goto failed; |
| 7523 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7524 | expr_ty val; |
| 7525 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7526 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7527 | if (len != PyList_GET_SIZE(tmp)) { |
| 7528 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 7529 | goto failed; |
| 7530 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7531 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7532 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7533 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7534 | } |
| 7535 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7536 | return 1; |
| 7537 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7538 | if (tmp == NULL) { |
| 7539 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 7540 | return 1; |
| 7541 | } |
| 7542 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7543 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7544 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7545 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7546 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7547 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7548 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7549 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7550 | if (*out == NULL) goto failed; |
| 7551 | return 0; |
| 7552 | } |
| 7553 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 7554 | if (isinstance == -1) { |
| 7555 | return 1; |
| 7556 | } |
| 7557 | if (isinstance) { |
| 7558 | asdl_seq* elts; |
| 7559 | expr_context_ty ctx; |
| 7560 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7561 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 7562 | return 1; |
| 7563 | } |
| 7564 | if (tmp == NULL) { |
| 7565 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 7566 | return 1; |
| 7567 | } |
| 7568 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7569 | int res; |
| 7570 | Py_ssize_t len; |
| 7571 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7572 | if (!PyList_Check(tmp)) { |
| 7573 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7574 | goto failed; |
| 7575 | } |
| 7576 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7577 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7578 | if (elts == NULL) goto failed; |
| 7579 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7580 | expr_ty val; |
| 7581 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7582 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7583 | if (len != PyList_GET_SIZE(tmp)) { |
| 7584 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 7585 | goto failed; |
| 7586 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7587 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7588 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7589 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7590 | } |
| 7591 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7592 | return 1; |
| 7593 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7594 | if (tmp == NULL) { |
| 7595 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 7596 | return 1; |
| 7597 | } |
| 7598 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7599 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7600 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7601 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7602 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7603 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7604 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7605 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7606 | if (*out == NULL) goto failed; |
| 7607 | return 0; |
| 7608 | } |
| 7609 | |
| 7610 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 7611 | failed: |
| 7612 | Py_XDECREF(tmp); |
| 7613 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7614 | } |
| 7615 | |
| 7616 | int |
| 7617 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 7618 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7619 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7620 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7621 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 7622 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7623 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7624 | } |
| 7625 | if (isinstance) { |
| 7626 | *out = Load; |
| 7627 | return 0; |
| 7628 | } |
| 7629 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 7630 | if (isinstance == -1) { |
| 7631 | return 1; |
| 7632 | } |
| 7633 | if (isinstance) { |
| 7634 | *out = Store; |
| 7635 | return 0; |
| 7636 | } |
| 7637 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 7638 | if (isinstance == -1) { |
| 7639 | return 1; |
| 7640 | } |
| 7641 | if (isinstance) { |
| 7642 | *out = Del; |
| 7643 | return 0; |
| 7644 | } |
| 7645 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 7646 | if (isinstance == -1) { |
| 7647 | return 1; |
| 7648 | } |
| 7649 | if (isinstance) { |
| 7650 | *out = AugLoad; |
| 7651 | return 0; |
| 7652 | } |
| 7653 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 7654 | if (isinstance == -1) { |
| 7655 | return 1; |
| 7656 | } |
| 7657 | if (isinstance) { |
| 7658 | *out = AugStore; |
| 7659 | return 0; |
| 7660 | } |
| 7661 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 7662 | if (isinstance == -1) { |
| 7663 | return 1; |
| 7664 | } |
| 7665 | if (isinstance) { |
| 7666 | *out = Param; |
| 7667 | return 0; |
| 7668 | } |
| 7669 | |
| 7670 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 7671 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7672 | } |
| 7673 | |
| 7674 | int |
| 7675 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 7676 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7677 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7678 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7679 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7680 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7681 | if (obj == Py_None) { |
| 7682 | *out = NULL; |
| 7683 | return 0; |
| 7684 | } |
| 7685 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 7686 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7687 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7688 | } |
| 7689 | if (isinstance) { |
| 7690 | expr_ty lower; |
| 7691 | expr_ty upper; |
| 7692 | expr_ty step; |
| 7693 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7694 | if (_PyObject_LookupAttrId(obj, &PyId_lower, &tmp) < 0) { |
| 7695 | return 1; |
| 7696 | } |
| 7697 | if (tmp == NULL || tmp == Py_None) { |
| 7698 | Py_CLEAR(tmp); |
| 7699 | lower = NULL; |
| 7700 | } |
| 7701 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7702 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7703 | res = obj2ast_expr(tmp, &lower, arena); |
| 7704 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7705 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7706 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7707 | if (_PyObject_LookupAttrId(obj, &PyId_upper, &tmp) < 0) { |
| 7708 | return 1; |
| 7709 | } |
| 7710 | if (tmp == NULL || tmp == Py_None) { |
| 7711 | Py_CLEAR(tmp); |
| 7712 | upper = NULL; |
| 7713 | } |
| 7714 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7715 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7716 | res = obj2ast_expr(tmp, &upper, arena); |
| 7717 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7718 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7719 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7720 | if (_PyObject_LookupAttrId(obj, &PyId_step, &tmp) < 0) { |
| 7721 | return 1; |
| 7722 | } |
| 7723 | if (tmp == NULL || tmp == Py_None) { |
| 7724 | Py_CLEAR(tmp); |
| 7725 | step = NULL; |
| 7726 | } |
| 7727 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7728 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7729 | res = obj2ast_expr(tmp, &step, arena); |
| 7730 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7731 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7732 | } |
| 7733 | *out = Slice(lower, upper, step, arena); |
| 7734 | if (*out == NULL) goto failed; |
| 7735 | return 0; |
| 7736 | } |
| 7737 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 7738 | if (isinstance == -1) { |
| 7739 | return 1; |
| 7740 | } |
| 7741 | if (isinstance) { |
| 7742 | asdl_seq* dims; |
| 7743 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7744 | if (_PyObject_LookupAttrId(obj, &PyId_dims, &tmp) < 0) { |
| 7745 | return 1; |
| 7746 | } |
| 7747 | if (tmp == NULL) { |
| 7748 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 7749 | return 1; |
| 7750 | } |
| 7751 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7752 | int res; |
| 7753 | Py_ssize_t len; |
| 7754 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7755 | if (!PyList_Check(tmp)) { |
| 7756 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7757 | goto failed; |
| 7758 | } |
| 7759 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7760 | dims = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7761 | if (dims == NULL) goto failed; |
| 7762 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7763 | slice_ty val; |
| 7764 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7765 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7766 | if (len != PyList_GET_SIZE(tmp)) { |
| 7767 | PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration"); |
| 7768 | goto failed; |
| 7769 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7770 | asdl_seq_SET(dims, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7771 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7772 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7773 | } |
| 7774 | *out = ExtSlice(dims, arena); |
| 7775 | if (*out == NULL) goto failed; |
| 7776 | return 0; |
| 7777 | } |
| 7778 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 7779 | if (isinstance == -1) { |
| 7780 | return 1; |
| 7781 | } |
| 7782 | if (isinstance) { |
| 7783 | expr_ty value; |
| 7784 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7785 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7786 | return 1; |
| 7787 | } |
| 7788 | if (tmp == NULL) { |
| 7789 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 7790 | return 1; |
| 7791 | } |
| 7792 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7793 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7794 | res = obj2ast_expr(tmp, &value, arena); |
| 7795 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7796 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7797 | } |
| 7798 | *out = Index(value, arena); |
| 7799 | if (*out == NULL) goto failed; |
| 7800 | return 0; |
| 7801 | } |
| 7802 | |
| 7803 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 7804 | failed: |
| 7805 | Py_XDECREF(tmp); |
| 7806 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7807 | } |
| 7808 | |
| 7809 | int |
| 7810 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 7811 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7812 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7813 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7814 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 7815 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7816 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7817 | } |
| 7818 | if (isinstance) { |
| 7819 | *out = And; |
| 7820 | return 0; |
| 7821 | } |
| 7822 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 7823 | if (isinstance == -1) { |
| 7824 | return 1; |
| 7825 | } |
| 7826 | if (isinstance) { |
| 7827 | *out = Or; |
| 7828 | return 0; |
| 7829 | } |
| 7830 | |
| 7831 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 7832 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7833 | } |
| 7834 | |
| 7835 | int |
| 7836 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 7837 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7838 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7839 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7840 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 7841 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7842 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7843 | } |
| 7844 | if (isinstance) { |
| 7845 | *out = Add; |
| 7846 | return 0; |
| 7847 | } |
| 7848 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 7849 | if (isinstance == -1) { |
| 7850 | return 1; |
| 7851 | } |
| 7852 | if (isinstance) { |
| 7853 | *out = Sub; |
| 7854 | return 0; |
| 7855 | } |
| 7856 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 7857 | if (isinstance == -1) { |
| 7858 | return 1; |
| 7859 | } |
| 7860 | if (isinstance) { |
| 7861 | *out = Mult; |
| 7862 | return 0; |
| 7863 | } |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 7864 | isinstance = PyObject_IsInstance(obj, (PyObject *)MatMult_type); |
| 7865 | if (isinstance == -1) { |
| 7866 | return 1; |
| 7867 | } |
| 7868 | if (isinstance) { |
| 7869 | *out = MatMult; |
| 7870 | return 0; |
| 7871 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7872 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 7873 | if (isinstance == -1) { |
| 7874 | return 1; |
| 7875 | } |
| 7876 | if (isinstance) { |
| 7877 | *out = Div; |
| 7878 | return 0; |
| 7879 | } |
| 7880 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 7881 | if (isinstance == -1) { |
| 7882 | return 1; |
| 7883 | } |
| 7884 | if (isinstance) { |
| 7885 | *out = Mod; |
| 7886 | return 0; |
| 7887 | } |
| 7888 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 7889 | if (isinstance == -1) { |
| 7890 | return 1; |
| 7891 | } |
| 7892 | if (isinstance) { |
| 7893 | *out = Pow; |
| 7894 | return 0; |
| 7895 | } |
| 7896 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 7897 | if (isinstance == -1) { |
| 7898 | return 1; |
| 7899 | } |
| 7900 | if (isinstance) { |
| 7901 | *out = LShift; |
| 7902 | return 0; |
| 7903 | } |
| 7904 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 7905 | if (isinstance == -1) { |
| 7906 | return 1; |
| 7907 | } |
| 7908 | if (isinstance) { |
| 7909 | *out = RShift; |
| 7910 | return 0; |
| 7911 | } |
| 7912 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 7913 | if (isinstance == -1) { |
| 7914 | return 1; |
| 7915 | } |
| 7916 | if (isinstance) { |
| 7917 | *out = BitOr; |
| 7918 | return 0; |
| 7919 | } |
| 7920 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 7921 | if (isinstance == -1) { |
| 7922 | return 1; |
| 7923 | } |
| 7924 | if (isinstance) { |
| 7925 | *out = BitXor; |
| 7926 | return 0; |
| 7927 | } |
| 7928 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 7929 | if (isinstance == -1) { |
| 7930 | return 1; |
| 7931 | } |
| 7932 | if (isinstance) { |
| 7933 | *out = BitAnd; |
| 7934 | return 0; |
| 7935 | } |
| 7936 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 7937 | if (isinstance == -1) { |
| 7938 | return 1; |
| 7939 | } |
| 7940 | if (isinstance) { |
| 7941 | *out = FloorDiv; |
| 7942 | return 0; |
| 7943 | } |
| 7944 | |
| 7945 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 7946 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7947 | } |
| 7948 | |
| 7949 | int |
| 7950 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 7951 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7952 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7953 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7954 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 7955 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7956 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7957 | } |
| 7958 | if (isinstance) { |
| 7959 | *out = Invert; |
| 7960 | return 0; |
| 7961 | } |
| 7962 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 7963 | if (isinstance == -1) { |
| 7964 | return 1; |
| 7965 | } |
| 7966 | if (isinstance) { |
| 7967 | *out = Not; |
| 7968 | return 0; |
| 7969 | } |
| 7970 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 7971 | if (isinstance == -1) { |
| 7972 | return 1; |
| 7973 | } |
| 7974 | if (isinstance) { |
| 7975 | *out = UAdd; |
| 7976 | return 0; |
| 7977 | } |
| 7978 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 7979 | if (isinstance == -1) { |
| 7980 | return 1; |
| 7981 | } |
| 7982 | if (isinstance) { |
| 7983 | *out = USub; |
| 7984 | return 0; |
| 7985 | } |
| 7986 | |
| 7987 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 7988 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7989 | } |
| 7990 | |
| 7991 | int |
| 7992 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 7993 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7994 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7995 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7996 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 7997 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7998 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7999 | } |
| 8000 | if (isinstance) { |
| 8001 | *out = Eq; |
| 8002 | return 0; |
| 8003 | } |
| 8004 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 8005 | if (isinstance == -1) { |
| 8006 | return 1; |
| 8007 | } |
| 8008 | if (isinstance) { |
| 8009 | *out = NotEq; |
| 8010 | return 0; |
| 8011 | } |
| 8012 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 8013 | if (isinstance == -1) { |
| 8014 | return 1; |
| 8015 | } |
| 8016 | if (isinstance) { |
| 8017 | *out = Lt; |
| 8018 | return 0; |
| 8019 | } |
| 8020 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 8021 | if (isinstance == -1) { |
| 8022 | return 1; |
| 8023 | } |
| 8024 | if (isinstance) { |
| 8025 | *out = LtE; |
| 8026 | return 0; |
| 8027 | } |
| 8028 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 8029 | if (isinstance == -1) { |
| 8030 | return 1; |
| 8031 | } |
| 8032 | if (isinstance) { |
| 8033 | *out = Gt; |
| 8034 | return 0; |
| 8035 | } |
| 8036 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 8037 | if (isinstance == -1) { |
| 8038 | return 1; |
| 8039 | } |
| 8040 | if (isinstance) { |
| 8041 | *out = GtE; |
| 8042 | return 0; |
| 8043 | } |
| 8044 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 8045 | if (isinstance == -1) { |
| 8046 | return 1; |
| 8047 | } |
| 8048 | if (isinstance) { |
| 8049 | *out = Is; |
| 8050 | return 0; |
| 8051 | } |
| 8052 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 8053 | if (isinstance == -1) { |
| 8054 | return 1; |
| 8055 | } |
| 8056 | if (isinstance) { |
| 8057 | *out = IsNot; |
| 8058 | return 0; |
| 8059 | } |
| 8060 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 8061 | if (isinstance == -1) { |
| 8062 | return 1; |
| 8063 | } |
| 8064 | if (isinstance) { |
| 8065 | *out = In; |
| 8066 | return 0; |
| 8067 | } |
| 8068 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 8069 | if (isinstance == -1) { |
| 8070 | return 1; |
| 8071 | } |
| 8072 | if (isinstance) { |
| 8073 | *out = NotIn; |
| 8074 | return 0; |
| 8075 | } |
| 8076 | |
| 8077 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 8078 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8079 | } |
| 8080 | |
| 8081 | int |
| 8082 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 8083 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8084 | PyObject* tmp = NULL; |
| 8085 | expr_ty target; |
| 8086 | expr_ty iter; |
| 8087 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8088 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8089 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8090 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 8091 | return 1; |
| 8092 | } |
| 8093 | if (tmp == NULL) { |
| 8094 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 8095 | return 1; |
| 8096 | } |
| 8097 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8098 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8099 | res = obj2ast_expr(tmp, &target, arena); |
| 8100 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8101 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8102 | } |
| 8103 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8104 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8105 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8106 | if (tmp == NULL) { |
| 8107 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 8108 | return 1; |
| 8109 | } |
| 8110 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8111 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8112 | res = obj2ast_expr(tmp, &iter, arena); |
| 8113 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8114 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8115 | } |
| 8116 | if (_PyObject_LookupAttrId(obj, &PyId_ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8117 | return 1; |
| 8118 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8119 | if (tmp == NULL) { |
| 8120 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 8121 | return 1; |
| 8122 | } |
| 8123 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8124 | int res; |
| 8125 | Py_ssize_t len; |
| 8126 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8127 | if (!PyList_Check(tmp)) { |
| 8128 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8129 | goto failed; |
| 8130 | } |
| 8131 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8132 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8133 | if (ifs == NULL) goto failed; |
| 8134 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8135 | expr_ty val; |
| 8136 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8137 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8138 | if (len != PyList_GET_SIZE(tmp)) { |
| 8139 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 8140 | goto failed; |
| 8141 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8142 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8143 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8144 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8145 | } |
| 8146 | if (_PyObject_LookupAttrId(obj, &PyId_is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8147 | return 1; |
| 8148 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8149 | if (tmp == NULL) { |
| 8150 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 8151 | return 1; |
| 8152 | } |
| 8153 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8154 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8155 | res = obj2ast_int(tmp, &is_async, arena); |
| 8156 | if (res != 0) goto failed; |
| 8157 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8158 | } |
| 8159 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8160 | return 0; |
| 8161 | failed: |
| 8162 | Py_XDECREF(tmp); |
| 8163 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8164 | } |
| 8165 | |
| 8166 | int |
| 8167 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 8168 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8169 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 8170 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8171 | PyObject *tmp = NULL; |
| 8172 | int lineno; |
| 8173 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8174 | int end_lineno; |
| 8175 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8176 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8177 | if (obj == Py_None) { |
| 8178 | *out = NULL; |
| 8179 | return 0; |
| 8180 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8181 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 8182 | return 1; |
| 8183 | } |
| 8184 | if (tmp == NULL) { |
| 8185 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 8186 | return 1; |
| 8187 | } |
| 8188 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8189 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8190 | res = obj2ast_int(tmp, &lineno, arena); |
| 8191 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8192 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8193 | } |
| 8194 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8195 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8196 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8197 | if (tmp == NULL) { |
| 8198 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 8199 | return 1; |
| 8200 | } |
| 8201 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8202 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8203 | res = obj2ast_int(tmp, &col_offset, arena); |
| 8204 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8205 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8206 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8207 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 8208 | return 1; |
| 8209 | } |
| 8210 | if (tmp == NULL || tmp == Py_None) { |
| 8211 | Py_CLEAR(tmp); |
| 8212 | end_lineno = 0; |
| 8213 | } |
| 8214 | else { |
| 8215 | int res; |
| 8216 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 8217 | if (res != 0) goto failed; |
| 8218 | Py_CLEAR(tmp); |
| 8219 | } |
| 8220 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 8221 | return 1; |
| 8222 | } |
| 8223 | if (tmp == NULL || tmp == Py_None) { |
| 8224 | Py_CLEAR(tmp); |
| 8225 | end_col_offset = 0; |
| 8226 | } |
| 8227 | else { |
| 8228 | int res; |
| 8229 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 8230 | if (res != 0) goto failed; |
| 8231 | Py_CLEAR(tmp); |
| 8232 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8233 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 8234 | if (isinstance == -1) { |
| 8235 | return 1; |
| 8236 | } |
| 8237 | if (isinstance) { |
| 8238 | expr_ty type; |
| 8239 | identifier name; |
| 8240 | asdl_seq* body; |
| 8241 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8242 | if (_PyObject_LookupAttrId(obj, &PyId_type, &tmp) < 0) { |
| 8243 | return 1; |
| 8244 | } |
| 8245 | if (tmp == NULL || tmp == Py_None) { |
| 8246 | Py_CLEAR(tmp); |
| 8247 | type = NULL; |
| 8248 | } |
| 8249 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8250 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8251 | res = obj2ast_expr(tmp, &type, arena); |
| 8252 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8253 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8254 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8255 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 8256 | return 1; |
| 8257 | } |
| 8258 | if (tmp == NULL || tmp == Py_None) { |
| 8259 | Py_CLEAR(tmp); |
| 8260 | name = NULL; |
| 8261 | } |
| 8262 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8263 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8264 | res = obj2ast_identifier(tmp, &name, arena); |
| 8265 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8266 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8267 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8268 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 8269 | return 1; |
| 8270 | } |
| 8271 | if (tmp == NULL) { |
| 8272 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 8273 | return 1; |
| 8274 | } |
| 8275 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8276 | int res; |
| 8277 | Py_ssize_t len; |
| 8278 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8279 | if (!PyList_Check(tmp)) { |
| 8280 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8281 | goto failed; |
| 8282 | } |
| 8283 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8284 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8285 | if (body == NULL) goto failed; |
| 8286 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8287 | stmt_ty val; |
| 8288 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8289 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8290 | if (len != PyList_GET_SIZE(tmp)) { |
| 8291 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 8292 | goto failed; |
| 8293 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8294 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8295 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8296 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8297 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8298 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 8299 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8300 | if (*out == NULL) goto failed; |
| 8301 | return 0; |
| 8302 | } |
| 8303 | |
| 8304 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 8305 | failed: |
| 8306 | Py_XDECREF(tmp); |
| 8307 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8308 | } |
| 8309 | |
| 8310 | int |
| 8311 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 8312 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8313 | PyObject* tmp = NULL; |
| 8314 | asdl_seq* args; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 8315 | asdl_seq* posonlyargs; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8316 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8317 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8318 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8319 | arg_ty kwarg; |
| 8320 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8321 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8322 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
| 8323 | return 1; |
| 8324 | } |
| 8325 | if (tmp == NULL) { |
| 8326 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 8327 | return 1; |
| 8328 | } |
| 8329 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8330 | int res; |
| 8331 | Py_ssize_t len; |
| 8332 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8333 | if (!PyList_Check(tmp)) { |
| 8334 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8335 | goto failed; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8336 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8337 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8338 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8339 | if (args == NULL) goto failed; |
| 8340 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8341 | arg_ty val; |
| 8342 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8343 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8344 | if (len != PyList_GET_SIZE(tmp)) { |
| 8345 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 8346 | goto failed; |
| 8347 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8348 | asdl_seq_SET(args, i, val); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8349 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8350 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8351 | } |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 8352 | if (_PyObject_LookupAttrId(obj, &PyId_posonlyargs, &tmp) < 0) { |
| 8353 | return 1; |
| 8354 | } |
| 8355 | if (tmp == NULL) { |
| 8356 | PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments"); |
| 8357 | return 1; |
| 8358 | } |
| 8359 | else { |
| 8360 | int res; |
| 8361 | Py_ssize_t len; |
| 8362 | Py_ssize_t i; |
| 8363 | if (!PyList_Check(tmp)) { |
| 8364 | PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8365 | goto failed; |
| 8366 | } |
| 8367 | len = PyList_GET_SIZE(tmp); |
| 8368 | posonlyargs = _Py_asdl_seq_new(len, arena); |
| 8369 | if (posonlyargs == NULL) goto failed; |
| 8370 | for (i = 0; i < len; i++) { |
| 8371 | arg_ty val; |
| 8372 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena); |
| 8373 | if (res != 0) goto failed; |
| 8374 | if (len != PyList_GET_SIZE(tmp)) { |
| 8375 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration"); |
| 8376 | goto failed; |
| 8377 | } |
| 8378 | asdl_seq_SET(posonlyargs, i, val); |
| 8379 | } |
| 8380 | Py_CLEAR(tmp); |
| 8381 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8382 | if (_PyObject_LookupAttrId(obj, &PyId_vararg, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8383 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8384 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8385 | if (tmp == NULL || tmp == Py_None) { |
| 8386 | Py_CLEAR(tmp); |
| 8387 | vararg = NULL; |
| 8388 | } |
| 8389 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8390 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8391 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8392 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8393 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8394 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8395 | if (_PyObject_LookupAttrId(obj, &PyId_kwonlyargs, &tmp) < 0) { |
| 8396 | return 1; |
| 8397 | } |
| 8398 | if (tmp == NULL) { |
| 8399 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 8400 | return 1; |
| 8401 | } |
| 8402 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8403 | int res; |
| 8404 | Py_ssize_t len; |
| 8405 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8406 | if (!PyList_Check(tmp)) { |
| 8407 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8408 | goto failed; |
| 8409 | } |
| 8410 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8411 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8412 | if (kwonlyargs == NULL) goto failed; |
| 8413 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8414 | arg_ty val; |
| 8415 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8416 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8417 | if (len != PyList_GET_SIZE(tmp)) { |
| 8418 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 8419 | goto failed; |
| 8420 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8421 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8422 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8423 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8424 | } |
| 8425 | if (_PyObject_LookupAttrId(obj, &PyId_kw_defaults, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8426 | return 1; |
| 8427 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8428 | if (tmp == NULL) { |
| 8429 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 8430 | return 1; |
| 8431 | } |
| 8432 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8433 | int res; |
| 8434 | Py_ssize_t len; |
| 8435 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8436 | if (!PyList_Check(tmp)) { |
| 8437 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8438 | goto failed; |
| 8439 | } |
| 8440 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8441 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8442 | if (kw_defaults == NULL) goto failed; |
| 8443 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8444 | expr_ty val; |
| 8445 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8446 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8447 | if (len != PyList_GET_SIZE(tmp)) { |
| 8448 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 8449 | goto failed; |
| 8450 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8451 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8452 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8453 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8454 | } |
| 8455 | if (_PyObject_LookupAttrId(obj, &PyId_kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8456 | return 1; |
| 8457 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8458 | if (tmp == NULL || tmp == Py_None) { |
| 8459 | Py_CLEAR(tmp); |
| 8460 | kwarg = NULL; |
| 8461 | } |
| 8462 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8463 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8464 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 8465 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 8466 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8467 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8468 | if (_PyObject_LookupAttrId(obj, &PyId_defaults, &tmp) < 0) { |
| 8469 | return 1; |
| 8470 | } |
| 8471 | if (tmp == NULL) { |
| 8472 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 8473 | return 1; |
| 8474 | } |
| 8475 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8476 | int res; |
| 8477 | Py_ssize_t len; |
| 8478 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8479 | if (!PyList_Check(tmp)) { |
| 8480 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8481 | goto failed; |
| 8482 | } |
| 8483 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8484 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8485 | if (defaults == NULL) goto failed; |
| 8486 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8487 | expr_ty val; |
| 8488 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8489 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8490 | if (len != PyList_GET_SIZE(tmp)) { |
| 8491 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 8492 | goto failed; |
| 8493 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8494 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8495 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 8496 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8497 | } |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 8498 | *out = arguments(args, posonlyargs, vararg, kwonlyargs, kw_defaults, kwarg, |
| 8499 | defaults, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8500 | return 0; |
| 8501 | failed: |
| 8502 | Py_XDECREF(tmp); |
| 8503 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8504 | } |
| 8505 | |
| 8506 | int |
| 8507 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 8508 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8509 | PyObject* tmp = NULL; |
| 8510 | identifier arg; |
| 8511 | expr_ty annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8512 | string type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8513 | int lineno; |
| 8514 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8515 | int end_lineno; |
| 8516 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8517 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8518 | if (_PyObject_LookupAttrId(obj, &PyId_arg, &tmp) < 0) { |
| 8519 | return 1; |
| 8520 | } |
| 8521 | if (tmp == NULL) { |
| 8522 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 8523 | return 1; |
| 8524 | } |
| 8525 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8526 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8527 | res = obj2ast_identifier(tmp, &arg, arena); |
| 8528 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8529 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8530 | } |
| 8531 | if (_PyObject_LookupAttrId(obj, &PyId_annotation, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8532 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8533 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8534 | if (tmp == NULL || tmp == Py_None) { |
| 8535 | Py_CLEAR(tmp); |
| 8536 | annotation = NULL; |
| 8537 | } |
| 8538 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8539 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8540 | res = obj2ast_expr(tmp, &annotation, arena); |
| 8541 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8542 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8543 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8544 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 8545 | return 1; |
| 8546 | } |
| 8547 | if (tmp == NULL || tmp == Py_None) { |
| 8548 | Py_CLEAR(tmp); |
| 8549 | type_comment = NULL; |
| 8550 | } |
| 8551 | else { |
| 8552 | int res; |
| 8553 | res = obj2ast_string(tmp, &type_comment, arena); |
| 8554 | if (res != 0) goto failed; |
| 8555 | Py_CLEAR(tmp); |
| 8556 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8557 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 8558 | return 1; |
| 8559 | } |
| 8560 | if (tmp == NULL) { |
| 8561 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 8562 | return 1; |
| 8563 | } |
| 8564 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8565 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8566 | res = obj2ast_int(tmp, &lineno, arena); |
| 8567 | if (res != 0) goto failed; |
| 8568 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8569 | } |
| 8570 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8571 | return 1; |
| 8572 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8573 | if (tmp == NULL) { |
| 8574 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 8575 | return 1; |
| 8576 | } |
| 8577 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8578 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8579 | res = obj2ast_int(tmp, &col_offset, arena); |
| 8580 | if (res != 0) goto failed; |
| 8581 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8582 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8583 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 8584 | return 1; |
| 8585 | } |
| 8586 | if (tmp == NULL || tmp == Py_None) { |
| 8587 | Py_CLEAR(tmp); |
| 8588 | end_lineno = 0; |
| 8589 | } |
| 8590 | else { |
| 8591 | int res; |
| 8592 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 8593 | if (res != 0) goto failed; |
| 8594 | Py_CLEAR(tmp); |
| 8595 | } |
| 8596 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 8597 | return 1; |
| 8598 | } |
| 8599 | if (tmp == NULL || tmp == Py_None) { |
| 8600 | Py_CLEAR(tmp); |
| 8601 | end_col_offset = 0; |
| 8602 | } |
| 8603 | else { |
| 8604 | int res; |
| 8605 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 8606 | if (res != 0) goto failed; |
| 8607 | Py_CLEAR(tmp); |
| 8608 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8609 | *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno, |
| 8610 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8611 | return 0; |
| 8612 | failed: |
| 8613 | Py_XDECREF(tmp); |
| 8614 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8615 | } |
| 8616 | |
| 8617 | int |
| 8618 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 8619 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8620 | PyObject* tmp = NULL; |
| 8621 | identifier arg; |
| 8622 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8623 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8624 | if (_PyObject_LookupAttrId(obj, &PyId_arg, &tmp) < 0) { |
| 8625 | return 1; |
| 8626 | } |
| 8627 | if (tmp == NULL || tmp == Py_None) { |
| 8628 | Py_CLEAR(tmp); |
| 8629 | arg = NULL; |
| 8630 | } |
| 8631 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8632 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8633 | res = obj2ast_identifier(tmp, &arg, arena); |
| 8634 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8635 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8636 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8637 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 8638 | return 1; |
| 8639 | } |
| 8640 | if (tmp == NULL) { |
| 8641 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 8642 | return 1; |
| 8643 | } |
| 8644 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8645 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8646 | res = obj2ast_expr(tmp, &value, arena); |
| 8647 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8648 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8649 | } |
| 8650 | *out = keyword(arg, value, arena); |
| 8651 | return 0; |
| 8652 | failed: |
| 8653 | Py_XDECREF(tmp); |
| 8654 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8655 | } |
| 8656 | |
| 8657 | int |
| 8658 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 8659 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8660 | PyObject* tmp = NULL; |
| 8661 | identifier name; |
| 8662 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8663 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8664 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 8665 | return 1; |
| 8666 | } |
| 8667 | if (tmp == NULL) { |
| 8668 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 8669 | return 1; |
| 8670 | } |
| 8671 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8672 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8673 | res = obj2ast_identifier(tmp, &name, arena); |
| 8674 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8675 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8676 | } |
| 8677 | if (_PyObject_LookupAttrId(obj, &PyId_asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8678 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8679 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8680 | if (tmp == NULL || tmp == Py_None) { |
| 8681 | Py_CLEAR(tmp); |
| 8682 | asname = NULL; |
| 8683 | } |
| 8684 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8685 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8686 | res = obj2ast_identifier(tmp, &asname, arena); |
| 8687 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8688 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8689 | } |
| 8690 | *out = alias(name, asname, arena); |
| 8691 | return 0; |
| 8692 | failed: |
| 8693 | Py_XDECREF(tmp); |
| 8694 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8695 | } |
| 8696 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8697 | int |
| 8698 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 8699 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8700 | PyObject* tmp = NULL; |
| 8701 | expr_ty context_expr; |
| 8702 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8703 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8704 | if (_PyObject_LookupAttrId(obj, &PyId_context_expr, &tmp) < 0) { |
| 8705 | return 1; |
| 8706 | } |
| 8707 | if (tmp == NULL) { |
| 8708 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 8709 | return 1; |
| 8710 | } |
| 8711 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8712 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8713 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 8714 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8715 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8716 | } |
| 8717 | if (_PyObject_LookupAttrId(obj, &PyId_optional_vars, &tmp) < 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8718 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8719 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8720 | if (tmp == NULL || tmp == Py_None) { |
| 8721 | Py_CLEAR(tmp); |
| 8722 | optional_vars = NULL; |
| 8723 | } |
| 8724 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8725 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8726 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 8727 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8728 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8729 | } |
| 8730 | *out = withitem(context_expr, optional_vars, arena); |
| 8731 | return 0; |
| 8732 | failed: |
| 8733 | Py_XDECREF(tmp); |
| 8734 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8735 | } |
| 8736 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8737 | int |
| 8738 | obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) |
| 8739 | { |
| 8740 | int isinstance; |
| 8741 | |
| 8742 | PyObject *tmp = NULL; |
| 8743 | |
| 8744 | if (obj == Py_None) { |
| 8745 | *out = NULL; |
| 8746 | return 0; |
| 8747 | } |
| 8748 | isinstance = PyObject_IsInstance(obj, (PyObject*)TypeIgnore_type); |
| 8749 | if (isinstance == -1) { |
| 8750 | return 1; |
| 8751 | } |
| 8752 | if (isinstance) { |
| 8753 | int lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 8754 | string tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8755 | |
| 8756 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 8757 | return 1; |
| 8758 | } |
| 8759 | if (tmp == NULL) { |
| 8760 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore"); |
| 8761 | return 1; |
| 8762 | } |
| 8763 | else { |
| 8764 | int res; |
| 8765 | res = obj2ast_int(tmp, &lineno, arena); |
| 8766 | if (res != 0) goto failed; |
| 8767 | Py_CLEAR(tmp); |
| 8768 | } |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 8769 | if (_PyObject_LookupAttrId(obj, &PyId_tag, &tmp) < 0) { |
| 8770 | return 1; |
| 8771 | } |
| 8772 | if (tmp == NULL) { |
| 8773 | PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore"); |
| 8774 | return 1; |
| 8775 | } |
| 8776 | else { |
| 8777 | int res; |
| 8778 | res = obj2ast_string(tmp, &tag, arena); |
| 8779 | if (res != 0) goto failed; |
| 8780 | Py_CLEAR(tmp); |
| 8781 | } |
| 8782 | *out = TypeIgnore(lineno, tag, arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8783 | if (*out == NULL) goto failed; |
| 8784 | return 0; |
| 8785 | } |
| 8786 | |
| 8787 | PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj); |
| 8788 | failed: |
| 8789 | Py_XDECREF(tmp); |
| 8790 | return 1; |
| 8791 | } |
| 8792 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8793 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 8794 | static struct PyModuleDef _astmodule = { |
| 8795 | PyModuleDef_HEAD_INIT, "_ast" |
| 8796 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8797 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 8798 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8799 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8800 | PyObject *m, *d; |
| 8801 | if (!init_types()) return NULL; |
| 8802 | m = PyModule_Create(&_astmodule); |
| 8803 | if (!m) return NULL; |
| 8804 | d = PyModule_GetDict(m); |
| 8805 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL; |
Matthias Bussonnier | 565b4f1 | 2019-05-21 13:12:03 -0700 | [diff] [blame] | 8806 | if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) |
| 8807 | return NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8808 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8809 | return NULL; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8810 | if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) |
| 8811 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8812 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; |
| 8813 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return |
| 8814 | NULL; |
| 8815 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) < |
| 8816 | 0) return NULL; |
| 8817 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0) |
| 8818 | return NULL; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8819 | if (PyDict_SetItemString(d, "FunctionType", (PyObject*)FunctionType_type) < |
| 8820 | 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8821 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 8822 | NULL; |
| 8823 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL; |
| 8824 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) < |
| 8825 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8826 | if (PyDict_SetItemString(d, "AsyncFunctionDef", |
| 8827 | (PyObject*)AsyncFunctionDef_type) < 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8828 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 8829 | return NULL; |
| 8830 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return |
| 8831 | NULL; |
| 8832 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return |
| 8833 | NULL; |
| 8834 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return |
| 8835 | NULL; |
| 8836 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0) |
| 8837 | return NULL; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 8838 | if (PyDict_SetItemString(d, "AnnAssign", (PyObject*)AnnAssign_type) < 0) |
| 8839 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8840 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8841 | if (PyDict_SetItemString(d, "AsyncFor", (PyObject*)AsyncFor_type) < 0) |
| 8842 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8843 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 8844 | NULL; |
| 8845 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 8846 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8847 | if (PyDict_SetItemString(d, "AsyncWith", (PyObject*)AsyncWith_type) < 0) |
| 8848 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8849 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 8850 | NULL; |
| 8851 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL; |
| 8852 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return |
| 8853 | NULL; |
| 8854 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return |
| 8855 | NULL; |
| 8856 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0) |
| 8857 | return NULL; |
| 8858 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return |
| 8859 | NULL; |
| 8860 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
| 8861 | return NULL; |
| 8862 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL; |
| 8863 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL; |
| 8864 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 8865 | NULL; |
| 8866 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 8867 | return NULL; |
| 8868 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL; |
| 8869 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return |
| 8870 | NULL; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 8871 | if (PyDict_SetItemString(d, "NamedExpr", (PyObject*)NamedExpr_type) < 0) |
| 8872 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8873 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 8874 | NULL; |
| 8875 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return |
| 8876 | NULL; |
| 8877 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return |
| 8878 | NULL; |
| 8879 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 8880 | NULL; |
| 8881 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL; |
| 8882 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL; |
| 8883 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 8884 | return NULL; |
| 8885 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return |
| 8886 | NULL; |
| 8887 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
| 8888 | return NULL; |
| 8889 | if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) < |
| 8890 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8891 | if (PyDict_SetItemString(d, "Await", (PyObject*)Await_type) < 0) return |
| 8892 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8893 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 8894 | NULL; |
| 8895 | if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0) |
| 8896 | return NULL; |
| 8897 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return |
| 8898 | NULL; |
| 8899 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8900 | if (PyDict_SetItemString(d, "FormattedValue", |
| 8901 | (PyObject*)FormattedValue_type) < 0) return NULL; |
| 8902 | if (PyDict_SetItemString(d, "JoinedStr", (PyObject*)JoinedStr_type) < 0) |
| 8903 | return NULL; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8904 | if (PyDict_SetItemString(d, "Constant", (PyObject*)Constant_type) < 0) |
| 8905 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8906 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0) |
| 8907 | return NULL; |
| 8908 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0) |
| 8909 | return NULL; |
| 8910 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return |
| 8911 | NULL; |
| 8912 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL; |
| 8913 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL; |
| 8914 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 8915 | NULL; |
| 8916 | if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) < |
| 8917 | 0) return NULL; |
| 8918 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL; |
| 8919 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 8920 | NULL; |
| 8921 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL; |
| 8922 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return |
| 8923 | NULL; |
| 8924 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 8925 | return NULL; |
| 8926 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 8927 | NULL; |
| 8928 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 8929 | NULL; |
| 8930 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 8931 | NULL; |
| 8932 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 8933 | return NULL; |
| 8934 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 8935 | NULL; |
| 8936 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return |
| 8937 | NULL; |
| 8938 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL; |
| 8939 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
| 8940 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 8941 | return NULL; |
| 8942 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL; |
| 8943 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL; |
| 8944 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8945 | if (PyDict_SetItemString(d, "MatMult", (PyObject*)MatMult_type) < 0) return |
| 8946 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8947 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL; |
| 8948 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL; |
| 8949 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL; |
| 8950 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return |
| 8951 | NULL; |
| 8952 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return |
| 8953 | NULL; |
| 8954 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 8955 | NULL; |
| 8956 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return |
| 8957 | NULL; |
| 8958 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return |
| 8959 | NULL; |
| 8960 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 8961 | return NULL; |
| 8962 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return |
| 8963 | NULL; |
| 8964 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return |
| 8965 | NULL; |
| 8966 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL; |
| 8967 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL; |
| 8968 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL; |
| 8969 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 8970 | NULL; |
| 8971 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 8972 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 8973 | NULL; |
| 8974 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 8975 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL; |
| 8976 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 8977 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL; |
| 8978 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 8979 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 8980 | NULL; |
| 8981 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 8982 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 8983 | NULL; |
| 8984 | if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type) |
| 8985 | < 0) return NULL; |
| 8986 | if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type) |
| 8987 | < 0) return NULL; |
| 8988 | if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type) |
| 8989 | < 0) return NULL; |
| 8990 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0) |
| 8991 | return NULL; |
| 8992 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL; |
| 8993 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return |
| 8994 | NULL; |
| 8995 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 8996 | NULL; |
| 8997 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 8998 | return NULL; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8999 | if (PyDict_SetItemString(d, "type_ignore", (PyObject*)type_ignore_type) < |
| 9000 | 0) return NULL; |
| 9001 | if (PyDict_SetItemString(d, "TypeIgnore", (PyObject*)TypeIgnore_type) < 0) |
| 9002 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9003 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9004 | } |
| 9005 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 9006 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 9007 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 9008 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 9009 | if (!init_types()) |
| 9010 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 9011 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 9012 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 9013 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 9014 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 9015 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9016 | { |
Guido van Rossum | 495da29 | 2019-03-07 12:38:08 -0800 | [diff] [blame] | 9017 | return PyAST_obj2mod_ex(ast, arena, mode, PY_MINOR_VERSION); |
| 9018 | } |
| 9019 | |
| 9020 | mod_ty PyAST_obj2mod_ex(PyObject* ast, PyArena* arena, int mode, int feature_version) |
| 9021 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9022 | mod_ty res; |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 9023 | PyObject *req_type[3]; |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 9024 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 9025 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 9026 | |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 9027 | if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { |
| 9028 | return NULL; |
| 9029 | } |
| 9030 | |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 9031 | req_type[0] = (PyObject*)Module_type; |
| 9032 | req_type[1] = (PyObject*)Expression_type; |
| 9033 | req_type[2] = (PyObject*)Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 9034 | |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 9035 | assert(0 <= mode && mode <= 2); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 9036 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 9037 | if (!init_types()) |
| 9038 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 9039 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 9040 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 9041 | if (isinstance == -1) |
| 9042 | return NULL; |
| 9043 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 9044 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 9045 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9046 | return NULL; |
| 9047 | } |
| 9048 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 9049 | return NULL; |
| 9050 | else |
| 9051 | return res; |
| 9052 | } |
| 9053 | |
| 9054 | int PyAST_Check(PyObject* obj) |
| 9055 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 9056 | if (!init_types()) |
| 9057 | return -1; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 9058 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9059 | } |
| 9060 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 9061 | |