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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 14 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 19 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 23 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 29 | static const char * const FunctionType_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 30 | "argtypes", |
| 31 | "returns", |
| 32 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 33 | static PyTypeObject *Suite_type; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 34 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 42 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 54 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 63 | static const char * const AsyncFunctionDef_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 74 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 83 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 88 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 92 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 100 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 108 | static const char * const AnnAssign_fields[]={ |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 117 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 125 | static const char * const AsyncFor_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 134 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 140 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 147 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 153 | static const char * const AsyncWith_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 161 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 168 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 176 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 182 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 188 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 194 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 198 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 202 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 209 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 218 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 223 | static const char * const NamedExpr_fields[]={ |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 230 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 237 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 242 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 247 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 254 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 260 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 266 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 271 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 277 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 283 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 288 | static const char * const Await_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 289 | "value", |
| 290 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 291 | static PyTypeObject *Yield_type; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 292 | static const char * const 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 296 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 302 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 309 | static const char * const 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); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 317 | static const char * const FormattedValue_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 318 | "value", |
| 319 | "conversion", |
| 320 | "format_spec", |
| 321 | }; |
| 322 | static PyTypeObject *JoinedStr_type; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 323 | static const char * const JoinedStr_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 324 | "values", |
| 325 | }; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 326 | static PyTypeObject *Constant_type; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 327 | _Py_IDENTIFIER(kind); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 328 | static const char * const Constant_fields[]={ |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 329 | "value", |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 330 | "kind", |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 331 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 332 | static PyTypeObject *Attribute_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 333 | _Py_IDENTIFIER(attr); |
| 334 | _Py_IDENTIFIER(ctx); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 335 | static const char * const Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 336 | "value", |
| 337 | "attr", |
| 338 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 339 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 340 | static PyTypeObject *Subscript_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 341 | _Py_IDENTIFIER(slice); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 342 | static const char * const Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 343 | "value", |
| 344 | "slice", |
| 345 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 346 | }; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 347 | static PyTypeObject *Starred_type; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 348 | static const char * const Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 349 | "value", |
| 350 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 351 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 352 | static PyTypeObject *Name_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 353 | _Py_IDENTIFIER(id); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 354 | static const char * const Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 355 | "id", |
| 356 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 357 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 358 | static PyTypeObject *List_type; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 359 | static const char * const List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 360 | "elts", |
| 361 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 362 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 363 | static PyTypeObject *Tuple_type; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 364 | static const char * const Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 365 | "elts", |
| 366 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 367 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 368 | static PyTypeObject *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 369 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
Serhiy Storchaka | d8b3a98 | 2019-03-05 20:42:06 +0200 | [diff] [blame] | 370 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 371 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 372 | static PyTypeObject *Load_type; |
| 373 | static PyTypeObject *Store_type; |
| 374 | static PyTypeObject *Del_type; |
| 375 | static PyTypeObject *AugLoad_type; |
| 376 | static PyTypeObject *AugStore_type; |
| 377 | static PyTypeObject *Param_type; |
| 378 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 379 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 380 | static PyTypeObject *Slice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 381 | _Py_IDENTIFIER(lower); |
| 382 | _Py_IDENTIFIER(upper); |
| 383 | _Py_IDENTIFIER(step); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 384 | static const char * const Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 385 | "lower", |
| 386 | "upper", |
| 387 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 388 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 389 | static PyTypeObject *ExtSlice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 390 | _Py_IDENTIFIER(dims); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 391 | static const char * const ExtSlice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 392 | "dims", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 393 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 394 | static PyTypeObject *Index_type; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 395 | static const char * const Index_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 396 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 397 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 398 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 399 | static PyObject *And_singleton, *Or_singleton; |
| 400 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 401 | static PyTypeObject *And_type; |
| 402 | static PyTypeObject *Or_type; |
| 403 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 404 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 405 | *MatMult_singleton, *Div_singleton, *Mod_singleton, *Pow_singleton, |
| 406 | *LShift_singleton, *RShift_singleton, *BitOr_singleton, *BitXor_singleton, |
| 407 | *BitAnd_singleton, *FloorDiv_singleton; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 408 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 409 | static PyTypeObject *Add_type; |
| 410 | static PyTypeObject *Sub_type; |
| 411 | static PyTypeObject *Mult_type; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 412 | static PyTypeObject *MatMult_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 413 | static PyTypeObject *Div_type; |
| 414 | static PyTypeObject *Mod_type; |
| 415 | static PyTypeObject *Pow_type; |
| 416 | static PyTypeObject *LShift_type; |
| 417 | static PyTypeObject *RShift_type; |
| 418 | static PyTypeObject *BitOr_type; |
| 419 | static PyTypeObject *BitXor_type; |
| 420 | static PyTypeObject *BitAnd_type; |
| 421 | static PyTypeObject *FloorDiv_type; |
| 422 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 423 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 424 | *USub_singleton; |
| 425 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 426 | static PyTypeObject *Invert_type; |
| 427 | static PyTypeObject *Not_type; |
| 428 | static PyTypeObject *UAdd_type; |
| 429 | static PyTypeObject *USub_type; |
| 430 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 431 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 432 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 433 | *NotIn_singleton; |
| 434 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 435 | static PyTypeObject *Eq_type; |
| 436 | static PyTypeObject *NotEq_type; |
| 437 | static PyTypeObject *Lt_type; |
| 438 | static PyTypeObject *LtE_type; |
| 439 | static PyTypeObject *Gt_type; |
| 440 | static PyTypeObject *GtE_type; |
| 441 | static PyTypeObject *Is_type; |
| 442 | static PyTypeObject *IsNot_type; |
| 443 | static PyTypeObject *In_type; |
| 444 | static PyTypeObject *NotIn_type; |
| 445 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 446 | static PyObject* ast2obj_comprehension(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 447 | _Py_IDENTIFIER(ifs); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 448 | _Py_IDENTIFIER(is_async); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 449 | static const char * const comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 450 | "target", |
| 451 | "iter", |
| 452 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 453 | "is_async", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 454 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 455 | static PyTypeObject *excepthandler_type; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 456 | static const char * const excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 457 | "lineno", |
| 458 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 459 | "end_lineno", |
| 460 | "end_col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 461 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 462 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 463 | static PyTypeObject *ExceptHandler_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 464 | _Py_IDENTIFIER(type); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 465 | static const char * const ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 466 | "type", |
| 467 | "name", |
| 468 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 469 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 470 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 471 | static PyObject* ast2obj_arguments(void*); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 472 | _Py_IDENTIFIER(posonlyargs); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 473 | _Py_IDENTIFIER(vararg); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 474 | _Py_IDENTIFIER(kwonlyargs); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 475 | _Py_IDENTIFIER(kw_defaults); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 476 | _Py_IDENTIFIER(kwarg); |
| 477 | _Py_IDENTIFIER(defaults); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 478 | static const char * const arguments_fields[]={ |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 479 | "posonlyargs", |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 480 | "args", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 481 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 482 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 483 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 484 | "kwarg", |
| 485 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 486 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 487 | static PyTypeObject *arg_type; |
| 488 | static PyObject* ast2obj_arg(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 489 | static const char * const arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 490 | "lineno", |
| 491 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 492 | "end_lineno", |
| 493 | "end_col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 494 | }; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 495 | _Py_IDENTIFIER(arg); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 496 | static const char * const arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 497 | "arg", |
| 498 | "annotation", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 499 | "type_comment", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 500 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 501 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 502 | static PyObject* ast2obj_keyword(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 503 | static const char * const keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 504 | "arg", |
| 505 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 506 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 507 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 508 | static PyObject* ast2obj_alias(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 509 | _Py_IDENTIFIER(asname); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 510 | static const char * const alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 511 | "name", |
| 512 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 513 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 514 | static PyTypeObject *withitem_type; |
| 515 | static PyObject* ast2obj_withitem(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 516 | _Py_IDENTIFIER(context_expr); |
| 517 | _Py_IDENTIFIER(optional_vars); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 518 | static const char * const withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 519 | "context_expr", |
| 520 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 521 | }; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 522 | static PyTypeObject *type_ignore_type; |
| 523 | static PyObject* ast2obj_type_ignore(void*); |
| 524 | static PyTypeObject *TypeIgnore_type; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 525 | _Py_IDENTIFIER(tag); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 526 | static const char * const TypeIgnore_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 527 | "lineno", |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 528 | "tag", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 529 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 530 | |
| 531 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 532 | _Py_IDENTIFIER(_fields); |
| 533 | _Py_IDENTIFIER(_attributes); |
| 534 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 535 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 536 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 537 | PyObject *dict; |
| 538 | } AST_object; |
| 539 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 540 | static void |
| 541 | ast_dealloc(AST_object *self) |
| 542 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 543 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
| 544 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 545 | Py_CLEAR(self->dict); |
Antoine Pitrou | 5075074 | 2012-07-08 12:43:32 +0200 | [diff] [blame] | 546 | Py_TYPE(self)->tp_free(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 547 | } |
| 548 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 549 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 550 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 551 | { |
| 552 | Py_VISIT(self->dict); |
| 553 | return 0; |
| 554 | } |
| 555 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 556 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 557 | ast_clear(AST_object *self) |
| 558 | { |
| 559 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 560 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 564 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 565 | { |
| 566 | Py_ssize_t i, numfields = 0; |
| 567 | int res = -1; |
| 568 | PyObject *key, *value, *fields; |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 569 | if (_PyObject_LookupAttrId((PyObject*)Py_TYPE(self), &PyId__fields, &fields) < 0) { |
| 570 | goto cleanup; |
| 571 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 572 | if (fields) { |
| 573 | numfields = PySequence_Size(fields); |
| 574 | if (numfields == -1) |
| 575 | goto cleanup; |
| 576 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 577 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 578 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 579 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 580 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 581 | "%zd positional argument%s", |
| 582 | Py_TYPE(self)->tp_name, |
| 583 | numfields, numfields == 1 ? "" : "s"); |
| 584 | res = -1; |
| 585 | goto cleanup; |
| 586 | } |
| 587 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 588 | /* cannot be reached when fields is NULL */ |
| 589 | PyObject *name = PySequence_GetItem(fields, i); |
| 590 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 591 | res = -1; |
| 592 | goto cleanup; |
| 593 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 594 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 595 | Py_DECREF(name); |
| 596 | if (res < 0) |
| 597 | goto cleanup; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 598 | } |
| 599 | if (kw) { |
| 600 | i = 0; /* needed by PyDict_Next */ |
| 601 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 602 | res = PyObject_SetAttr(self, key, value); |
| 603 | if (res < 0) |
| 604 | goto cleanup; |
| 605 | } |
| 606 | } |
| 607 | cleanup: |
| 608 | Py_XDECREF(fields); |
| 609 | return res; |
| 610 | } |
| 611 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 612 | /* Pickling support */ |
| 613 | static PyObject * |
| 614 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 615 | { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 616 | _Py_IDENTIFIER(__dict__); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 617 | PyObject *dict; |
| 618 | if (_PyObject_LookupAttrId(self, &PyId___dict__, &dict) < 0) { |
| 619 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 620 | } |
| 621 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 622 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 623 | } |
| 624 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 625 | } |
| 626 | |
| 627 | static PyMethodDef ast_type_methods[] = { |
| 628 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 629 | {NULL} |
| 630 | }; |
| 631 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 632 | static PyGetSetDef ast_type_getsets[] = { |
| 633 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 634 | {NULL} |
| 635 | }; |
| 636 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 637 | static PyTypeObject AST_type = { |
| 638 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 639 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 640 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 641 | 0, |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 642 | (destructor)ast_dealloc, /* tp_dealloc */ |
Jeroen Demeyer | 530f506 | 2019-05-31 04:13:39 +0200 | [diff] [blame] | 643 | 0, /* tp_vectorcall_offset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 644 | 0, /* tp_getattr */ |
| 645 | 0, /* tp_setattr */ |
Jeroen Demeyer | 530f506 | 2019-05-31 04:13:39 +0200 | [diff] [blame] | 646 | 0, /* tp_as_async */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 647 | 0, /* tp_repr */ |
| 648 | 0, /* tp_as_number */ |
| 649 | 0, /* tp_as_sequence */ |
| 650 | 0, /* tp_as_mapping */ |
| 651 | 0, /* tp_hash */ |
| 652 | 0, /* tp_call */ |
| 653 | 0, /* tp_str */ |
| 654 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 655 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 656 | 0, /* tp_as_buffer */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 657 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 658 | 0, /* tp_doc */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 659 | (traverseproc)ast_traverse, /* tp_traverse */ |
| 660 | (inquiry)ast_clear, /* tp_clear */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 661 | 0, /* tp_richcompare */ |
| 662 | 0, /* tp_weaklistoffset */ |
| 663 | 0, /* tp_iter */ |
| 664 | 0, /* tp_iternext */ |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 665 | ast_type_methods, /* tp_methods */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 666 | 0, /* tp_members */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 667 | ast_type_getsets, /* tp_getset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 668 | 0, /* tp_base */ |
| 669 | 0, /* tp_dict */ |
| 670 | 0, /* tp_descr_get */ |
| 671 | 0, /* tp_descr_set */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 672 | offsetof(AST_object, dict),/* tp_dictoffset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 673 | (initproc)ast_type_init, /* tp_init */ |
| 674 | PyType_GenericAlloc, /* tp_alloc */ |
| 675 | PyType_GenericNew, /* tp_new */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 676 | PyObject_GC_Del, /* tp_free */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 677 | }; |
| 678 | |
| 679 | |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 680 | static PyTypeObject * |
| 681 | make_type(const char *type, PyTypeObject *base, const char * const *fields, int num_fields) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 682 | { |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 683 | _Py_IDENTIFIER(__module__); |
| 684 | _Py_IDENTIFIER(_ast); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 685 | PyObject *fnames, *result; |
| 686 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 687 | fnames = PyTuple_New(num_fields); |
| 688 | if (!fnames) return NULL; |
| 689 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 690 | PyObject *field = PyUnicode_InternFromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 691 | if (!field) { |
| 692 | Py_DECREF(fnames); |
| 693 | return NULL; |
| 694 | } |
| 695 | PyTuple_SET_ITEM(fnames, i, field); |
| 696 | } |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 697 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}", |
| 698 | type, base, |
| 699 | _PyUnicode_FromId(&PyId__fields), fnames, |
| 700 | _PyUnicode_FromId(&PyId___module__), |
| 701 | _PyUnicode_FromId(&PyId__ast)); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 702 | Py_DECREF(fnames); |
| 703 | return (PyTypeObject*)result; |
| 704 | } |
| 705 | |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 706 | static int |
| 707 | add_attributes(PyTypeObject *type, const char * const *attrs, int num_fields) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 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++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 714 | s = PyUnicode_InternFromString(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 | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 957 | FormattedValue_fields, 3); |
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 | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 2256 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
| 2257 | int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2258 | *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; |
| 2273 | p->lineno = lineno; |
| 2274 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2275 | p->end_lineno = end_lineno; |
| 2276 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2277 | return p; |
| 2278 | } |
| 2279 | |
| 2280 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2281 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 2282 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2283 | { |
| 2284 | expr_ty p; |
| 2285 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2286 | if (!p) |
| 2287 | return NULL; |
| 2288 | p->kind = JoinedStr_kind; |
| 2289 | p->v.JoinedStr.values = values; |
| 2290 | p->lineno = lineno; |
| 2291 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2292 | p->end_lineno = end_lineno; |
| 2293 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2294 | return p; |
| 2295 | } |
| 2296 | |
| 2297 | expr_ty |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 2298 | Constant(constant value, string kind, int lineno, int col_offset, int |
| 2299 | end_lineno, int end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2300 | { |
| 2301 | expr_ty p; |
| 2302 | if (!value) { |
| 2303 | PyErr_SetString(PyExc_ValueError, |
| 2304 | "field value is required for Constant"); |
| 2305 | return NULL; |
| 2306 | } |
| 2307 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2308 | if (!p) |
| 2309 | return NULL; |
| 2310 | p->kind = Constant_kind; |
| 2311 | p->v.Constant.value = value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 2312 | p->v.Constant.kind = kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2313 | p->lineno = lineno; |
| 2314 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2315 | p->end_lineno = end_lineno; |
| 2316 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2317 | return p; |
| 2318 | } |
| 2319 | |
| 2320 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2321 | 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] | 2322 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2323 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2324 | expr_ty p; |
| 2325 | if (!value) { |
| 2326 | PyErr_SetString(PyExc_ValueError, |
| 2327 | "field value is required for Attribute"); |
| 2328 | return NULL; |
| 2329 | } |
| 2330 | if (!attr) { |
| 2331 | PyErr_SetString(PyExc_ValueError, |
| 2332 | "field attr is required for Attribute"); |
| 2333 | return NULL; |
| 2334 | } |
| 2335 | if (!ctx) { |
| 2336 | PyErr_SetString(PyExc_ValueError, |
| 2337 | "field ctx is required for Attribute"); |
| 2338 | return NULL; |
| 2339 | } |
| 2340 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2341 | if (!p) |
| 2342 | return NULL; |
| 2343 | p->kind = Attribute_kind; |
| 2344 | p->v.Attribute.value = value; |
| 2345 | p->v.Attribute.attr = attr; |
| 2346 | p->v.Attribute.ctx = ctx; |
| 2347 | p->lineno = lineno; |
| 2348 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2349 | p->end_lineno = end_lineno; |
| 2350 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2351 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2355 | 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] | 2356 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2357 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2358 | expr_ty p; |
| 2359 | if (!value) { |
| 2360 | PyErr_SetString(PyExc_ValueError, |
| 2361 | "field value is required for Subscript"); |
| 2362 | return NULL; |
| 2363 | } |
| 2364 | if (!slice) { |
| 2365 | PyErr_SetString(PyExc_ValueError, |
| 2366 | "field slice is required for Subscript"); |
| 2367 | return NULL; |
| 2368 | } |
| 2369 | if (!ctx) { |
| 2370 | PyErr_SetString(PyExc_ValueError, |
| 2371 | "field ctx is required for Subscript"); |
| 2372 | return NULL; |
| 2373 | } |
| 2374 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2375 | if (!p) |
| 2376 | return NULL; |
| 2377 | p->kind = Subscript_kind; |
| 2378 | p->v.Subscript.value = value; |
| 2379 | p->v.Subscript.slice = slice; |
| 2380 | p->v.Subscript.ctx = ctx; |
| 2381 | p->lineno = lineno; |
| 2382 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2383 | p->end_lineno = end_lineno; |
| 2384 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2385 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2389 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 2390 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2391 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2392 | expr_ty p; |
| 2393 | if (!value) { |
| 2394 | PyErr_SetString(PyExc_ValueError, |
| 2395 | "field value is required for Starred"); |
| 2396 | return NULL; |
| 2397 | } |
| 2398 | if (!ctx) { |
| 2399 | PyErr_SetString(PyExc_ValueError, |
| 2400 | "field ctx is required for Starred"); |
| 2401 | return NULL; |
| 2402 | } |
| 2403 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2404 | if (!p) |
| 2405 | return NULL; |
| 2406 | p->kind = Starred_kind; |
| 2407 | p->v.Starred.value = value; |
| 2408 | p->v.Starred.ctx = ctx; |
| 2409 | p->lineno = lineno; |
| 2410 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2411 | p->end_lineno = end_lineno; |
| 2412 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2413 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2417 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 2418 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2419 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2420 | expr_ty p; |
| 2421 | if (!id) { |
| 2422 | PyErr_SetString(PyExc_ValueError, |
| 2423 | "field id is required for Name"); |
| 2424 | return NULL; |
| 2425 | } |
| 2426 | if (!ctx) { |
| 2427 | PyErr_SetString(PyExc_ValueError, |
| 2428 | "field ctx is required for Name"); |
| 2429 | return NULL; |
| 2430 | } |
| 2431 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2432 | if (!p) |
| 2433 | return NULL; |
| 2434 | p->kind = Name_kind; |
| 2435 | p->v.Name.id = id; |
| 2436 | p->v.Name.ctx = ctx; |
| 2437 | p->lineno = lineno; |
| 2438 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2439 | p->end_lineno = end_lineno; |
| 2440 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2441 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2445 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 2446 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2447 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2448 | expr_ty p; |
| 2449 | if (!ctx) { |
| 2450 | PyErr_SetString(PyExc_ValueError, |
| 2451 | "field ctx is required for List"); |
| 2452 | return NULL; |
| 2453 | } |
| 2454 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2455 | if (!p) |
| 2456 | return NULL; |
| 2457 | p->kind = List_kind; |
| 2458 | p->v.List.elts = elts; |
| 2459 | p->v.List.ctx = ctx; |
| 2460 | p->lineno = lineno; |
| 2461 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2462 | p->end_lineno = end_lineno; |
| 2463 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2464 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2465 | } |
| 2466 | |
| 2467 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2468 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 2469 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2470 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2471 | expr_ty p; |
| 2472 | if (!ctx) { |
| 2473 | PyErr_SetString(PyExc_ValueError, |
| 2474 | "field ctx is required for Tuple"); |
| 2475 | return NULL; |
| 2476 | } |
| 2477 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2478 | if (!p) |
| 2479 | return NULL; |
| 2480 | p->kind = Tuple_kind; |
| 2481 | p->v.Tuple.elts = elts; |
| 2482 | p->v.Tuple.ctx = ctx; |
| 2483 | p->lineno = lineno; |
| 2484 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2485 | p->end_lineno = end_lineno; |
| 2486 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2487 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2491 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2492 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2493 | slice_ty p; |
| 2494 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2495 | if (!p) |
| 2496 | return NULL; |
| 2497 | p->kind = Slice_kind; |
| 2498 | p->v.Slice.lower = lower; |
| 2499 | p->v.Slice.upper = upper; |
| 2500 | p->v.Slice.step = step; |
| 2501 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2505 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2506 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2507 | slice_ty p; |
| 2508 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2509 | if (!p) |
| 2510 | return NULL; |
| 2511 | p->kind = ExtSlice_kind; |
| 2512 | p->v.ExtSlice.dims = dims; |
| 2513 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2514 | } |
| 2515 | |
| 2516 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2517 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2518 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2519 | slice_ty p; |
| 2520 | if (!value) { |
| 2521 | PyErr_SetString(PyExc_ValueError, |
| 2522 | "field value is required for Index"); |
| 2523 | return NULL; |
| 2524 | } |
| 2525 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2526 | if (!p) |
| 2527 | return NULL; |
| 2528 | p->kind = Index_kind; |
| 2529 | p->v.Index.value = value; |
| 2530 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 2534 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 2535 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2536 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2537 | comprehension_ty p; |
| 2538 | if (!target) { |
| 2539 | PyErr_SetString(PyExc_ValueError, |
| 2540 | "field target is required for comprehension"); |
| 2541 | return NULL; |
| 2542 | } |
| 2543 | if (!iter) { |
| 2544 | PyErr_SetString(PyExc_ValueError, |
| 2545 | "field iter is required for comprehension"); |
| 2546 | return NULL; |
| 2547 | } |
| 2548 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2549 | if (!p) |
| 2550 | return NULL; |
| 2551 | p->target = target; |
| 2552 | p->iter = iter; |
| 2553 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 2554 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2555 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2556 | } |
| 2557 | |
| 2558 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2559 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2560 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2561 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2562 | excepthandler_ty p; |
| 2563 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2564 | if (!p) |
| 2565 | return NULL; |
| 2566 | p->kind = ExceptHandler_kind; |
| 2567 | p->v.ExceptHandler.type = type; |
| 2568 | p->v.ExceptHandler.name = name; |
| 2569 | p->v.ExceptHandler.body = body; |
| 2570 | p->lineno = lineno; |
| 2571 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2572 | p->end_lineno = end_lineno; |
| 2573 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2574 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2575 | } |
| 2576 | |
| 2577 | arguments_ty |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 2578 | arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq * |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 2579 | kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq * |
| 2580 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2581 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2582 | arguments_ty p; |
| 2583 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2584 | if (!p) |
| 2585 | return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 2586 | p->posonlyargs = posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 2587 | p->args = args; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2588 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2589 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2590 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 2591 | p->kwarg = kwarg; |
| 2592 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2593 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2594 | } |
| 2595 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2596 | arg_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2597 | arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int |
| 2598 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2599 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2600 | arg_ty p; |
| 2601 | if (!arg) { |
| 2602 | PyErr_SetString(PyExc_ValueError, |
| 2603 | "field arg is required for arg"); |
| 2604 | return NULL; |
| 2605 | } |
| 2606 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2607 | if (!p) |
| 2608 | return NULL; |
| 2609 | p->arg = arg; |
| 2610 | p->annotation = annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2611 | p->type_comment = type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 2612 | p->lineno = lineno; |
| 2613 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2614 | p->end_lineno = end_lineno; |
| 2615 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2616 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2617 | } |
| 2618 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2619 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2620 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2621 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2622 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2623 | if (!value) { |
| 2624 | PyErr_SetString(PyExc_ValueError, |
| 2625 | "field value is required for keyword"); |
| 2626 | return NULL; |
| 2627 | } |
| 2628 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2629 | if (!p) |
| 2630 | return NULL; |
| 2631 | p->arg = arg; |
| 2632 | p->value = value; |
| 2633 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2637 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2638 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2639 | alias_ty p; |
| 2640 | if (!name) { |
| 2641 | PyErr_SetString(PyExc_ValueError, |
| 2642 | "field name is required for alias"); |
| 2643 | return NULL; |
| 2644 | } |
| 2645 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2646 | if (!p) |
| 2647 | return NULL; |
| 2648 | p->name = name; |
| 2649 | p->asname = asname; |
| 2650 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2651 | } |
| 2652 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2653 | withitem_ty |
| 2654 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2655 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2656 | withitem_ty p; |
| 2657 | if (!context_expr) { |
| 2658 | PyErr_SetString(PyExc_ValueError, |
| 2659 | "field context_expr is required for withitem"); |
| 2660 | return NULL; |
| 2661 | } |
| 2662 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2663 | if (!p) |
| 2664 | return NULL; |
| 2665 | p->context_expr = context_expr; |
| 2666 | p->optional_vars = optional_vars; |
| 2667 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2668 | } |
| 2669 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2670 | type_ignore_ty |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 2671 | TypeIgnore(int lineno, string tag, PyArena *arena) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2672 | { |
| 2673 | type_ignore_ty p; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 2674 | if (!tag) { |
| 2675 | PyErr_SetString(PyExc_ValueError, |
| 2676 | "field tag is required for TypeIgnore"); |
| 2677 | return NULL; |
| 2678 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2679 | p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2680 | if (!p) |
| 2681 | return NULL; |
| 2682 | p->kind = TypeIgnore_kind; |
| 2683 | p->v.TypeIgnore.lineno = lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 2684 | p->v.TypeIgnore.tag = tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2685 | return p; |
| 2686 | } |
| 2687 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2688 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2689 | PyObject* |
| 2690 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2691 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2692 | mod_ty o = (mod_ty)_o; |
| 2693 | PyObject *result = NULL, *value = NULL; |
| 2694 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 2695 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2696 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2697 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2698 | switch (o->kind) { |
| 2699 | case Module_kind: |
| 2700 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2701 | if (!result) goto failed; |
| 2702 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2703 | if (!value) goto failed; |
| 2704 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2705 | goto failed; |
| 2706 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2707 | value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); |
| 2708 | if (!value) goto failed; |
| 2709 | if (_PyObject_SetAttrId(result, &PyId_type_ignores, value) == -1) |
| 2710 | goto failed; |
| 2711 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2712 | break; |
| 2713 | case Interactive_kind: |
| 2714 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2715 | if (!result) goto failed; |
| 2716 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2717 | if (!value) goto failed; |
| 2718 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2719 | goto failed; |
| 2720 | Py_DECREF(value); |
| 2721 | break; |
| 2722 | case Expression_kind: |
| 2723 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2724 | if (!result) goto failed; |
| 2725 | value = ast2obj_expr(o->v.Expression.body); |
| 2726 | if (!value) goto failed; |
| 2727 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2728 | goto failed; |
| 2729 | Py_DECREF(value); |
| 2730 | break; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2731 | case FunctionType_kind: |
| 2732 | result = PyType_GenericNew(FunctionType_type, NULL, NULL); |
| 2733 | if (!result) goto failed; |
| 2734 | value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); |
| 2735 | if (!value) goto failed; |
| 2736 | if (_PyObject_SetAttrId(result, &PyId_argtypes, value) == -1) |
| 2737 | goto failed; |
| 2738 | Py_DECREF(value); |
| 2739 | value = ast2obj_expr(o->v.FunctionType.returns); |
| 2740 | if (!value) goto failed; |
| 2741 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2742 | goto failed; |
| 2743 | Py_DECREF(value); |
| 2744 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2745 | case Suite_kind: |
| 2746 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2747 | if (!result) goto failed; |
| 2748 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2749 | if (!value) goto failed; |
| 2750 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2751 | goto failed; |
| 2752 | Py_DECREF(value); |
| 2753 | break; |
| 2754 | } |
| 2755 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2756 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2757 | Py_XDECREF(value); |
| 2758 | Py_XDECREF(result); |
| 2759 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2760 | } |
| 2761 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2762 | PyObject* |
| 2763 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2764 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2765 | stmt_ty o = (stmt_ty)_o; |
| 2766 | PyObject *result = NULL, *value = NULL; |
| 2767 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 2768 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2769 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2770 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2771 | switch (o->kind) { |
| 2772 | case FunctionDef_kind: |
| 2773 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2774 | if (!result) goto failed; |
| 2775 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2776 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2777 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2778 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2779 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2780 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2781 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2782 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2783 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2784 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2785 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2786 | if (!value) goto failed; |
| 2787 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2788 | goto failed; |
| 2789 | Py_DECREF(value); |
| 2790 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 2791 | if (!value) goto failed; |
| 2792 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2793 | goto failed; |
| 2794 | Py_DECREF(value); |
| 2795 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2796 | if (!value) goto failed; |
| 2797 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2798 | goto failed; |
| 2799 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2800 | value = ast2obj_string(o->v.FunctionDef.type_comment); |
| 2801 | if (!value) goto failed; |
| 2802 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2803 | goto failed; |
| 2804 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2805 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2806 | case AsyncFunctionDef_kind: |
| 2807 | result = PyType_GenericNew(AsyncFunctionDef_type, NULL, NULL); |
| 2808 | if (!result) goto failed; |
| 2809 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 2810 | if (!value) goto failed; |
| 2811 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2812 | goto failed; |
| 2813 | Py_DECREF(value); |
| 2814 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 2815 | if (!value) goto failed; |
| 2816 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2817 | goto failed; |
| 2818 | Py_DECREF(value); |
| 2819 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 2820 | if (!value) goto failed; |
| 2821 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2822 | goto failed; |
| 2823 | Py_DECREF(value); |
| 2824 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 2825 | ast2obj_expr); |
| 2826 | if (!value) goto failed; |
| 2827 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2828 | goto failed; |
| 2829 | Py_DECREF(value); |
| 2830 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 2831 | if (!value) goto failed; |
| 2832 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2833 | goto failed; |
| 2834 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2835 | value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); |
| 2836 | if (!value) goto failed; |
| 2837 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2838 | goto failed; |
| 2839 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2840 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2841 | case ClassDef_kind: |
| 2842 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2843 | if (!result) goto failed; |
| 2844 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2845 | if (!value) goto failed; |
| 2846 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2847 | goto failed; |
| 2848 | Py_DECREF(value); |
| 2849 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2850 | if (!value) goto failed; |
| 2851 | if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) |
| 2852 | goto failed; |
| 2853 | Py_DECREF(value); |
| 2854 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2855 | if (!value) goto failed; |
| 2856 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 2857 | goto failed; |
| 2858 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2859 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2860 | if (!value) goto failed; |
| 2861 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2862 | goto failed; |
| 2863 | Py_DECREF(value); |
| 2864 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 2865 | if (!value) goto failed; |
| 2866 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2867 | goto failed; |
| 2868 | Py_DECREF(value); |
| 2869 | break; |
| 2870 | case Return_kind: |
| 2871 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2872 | if (!result) goto failed; |
| 2873 | value = ast2obj_expr(o->v.Return.value); |
| 2874 | if (!value) goto failed; |
| 2875 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2876 | goto failed; |
| 2877 | Py_DECREF(value); |
| 2878 | break; |
| 2879 | case Delete_kind: |
| 2880 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2881 | if (!result) goto failed; |
| 2882 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2883 | if (!value) goto failed; |
| 2884 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2885 | goto failed; |
| 2886 | Py_DECREF(value); |
| 2887 | break; |
| 2888 | case Assign_kind: |
| 2889 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2890 | if (!result) goto failed; |
| 2891 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2892 | if (!value) goto failed; |
| 2893 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2894 | goto failed; |
| 2895 | Py_DECREF(value); |
| 2896 | value = ast2obj_expr(o->v.Assign.value); |
| 2897 | if (!value) goto failed; |
| 2898 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2899 | goto failed; |
| 2900 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2901 | value = ast2obj_string(o->v.Assign.type_comment); |
| 2902 | if (!value) goto failed; |
| 2903 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2904 | goto failed; |
| 2905 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2906 | break; |
| 2907 | case AugAssign_kind: |
| 2908 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2909 | if (!result) goto failed; |
| 2910 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2911 | if (!value) goto failed; |
| 2912 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2913 | goto failed; |
| 2914 | Py_DECREF(value); |
| 2915 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2916 | if (!value) goto failed; |
| 2917 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2918 | goto failed; |
| 2919 | Py_DECREF(value); |
| 2920 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2921 | if (!value) goto failed; |
| 2922 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2923 | goto failed; |
| 2924 | Py_DECREF(value); |
| 2925 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2926 | case AnnAssign_kind: |
| 2927 | result = PyType_GenericNew(AnnAssign_type, NULL, NULL); |
| 2928 | if (!result) goto failed; |
| 2929 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 2930 | if (!value) goto failed; |
| 2931 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2932 | goto failed; |
| 2933 | Py_DECREF(value); |
| 2934 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 2935 | if (!value) goto failed; |
| 2936 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 2937 | goto failed; |
| 2938 | Py_DECREF(value); |
| 2939 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 2940 | if (!value) goto failed; |
| 2941 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2942 | goto failed; |
| 2943 | Py_DECREF(value); |
| 2944 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 2945 | if (!value) goto failed; |
| 2946 | if (_PyObject_SetAttrId(result, &PyId_simple, value) == -1) |
| 2947 | goto failed; |
| 2948 | Py_DECREF(value); |
| 2949 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2950 | case For_kind: |
| 2951 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2952 | if (!result) goto failed; |
| 2953 | value = ast2obj_expr(o->v.For.target); |
| 2954 | if (!value) goto failed; |
| 2955 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2956 | goto failed; |
| 2957 | Py_DECREF(value); |
| 2958 | value = ast2obj_expr(o->v.For.iter); |
| 2959 | if (!value) goto failed; |
| 2960 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2961 | goto failed; |
| 2962 | Py_DECREF(value); |
| 2963 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2964 | if (!value) goto failed; |
| 2965 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2966 | goto failed; |
| 2967 | Py_DECREF(value); |
| 2968 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2969 | if (!value) goto failed; |
| 2970 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2971 | goto failed; |
| 2972 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2973 | value = ast2obj_string(o->v.For.type_comment); |
| 2974 | if (!value) goto failed; |
| 2975 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 2976 | goto failed; |
| 2977 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2978 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2979 | case AsyncFor_kind: |
| 2980 | result = PyType_GenericNew(AsyncFor_type, NULL, NULL); |
| 2981 | if (!result) goto failed; |
| 2982 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 2983 | if (!value) goto failed; |
| 2984 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2985 | goto failed; |
| 2986 | Py_DECREF(value); |
| 2987 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 2988 | if (!value) goto failed; |
| 2989 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2990 | goto failed; |
| 2991 | Py_DECREF(value); |
| 2992 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 2993 | if (!value) goto failed; |
| 2994 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2995 | goto failed; |
| 2996 | Py_DECREF(value); |
| 2997 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 2998 | if (!value) goto failed; |
| 2999 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3000 | goto failed; |
| 3001 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3002 | value = ast2obj_string(o->v.AsyncFor.type_comment); |
| 3003 | if (!value) goto failed; |
| 3004 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 3005 | goto failed; |
| 3006 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3007 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3008 | case While_kind: |
| 3009 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 3010 | if (!result) goto failed; |
| 3011 | value = ast2obj_expr(o->v.While.test); |
| 3012 | if (!value) goto failed; |
| 3013 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3014 | goto failed; |
| 3015 | Py_DECREF(value); |
| 3016 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 3017 | if (!value) goto failed; |
| 3018 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3019 | goto failed; |
| 3020 | Py_DECREF(value); |
| 3021 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 3022 | if (!value) goto failed; |
| 3023 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3024 | goto failed; |
| 3025 | Py_DECREF(value); |
| 3026 | break; |
| 3027 | case If_kind: |
| 3028 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 3029 | if (!result) goto failed; |
| 3030 | value = ast2obj_expr(o->v.If.test); |
| 3031 | if (!value) goto failed; |
| 3032 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3033 | goto failed; |
| 3034 | Py_DECREF(value); |
| 3035 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 3036 | if (!value) goto failed; |
| 3037 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3038 | goto failed; |
| 3039 | Py_DECREF(value); |
| 3040 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 3041 | if (!value) goto failed; |
| 3042 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3043 | goto failed; |
| 3044 | Py_DECREF(value); |
| 3045 | break; |
| 3046 | case With_kind: |
| 3047 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 3048 | if (!result) goto failed; |
| 3049 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 3050 | if (!value) goto failed; |
| 3051 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 3052 | goto failed; |
| 3053 | Py_DECREF(value); |
| 3054 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 3055 | if (!value) goto failed; |
| 3056 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3057 | goto failed; |
| 3058 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3059 | value = ast2obj_string(o->v.With.type_comment); |
| 3060 | if (!value) goto failed; |
| 3061 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 3062 | goto failed; |
| 3063 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3064 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3065 | case AsyncWith_kind: |
| 3066 | result = PyType_GenericNew(AsyncWith_type, NULL, NULL); |
| 3067 | if (!result) goto failed; |
| 3068 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 3069 | if (!value) goto failed; |
| 3070 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 3071 | goto failed; |
| 3072 | Py_DECREF(value); |
| 3073 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 3074 | if (!value) goto failed; |
| 3075 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3076 | goto failed; |
| 3077 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3078 | value = ast2obj_string(o->v.AsyncWith.type_comment); |
| 3079 | if (!value) goto failed; |
| 3080 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 3081 | goto failed; |
| 3082 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3083 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3084 | case Raise_kind: |
| 3085 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 3086 | if (!result) goto failed; |
| 3087 | value = ast2obj_expr(o->v.Raise.exc); |
| 3088 | if (!value) goto failed; |
| 3089 | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
| 3090 | goto failed; |
| 3091 | Py_DECREF(value); |
| 3092 | value = ast2obj_expr(o->v.Raise.cause); |
| 3093 | if (!value) goto failed; |
| 3094 | if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) |
| 3095 | goto failed; |
| 3096 | Py_DECREF(value); |
| 3097 | break; |
| 3098 | case Try_kind: |
| 3099 | result = PyType_GenericNew(Try_type, NULL, NULL); |
| 3100 | if (!result) goto failed; |
| 3101 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 3102 | if (!value) goto failed; |
| 3103 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3104 | goto failed; |
| 3105 | Py_DECREF(value); |
| 3106 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 3107 | if (!value) goto failed; |
| 3108 | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
| 3109 | goto failed; |
| 3110 | Py_DECREF(value); |
| 3111 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 3112 | if (!value) goto failed; |
| 3113 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3114 | goto failed; |
| 3115 | Py_DECREF(value); |
| 3116 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 3117 | if (!value) goto failed; |
| 3118 | if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) |
| 3119 | goto failed; |
| 3120 | Py_DECREF(value); |
| 3121 | break; |
| 3122 | case Assert_kind: |
| 3123 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 3124 | if (!result) goto failed; |
| 3125 | value = ast2obj_expr(o->v.Assert.test); |
| 3126 | if (!value) goto failed; |
| 3127 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3128 | goto failed; |
| 3129 | Py_DECREF(value); |
| 3130 | value = ast2obj_expr(o->v.Assert.msg); |
| 3131 | if (!value) goto failed; |
| 3132 | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
| 3133 | goto failed; |
| 3134 | Py_DECREF(value); |
| 3135 | break; |
| 3136 | case Import_kind: |
| 3137 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 3138 | if (!result) goto failed; |
| 3139 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 3140 | if (!value) goto failed; |
| 3141 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3142 | goto failed; |
| 3143 | Py_DECREF(value); |
| 3144 | break; |
| 3145 | case ImportFrom_kind: |
| 3146 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 3147 | if (!result) goto failed; |
| 3148 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 3149 | if (!value) goto failed; |
| 3150 | if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) |
| 3151 | goto failed; |
| 3152 | Py_DECREF(value); |
| 3153 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 3154 | if (!value) goto failed; |
| 3155 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3156 | goto failed; |
| 3157 | Py_DECREF(value); |
| 3158 | value = ast2obj_int(o->v.ImportFrom.level); |
| 3159 | if (!value) goto failed; |
| 3160 | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
| 3161 | goto failed; |
| 3162 | Py_DECREF(value); |
| 3163 | break; |
| 3164 | case Global_kind: |
| 3165 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 3166 | if (!result) goto failed; |
| 3167 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 3168 | if (!value) goto failed; |
| 3169 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3170 | goto failed; |
| 3171 | Py_DECREF(value); |
| 3172 | break; |
| 3173 | case Nonlocal_kind: |
| 3174 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 3175 | if (!result) goto failed; |
| 3176 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 3177 | if (!value) goto failed; |
| 3178 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3179 | goto failed; |
| 3180 | Py_DECREF(value); |
| 3181 | break; |
| 3182 | case Expr_kind: |
| 3183 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 3184 | if (!result) goto failed; |
| 3185 | value = ast2obj_expr(o->v.Expr.value); |
| 3186 | if (!value) goto failed; |
| 3187 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3188 | goto failed; |
| 3189 | Py_DECREF(value); |
| 3190 | break; |
| 3191 | case Pass_kind: |
| 3192 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 3193 | if (!result) goto failed; |
| 3194 | break; |
| 3195 | case Break_kind: |
| 3196 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 3197 | if (!result) goto failed; |
| 3198 | break; |
| 3199 | case Continue_kind: |
| 3200 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 3201 | if (!result) goto failed; |
| 3202 | break; |
| 3203 | } |
| 3204 | value = ast2obj_int(o->lineno); |
| 3205 | if (!value) goto failed; |
| 3206 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3207 | goto failed; |
| 3208 | Py_DECREF(value); |
| 3209 | value = ast2obj_int(o->col_offset); |
| 3210 | if (!value) goto failed; |
| 3211 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3212 | goto failed; |
| 3213 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3214 | value = ast2obj_int(o->end_lineno); |
| 3215 | if (!value) goto failed; |
| 3216 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3217 | goto failed; |
| 3218 | Py_DECREF(value); |
| 3219 | value = ast2obj_int(o->end_col_offset); |
| 3220 | if (!value) goto failed; |
| 3221 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3222 | goto failed; |
| 3223 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3224 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3225 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3226 | Py_XDECREF(value); |
| 3227 | Py_XDECREF(result); |
| 3228 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3229 | } |
| 3230 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3231 | PyObject* |
| 3232 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3233 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3234 | expr_ty o = (expr_ty)_o; |
| 3235 | PyObject *result = NULL, *value = NULL; |
| 3236 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3237 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3238 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3239 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3240 | switch (o->kind) { |
| 3241 | case BoolOp_kind: |
| 3242 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 3243 | if (!result) goto failed; |
| 3244 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 3245 | if (!value) goto failed; |
| 3246 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3247 | goto failed; |
| 3248 | Py_DECREF(value); |
| 3249 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 3250 | if (!value) goto failed; |
| 3251 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3252 | goto failed; |
| 3253 | Py_DECREF(value); |
| 3254 | break; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3255 | case NamedExpr_kind: |
| 3256 | result = PyType_GenericNew(NamedExpr_type, NULL, NULL); |
| 3257 | if (!result) goto failed; |
| 3258 | value = ast2obj_expr(o->v.NamedExpr.target); |
| 3259 | if (!value) goto failed; |
| 3260 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 3261 | goto failed; |
| 3262 | Py_DECREF(value); |
| 3263 | value = ast2obj_expr(o->v.NamedExpr.value); |
| 3264 | if (!value) goto failed; |
| 3265 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3266 | goto failed; |
| 3267 | Py_DECREF(value); |
| 3268 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3269 | case BinOp_kind: |
| 3270 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 3271 | if (!result) goto failed; |
| 3272 | value = ast2obj_expr(o->v.BinOp.left); |
| 3273 | if (!value) goto failed; |
| 3274 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3275 | goto failed; |
| 3276 | Py_DECREF(value); |
| 3277 | value = ast2obj_operator(o->v.BinOp.op); |
| 3278 | if (!value) goto failed; |
| 3279 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3280 | goto failed; |
| 3281 | Py_DECREF(value); |
| 3282 | value = ast2obj_expr(o->v.BinOp.right); |
| 3283 | if (!value) goto failed; |
| 3284 | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
| 3285 | goto failed; |
| 3286 | Py_DECREF(value); |
| 3287 | break; |
| 3288 | case UnaryOp_kind: |
| 3289 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 3290 | if (!result) goto failed; |
| 3291 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 3292 | if (!value) goto failed; |
| 3293 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3294 | goto failed; |
| 3295 | Py_DECREF(value); |
| 3296 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 3297 | if (!value) goto failed; |
| 3298 | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
| 3299 | goto failed; |
| 3300 | Py_DECREF(value); |
| 3301 | break; |
| 3302 | case Lambda_kind: |
| 3303 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 3304 | if (!result) goto failed; |
| 3305 | value = ast2obj_arguments(o->v.Lambda.args); |
| 3306 | if (!value) goto failed; |
| 3307 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3308 | goto failed; |
| 3309 | Py_DECREF(value); |
| 3310 | value = ast2obj_expr(o->v.Lambda.body); |
| 3311 | if (!value) goto failed; |
| 3312 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3313 | goto failed; |
| 3314 | Py_DECREF(value); |
| 3315 | break; |
| 3316 | case IfExp_kind: |
| 3317 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 3318 | if (!result) goto failed; |
| 3319 | value = ast2obj_expr(o->v.IfExp.test); |
| 3320 | if (!value) goto failed; |
| 3321 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3322 | goto failed; |
| 3323 | Py_DECREF(value); |
| 3324 | value = ast2obj_expr(o->v.IfExp.body); |
| 3325 | if (!value) goto failed; |
| 3326 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3327 | goto failed; |
| 3328 | Py_DECREF(value); |
| 3329 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 3330 | if (!value) goto failed; |
| 3331 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3332 | goto failed; |
| 3333 | Py_DECREF(value); |
| 3334 | break; |
| 3335 | case Dict_kind: |
| 3336 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 3337 | if (!result) goto failed; |
| 3338 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 3339 | if (!value) goto failed; |
| 3340 | if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) |
| 3341 | goto failed; |
| 3342 | Py_DECREF(value); |
| 3343 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 3344 | if (!value) goto failed; |
| 3345 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3346 | goto failed; |
| 3347 | Py_DECREF(value); |
| 3348 | break; |
| 3349 | case Set_kind: |
| 3350 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 3351 | if (!result) goto failed; |
| 3352 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 3353 | if (!value) goto failed; |
| 3354 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3355 | goto failed; |
| 3356 | Py_DECREF(value); |
| 3357 | break; |
| 3358 | case ListComp_kind: |
| 3359 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 3360 | if (!result) goto failed; |
| 3361 | value = ast2obj_expr(o->v.ListComp.elt); |
| 3362 | if (!value) goto failed; |
| 3363 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3364 | goto failed; |
| 3365 | Py_DECREF(value); |
| 3366 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 3367 | if (!value) goto failed; |
| 3368 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3369 | goto failed; |
| 3370 | Py_DECREF(value); |
| 3371 | break; |
| 3372 | case SetComp_kind: |
| 3373 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 3374 | if (!result) goto failed; |
| 3375 | value = ast2obj_expr(o->v.SetComp.elt); |
| 3376 | if (!value) goto failed; |
| 3377 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3378 | goto failed; |
| 3379 | Py_DECREF(value); |
| 3380 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 3381 | if (!value) goto failed; |
| 3382 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3383 | goto failed; |
| 3384 | Py_DECREF(value); |
| 3385 | break; |
| 3386 | case DictComp_kind: |
| 3387 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 3388 | if (!result) goto failed; |
| 3389 | value = ast2obj_expr(o->v.DictComp.key); |
| 3390 | if (!value) goto failed; |
| 3391 | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
| 3392 | goto failed; |
| 3393 | Py_DECREF(value); |
| 3394 | value = ast2obj_expr(o->v.DictComp.value); |
| 3395 | if (!value) goto failed; |
| 3396 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3397 | goto failed; |
| 3398 | Py_DECREF(value); |
| 3399 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 3400 | if (!value) goto failed; |
| 3401 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3402 | goto failed; |
| 3403 | Py_DECREF(value); |
| 3404 | break; |
| 3405 | case GeneratorExp_kind: |
| 3406 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 3407 | if (!result) goto failed; |
| 3408 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 3409 | if (!value) goto failed; |
| 3410 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3411 | goto failed; |
| 3412 | Py_DECREF(value); |
| 3413 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 3414 | ast2obj_comprehension); |
| 3415 | if (!value) goto failed; |
| 3416 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3417 | goto failed; |
| 3418 | Py_DECREF(value); |
| 3419 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3420 | case Await_kind: |
| 3421 | result = PyType_GenericNew(Await_type, NULL, NULL); |
| 3422 | if (!result) goto failed; |
| 3423 | value = ast2obj_expr(o->v.Await.value); |
| 3424 | if (!value) goto failed; |
| 3425 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3426 | goto failed; |
| 3427 | Py_DECREF(value); |
| 3428 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3429 | case Yield_kind: |
| 3430 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 3431 | if (!result) goto failed; |
| 3432 | value = ast2obj_expr(o->v.Yield.value); |
| 3433 | if (!value) goto failed; |
| 3434 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3435 | goto failed; |
| 3436 | Py_DECREF(value); |
| 3437 | break; |
| 3438 | case YieldFrom_kind: |
| 3439 | result = PyType_GenericNew(YieldFrom_type, NULL, NULL); |
| 3440 | if (!result) goto failed; |
| 3441 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 3442 | if (!value) goto failed; |
| 3443 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3444 | goto failed; |
| 3445 | Py_DECREF(value); |
| 3446 | break; |
| 3447 | case Compare_kind: |
| 3448 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 3449 | if (!result) goto failed; |
| 3450 | value = ast2obj_expr(o->v.Compare.left); |
| 3451 | if (!value) goto failed; |
| 3452 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3453 | goto failed; |
| 3454 | Py_DECREF(value); |
| 3455 | { |
| 3456 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 3457 | value = PyList_New(n); |
| 3458 | if (!value) goto failed; |
| 3459 | for(i = 0; i < n; i++) |
| 3460 | 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] | 3461 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3462 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3463 | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
| 3464 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3465 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3466 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3467 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3468 | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
| 3469 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3470 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3471 | break; |
| 3472 | case Call_kind: |
| 3473 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 3474 | if (!result) goto failed; |
| 3475 | value = ast2obj_expr(o->v.Call.func); |
| 3476 | if (!value) goto failed; |
| 3477 | if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) |
| 3478 | goto failed; |
| 3479 | Py_DECREF(value); |
| 3480 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 3481 | if (!value) goto failed; |
| 3482 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3483 | goto failed; |
| 3484 | Py_DECREF(value); |
| 3485 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 3486 | if (!value) goto failed; |
| 3487 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 3488 | goto failed; |
| 3489 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3490 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3491 | case FormattedValue_kind: |
| 3492 | result = PyType_GenericNew(FormattedValue_type, NULL, NULL); |
| 3493 | if (!result) goto failed; |
| 3494 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 3495 | if (!value) goto failed; |
| 3496 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3497 | goto failed; |
| 3498 | Py_DECREF(value); |
| 3499 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 3500 | if (!value) goto failed; |
| 3501 | if (_PyObject_SetAttrId(result, &PyId_conversion, value) == -1) |
| 3502 | goto failed; |
| 3503 | Py_DECREF(value); |
| 3504 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 3505 | if (!value) goto failed; |
| 3506 | if (_PyObject_SetAttrId(result, &PyId_format_spec, value) == -1) |
| 3507 | goto failed; |
| 3508 | Py_DECREF(value); |
| 3509 | break; |
| 3510 | case JoinedStr_kind: |
| 3511 | result = PyType_GenericNew(JoinedStr_type, NULL, NULL); |
| 3512 | if (!result) goto failed; |
| 3513 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 3514 | if (!value) goto failed; |
| 3515 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3516 | goto failed; |
| 3517 | Py_DECREF(value); |
| 3518 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3519 | case Constant_kind: |
| 3520 | result = PyType_GenericNew(Constant_type, NULL, NULL); |
| 3521 | if (!result) goto failed; |
| 3522 | value = ast2obj_constant(o->v.Constant.value); |
| 3523 | if (!value) goto failed; |
| 3524 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3525 | goto failed; |
| 3526 | Py_DECREF(value); |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 3527 | value = ast2obj_string(o->v.Constant.kind); |
| 3528 | if (!value) goto failed; |
| 3529 | if (_PyObject_SetAttrId(result, &PyId_kind, value) == -1) |
| 3530 | goto failed; |
| 3531 | Py_DECREF(value); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3532 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3533 | case Attribute_kind: |
| 3534 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 3535 | if (!result) goto failed; |
| 3536 | value = ast2obj_expr(o->v.Attribute.value); |
| 3537 | if (!value) goto failed; |
| 3538 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3539 | goto failed; |
| 3540 | Py_DECREF(value); |
| 3541 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 3542 | if (!value) goto failed; |
| 3543 | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
| 3544 | goto failed; |
| 3545 | Py_DECREF(value); |
| 3546 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 3547 | if (!value) goto failed; |
| 3548 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3549 | goto failed; |
| 3550 | Py_DECREF(value); |
| 3551 | break; |
| 3552 | case Subscript_kind: |
| 3553 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 3554 | if (!result) goto failed; |
| 3555 | value = ast2obj_expr(o->v.Subscript.value); |
| 3556 | if (!value) goto failed; |
| 3557 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3558 | goto failed; |
| 3559 | Py_DECREF(value); |
| 3560 | value = ast2obj_slice(o->v.Subscript.slice); |
| 3561 | if (!value) goto failed; |
| 3562 | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
| 3563 | goto failed; |
| 3564 | Py_DECREF(value); |
| 3565 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 3566 | if (!value) goto failed; |
| 3567 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3568 | goto failed; |
| 3569 | Py_DECREF(value); |
| 3570 | break; |
| 3571 | case Starred_kind: |
| 3572 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 3573 | if (!result) goto failed; |
| 3574 | value = ast2obj_expr(o->v.Starred.value); |
| 3575 | if (!value) goto failed; |
| 3576 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3577 | goto failed; |
| 3578 | Py_DECREF(value); |
| 3579 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 3580 | if (!value) goto failed; |
| 3581 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3582 | goto failed; |
| 3583 | Py_DECREF(value); |
| 3584 | break; |
| 3585 | case Name_kind: |
| 3586 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 3587 | if (!result) goto failed; |
| 3588 | value = ast2obj_identifier(o->v.Name.id); |
| 3589 | if (!value) goto failed; |
| 3590 | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
| 3591 | goto failed; |
| 3592 | Py_DECREF(value); |
| 3593 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 3594 | if (!value) goto failed; |
| 3595 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3596 | goto failed; |
| 3597 | Py_DECREF(value); |
| 3598 | break; |
| 3599 | case List_kind: |
| 3600 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 3601 | if (!result) goto failed; |
| 3602 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 3603 | if (!value) goto failed; |
| 3604 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3605 | goto failed; |
| 3606 | Py_DECREF(value); |
| 3607 | value = ast2obj_expr_context(o->v.List.ctx); |
| 3608 | if (!value) goto failed; |
| 3609 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3610 | goto failed; |
| 3611 | Py_DECREF(value); |
| 3612 | break; |
| 3613 | case Tuple_kind: |
| 3614 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 3615 | if (!result) goto failed; |
| 3616 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 3617 | if (!value) goto failed; |
| 3618 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3619 | goto failed; |
| 3620 | Py_DECREF(value); |
| 3621 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 3622 | if (!value) goto failed; |
| 3623 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3624 | goto failed; |
| 3625 | Py_DECREF(value); |
| 3626 | break; |
| 3627 | } |
| 3628 | value = ast2obj_int(o->lineno); |
| 3629 | if (!value) goto failed; |
| 3630 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3631 | goto failed; |
| 3632 | Py_DECREF(value); |
| 3633 | value = ast2obj_int(o->col_offset); |
| 3634 | if (!value) goto failed; |
| 3635 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3636 | goto failed; |
| 3637 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3638 | value = ast2obj_int(o->end_lineno); |
| 3639 | if (!value) goto failed; |
| 3640 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3641 | goto failed; |
| 3642 | Py_DECREF(value); |
| 3643 | value = ast2obj_int(o->end_col_offset); |
| 3644 | if (!value) goto failed; |
| 3645 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3646 | goto failed; |
| 3647 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3648 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3649 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3650 | Py_XDECREF(value); |
| 3651 | Py_XDECREF(result); |
| 3652 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3653 | } |
| 3654 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3655 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3656 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3657 | switch(o) { |
| 3658 | case Load: |
| 3659 | Py_INCREF(Load_singleton); |
| 3660 | return Load_singleton; |
| 3661 | case Store: |
| 3662 | Py_INCREF(Store_singleton); |
| 3663 | return Store_singleton; |
| 3664 | case Del: |
| 3665 | Py_INCREF(Del_singleton); |
| 3666 | return Del_singleton; |
| 3667 | case AugLoad: |
| 3668 | Py_INCREF(AugLoad_singleton); |
| 3669 | return AugLoad_singleton; |
| 3670 | case AugStore: |
| 3671 | Py_INCREF(AugStore_singleton); |
| 3672 | return AugStore_singleton; |
| 3673 | case Param: |
| 3674 | Py_INCREF(Param_singleton); |
| 3675 | return Param_singleton; |
| 3676 | default: |
| 3677 | /* should never happen, but just in case ... */ |
| 3678 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 3679 | return NULL; |
| 3680 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3681 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3682 | PyObject* |
| 3683 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3684 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3685 | slice_ty o = (slice_ty)_o; |
| 3686 | PyObject *result = NULL, *value = NULL; |
| 3687 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3688 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3689 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3690 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3691 | switch (o->kind) { |
| 3692 | case Slice_kind: |
| 3693 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 3694 | if (!result) goto failed; |
| 3695 | value = ast2obj_expr(o->v.Slice.lower); |
| 3696 | if (!value) goto failed; |
| 3697 | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
| 3698 | goto failed; |
| 3699 | Py_DECREF(value); |
| 3700 | value = ast2obj_expr(o->v.Slice.upper); |
| 3701 | if (!value) goto failed; |
| 3702 | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
| 3703 | goto failed; |
| 3704 | Py_DECREF(value); |
| 3705 | value = ast2obj_expr(o->v.Slice.step); |
| 3706 | if (!value) goto failed; |
| 3707 | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
| 3708 | goto failed; |
| 3709 | Py_DECREF(value); |
| 3710 | break; |
| 3711 | case ExtSlice_kind: |
| 3712 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3713 | if (!result) goto failed; |
| 3714 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3715 | if (!value) goto failed; |
| 3716 | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
| 3717 | goto failed; |
| 3718 | Py_DECREF(value); |
| 3719 | break; |
| 3720 | case Index_kind: |
| 3721 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3722 | if (!result) goto failed; |
| 3723 | value = ast2obj_expr(o->v.Index.value); |
| 3724 | if (!value) goto failed; |
| 3725 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3726 | goto failed; |
| 3727 | Py_DECREF(value); |
| 3728 | break; |
| 3729 | } |
| 3730 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3731 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3732 | Py_XDECREF(value); |
| 3733 | Py_XDECREF(result); |
| 3734 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3735 | } |
| 3736 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3737 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3738 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3739 | switch(o) { |
| 3740 | case And: |
| 3741 | Py_INCREF(And_singleton); |
| 3742 | return And_singleton; |
| 3743 | case Or: |
| 3744 | Py_INCREF(Or_singleton); |
| 3745 | return Or_singleton; |
| 3746 | default: |
| 3747 | /* should never happen, but just in case ... */ |
| 3748 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3749 | return NULL; |
| 3750 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3751 | } |
| 3752 | PyObject* ast2obj_operator(operator_ty o) |
| 3753 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3754 | switch(o) { |
| 3755 | case Add: |
| 3756 | Py_INCREF(Add_singleton); |
| 3757 | return Add_singleton; |
| 3758 | case Sub: |
| 3759 | Py_INCREF(Sub_singleton); |
| 3760 | return Sub_singleton; |
| 3761 | case Mult: |
| 3762 | Py_INCREF(Mult_singleton); |
| 3763 | return Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 3764 | case MatMult: |
| 3765 | Py_INCREF(MatMult_singleton); |
| 3766 | return MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3767 | case Div: |
| 3768 | Py_INCREF(Div_singleton); |
| 3769 | return Div_singleton; |
| 3770 | case Mod: |
| 3771 | Py_INCREF(Mod_singleton); |
| 3772 | return Mod_singleton; |
| 3773 | case Pow: |
| 3774 | Py_INCREF(Pow_singleton); |
| 3775 | return Pow_singleton; |
| 3776 | case LShift: |
| 3777 | Py_INCREF(LShift_singleton); |
| 3778 | return LShift_singleton; |
| 3779 | case RShift: |
| 3780 | Py_INCREF(RShift_singleton); |
| 3781 | return RShift_singleton; |
| 3782 | case BitOr: |
| 3783 | Py_INCREF(BitOr_singleton); |
| 3784 | return BitOr_singleton; |
| 3785 | case BitXor: |
| 3786 | Py_INCREF(BitXor_singleton); |
| 3787 | return BitXor_singleton; |
| 3788 | case BitAnd: |
| 3789 | Py_INCREF(BitAnd_singleton); |
| 3790 | return BitAnd_singleton; |
| 3791 | case FloorDiv: |
| 3792 | Py_INCREF(FloorDiv_singleton); |
| 3793 | return FloorDiv_singleton; |
| 3794 | default: |
| 3795 | /* should never happen, but just in case ... */ |
| 3796 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3797 | return NULL; |
| 3798 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3799 | } |
| 3800 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3801 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3802 | switch(o) { |
| 3803 | case Invert: |
| 3804 | Py_INCREF(Invert_singleton); |
| 3805 | return Invert_singleton; |
| 3806 | case Not: |
| 3807 | Py_INCREF(Not_singleton); |
| 3808 | return Not_singleton; |
| 3809 | case UAdd: |
| 3810 | Py_INCREF(UAdd_singleton); |
| 3811 | return UAdd_singleton; |
| 3812 | case USub: |
| 3813 | Py_INCREF(USub_singleton); |
| 3814 | return USub_singleton; |
| 3815 | default: |
| 3816 | /* should never happen, but just in case ... */ |
| 3817 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3818 | return NULL; |
| 3819 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3820 | } |
| 3821 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3822 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3823 | switch(o) { |
| 3824 | case Eq: |
| 3825 | Py_INCREF(Eq_singleton); |
| 3826 | return Eq_singleton; |
| 3827 | case NotEq: |
| 3828 | Py_INCREF(NotEq_singleton); |
| 3829 | return NotEq_singleton; |
| 3830 | case Lt: |
| 3831 | Py_INCREF(Lt_singleton); |
| 3832 | return Lt_singleton; |
| 3833 | case LtE: |
| 3834 | Py_INCREF(LtE_singleton); |
| 3835 | return LtE_singleton; |
| 3836 | case Gt: |
| 3837 | Py_INCREF(Gt_singleton); |
| 3838 | return Gt_singleton; |
| 3839 | case GtE: |
| 3840 | Py_INCREF(GtE_singleton); |
| 3841 | return GtE_singleton; |
| 3842 | case Is: |
| 3843 | Py_INCREF(Is_singleton); |
| 3844 | return Is_singleton; |
| 3845 | case IsNot: |
| 3846 | Py_INCREF(IsNot_singleton); |
| 3847 | return IsNot_singleton; |
| 3848 | case In: |
| 3849 | Py_INCREF(In_singleton); |
| 3850 | return In_singleton; |
| 3851 | case NotIn: |
| 3852 | Py_INCREF(NotIn_singleton); |
| 3853 | return NotIn_singleton; |
| 3854 | default: |
| 3855 | /* should never happen, but just in case ... */ |
| 3856 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3857 | return NULL; |
| 3858 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3859 | } |
| 3860 | PyObject* |
| 3861 | ast2obj_comprehension(void* _o) |
| 3862 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3863 | comprehension_ty o = (comprehension_ty)_o; |
| 3864 | PyObject *result = NULL, *value = NULL; |
| 3865 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3866 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3867 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3868 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3869 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3870 | if (!result) return NULL; |
| 3871 | value = ast2obj_expr(o->target); |
| 3872 | if (!value) goto failed; |
| 3873 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 3874 | goto failed; |
| 3875 | Py_DECREF(value); |
| 3876 | value = ast2obj_expr(o->iter); |
| 3877 | if (!value) goto failed; |
| 3878 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 3879 | goto failed; |
| 3880 | Py_DECREF(value); |
| 3881 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3882 | if (!value) goto failed; |
| 3883 | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
| 3884 | goto failed; |
| 3885 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3886 | value = ast2obj_int(o->is_async); |
| 3887 | if (!value) goto failed; |
| 3888 | if (_PyObject_SetAttrId(result, &PyId_is_async, value) == -1) |
| 3889 | goto failed; |
| 3890 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3891 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3892 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3893 | Py_XDECREF(value); |
| 3894 | Py_XDECREF(result); |
| 3895 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3896 | } |
| 3897 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3898 | PyObject* |
| 3899 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3900 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3901 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3902 | PyObject *result = NULL, *value = NULL; |
| 3903 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3904 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3905 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3906 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3907 | switch (o->kind) { |
| 3908 | case ExceptHandler_kind: |
| 3909 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3910 | if (!result) goto failed; |
| 3911 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3912 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3913 | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
| 3914 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3915 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3916 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3917 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3918 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3919 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3920 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3921 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3922 | if (!value) goto failed; |
| 3923 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3924 | goto failed; |
| 3925 | Py_DECREF(value); |
| 3926 | break; |
| 3927 | } |
| 3928 | value = ast2obj_int(o->lineno); |
| 3929 | if (!value) goto failed; |
| 3930 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3931 | goto failed; |
| 3932 | Py_DECREF(value); |
| 3933 | value = ast2obj_int(o->col_offset); |
| 3934 | if (!value) goto failed; |
| 3935 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3936 | goto failed; |
| 3937 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3938 | value = ast2obj_int(o->end_lineno); |
| 3939 | if (!value) goto failed; |
| 3940 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 3941 | goto failed; |
| 3942 | Py_DECREF(value); |
| 3943 | value = ast2obj_int(o->end_col_offset); |
| 3944 | if (!value) goto failed; |
| 3945 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 3946 | goto failed; |
| 3947 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3948 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3949 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3950 | Py_XDECREF(value); |
| 3951 | Py_XDECREF(result); |
| 3952 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3953 | } |
| 3954 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3955 | PyObject* |
| 3956 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3957 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3958 | arguments_ty o = (arguments_ty)_o; |
| 3959 | PyObject *result = NULL, *value = NULL; |
| 3960 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3961 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3962 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3963 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3964 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3965 | if (!result) return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3966 | value = ast2obj_list(o->posonlyargs, ast2obj_arg); |
| 3967 | if (!value) goto failed; |
| 3968 | if (_PyObject_SetAttrId(result, &PyId_posonlyargs, value) == -1) |
| 3969 | goto failed; |
| 3970 | Py_DECREF(value); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3971 | value = ast2obj_list(o->args, ast2obj_arg); |
| 3972 | if (!value) goto failed; |
| 3973 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3974 | goto failed; |
| 3975 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3976 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3977 | if (!value) goto failed; |
| 3978 | if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) |
| 3979 | goto failed; |
| 3980 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3981 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 3982 | if (!value) goto failed; |
| 3983 | if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) |
| 3984 | goto failed; |
| 3985 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3986 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3987 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3988 | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3989 | goto failed; |
| 3990 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3991 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3992 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3993 | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3994 | goto failed; |
| 3995 | Py_DECREF(value); |
| 3996 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3997 | if (!value) goto failed; |
| 3998 | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
| 3999 | goto failed; |
| 4000 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4001 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4002 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4003 | Py_XDECREF(value); |
| 4004 | Py_XDECREF(result); |
| 4005 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4006 | } |
| 4007 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4008 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4009 | ast2obj_arg(void* _o) |
| 4010 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4011 | arg_ty o = (arg_ty)_o; |
| 4012 | PyObject *result = NULL, *value = NULL; |
| 4013 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4014 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4015 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4016 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4017 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 4018 | if (!result) return NULL; |
| 4019 | value = ast2obj_identifier(o->arg); |
| 4020 | if (!value) goto failed; |
| 4021 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 4022 | goto failed; |
| 4023 | Py_DECREF(value); |
| 4024 | value = ast2obj_expr(o->annotation); |
| 4025 | if (!value) goto failed; |
| 4026 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 4027 | goto failed; |
| 4028 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4029 | value = ast2obj_string(o->type_comment); |
| 4030 | if (!value) goto failed; |
| 4031 | if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1) |
| 4032 | goto failed; |
| 4033 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4034 | value = ast2obj_int(o->lineno); |
| 4035 | if (!value) goto failed; |
| 4036 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 4037 | goto failed; |
| 4038 | Py_DECREF(value); |
| 4039 | value = ast2obj_int(o->col_offset); |
| 4040 | if (!value) goto failed; |
| 4041 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 4042 | goto failed; |
| 4043 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4044 | value = ast2obj_int(o->end_lineno); |
| 4045 | if (!value) goto failed; |
| 4046 | if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0) |
| 4047 | goto failed; |
| 4048 | Py_DECREF(value); |
| 4049 | value = ast2obj_int(o->end_col_offset); |
| 4050 | if (!value) goto failed; |
| 4051 | if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0) |
| 4052 | goto failed; |
| 4053 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4054 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4055 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4056 | Py_XDECREF(value); |
| 4057 | Py_XDECREF(result); |
| 4058 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4062 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4063 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4064 | keyword_ty o = (keyword_ty)_o; |
| 4065 | PyObject *result = NULL, *value = NULL; |
| 4066 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4067 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4068 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4069 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4070 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 4071 | if (!result) return NULL; |
| 4072 | value = ast2obj_identifier(o->arg); |
| 4073 | if (!value) goto failed; |
| 4074 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 4075 | goto failed; |
| 4076 | Py_DECREF(value); |
| 4077 | value = ast2obj_expr(o->value); |
| 4078 | if (!value) goto failed; |
| 4079 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 4080 | goto failed; |
| 4081 | Py_DECREF(value); |
| 4082 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4083 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4084 | Py_XDECREF(value); |
| 4085 | Py_XDECREF(result); |
| 4086 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4087 | } |
| 4088 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4089 | PyObject* |
| 4090 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4091 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4092 | alias_ty o = (alias_ty)_o; |
| 4093 | PyObject *result = NULL, *value = NULL; |
| 4094 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4095 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4096 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4097 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4098 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 4099 | if (!result) return NULL; |
| 4100 | value = ast2obj_identifier(o->name); |
| 4101 | if (!value) goto failed; |
| 4102 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 4103 | goto failed; |
| 4104 | Py_DECREF(value); |
| 4105 | value = ast2obj_identifier(o->asname); |
| 4106 | if (!value) goto failed; |
| 4107 | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
| 4108 | goto failed; |
| 4109 | Py_DECREF(value); |
| 4110 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4111 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4112 | Py_XDECREF(value); |
| 4113 | Py_XDECREF(result); |
| 4114 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4115 | } |
| 4116 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4117 | PyObject* |
| 4118 | ast2obj_withitem(void* _o) |
| 4119 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4120 | withitem_ty o = (withitem_ty)_o; |
| 4121 | PyObject *result = NULL, *value = NULL; |
| 4122 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4123 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4124 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4125 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4126 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 4127 | if (!result) return NULL; |
| 4128 | value = ast2obj_expr(o->context_expr); |
| 4129 | if (!value) goto failed; |
| 4130 | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
| 4131 | goto failed; |
| 4132 | Py_DECREF(value); |
| 4133 | value = ast2obj_expr(o->optional_vars); |
| 4134 | if (!value) goto failed; |
| 4135 | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
| 4136 | goto failed; |
| 4137 | Py_DECREF(value); |
| 4138 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4139 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4140 | Py_XDECREF(value); |
| 4141 | Py_XDECREF(result); |
| 4142 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4143 | } |
| 4144 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4145 | PyObject* |
| 4146 | ast2obj_type_ignore(void* _o) |
| 4147 | { |
| 4148 | type_ignore_ty o = (type_ignore_ty)_o; |
| 4149 | PyObject *result = NULL, *value = NULL; |
| 4150 | if (!o) { |
| 4151 | Py_RETURN_NONE; |
| 4152 | } |
| 4153 | |
| 4154 | switch (o->kind) { |
| 4155 | case TypeIgnore_kind: |
| 4156 | result = PyType_GenericNew(TypeIgnore_type, NULL, NULL); |
| 4157 | if (!result) goto failed; |
| 4158 | value = ast2obj_int(o->v.TypeIgnore.lineno); |
| 4159 | if (!value) goto failed; |
| 4160 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) == -1) |
| 4161 | goto failed; |
| 4162 | Py_DECREF(value); |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 4163 | value = ast2obj_string(o->v.TypeIgnore.tag); |
| 4164 | if (!value) goto failed; |
| 4165 | if (_PyObject_SetAttrId(result, &PyId_tag, value) == -1) |
| 4166 | goto failed; |
| 4167 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4168 | break; |
| 4169 | } |
| 4170 | return result; |
| 4171 | failed: |
| 4172 | Py_XDECREF(value); |
| 4173 | Py_XDECREF(result); |
| 4174 | return NULL; |
| 4175 | } |
| 4176 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4177 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4178 | int |
| 4179 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 4180 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4181 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4182 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4183 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4184 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4185 | if (obj == Py_None) { |
| 4186 | *out = NULL; |
| 4187 | return 0; |
| 4188 | } |
| 4189 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 4190 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4191 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4192 | } |
| 4193 | if (isinstance) { |
| 4194 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4195 | asdl_seq* type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4196 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4197 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4198 | return 1; |
| 4199 | } |
| 4200 | if (tmp == NULL) { |
| 4201 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 4202 | return 1; |
| 4203 | } |
| 4204 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4205 | int res; |
| 4206 | Py_ssize_t len; |
| 4207 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4208 | if (!PyList_Check(tmp)) { |
| 4209 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4210 | goto failed; |
| 4211 | } |
| 4212 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4213 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4214 | if (body == NULL) goto failed; |
| 4215 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4216 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 4217 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 4218 | Py_INCREF(tmp2); |
| 4219 | res = obj2ast_stmt(tmp2, &val, arena); |
| 4220 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4221 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4222 | if (len != PyList_GET_SIZE(tmp)) { |
| 4223 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 4224 | goto failed; |
| 4225 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4226 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4227 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4228 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4229 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4230 | if (_PyObject_LookupAttrId(obj, &PyId_type_ignores, &tmp) < 0) { |
| 4231 | return 1; |
| 4232 | } |
| 4233 | if (tmp == NULL) { |
| 4234 | PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module"); |
| 4235 | return 1; |
| 4236 | } |
| 4237 | else { |
| 4238 | int res; |
| 4239 | Py_ssize_t len; |
| 4240 | Py_ssize_t i; |
| 4241 | if (!PyList_Check(tmp)) { |
| 4242 | PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4243 | goto failed; |
| 4244 | } |
| 4245 | len = PyList_GET_SIZE(tmp); |
| 4246 | type_ignores = _Py_asdl_seq_new(len, arena); |
| 4247 | if (type_ignores == NULL) goto failed; |
| 4248 | for (i = 0; i < len; i++) { |
| 4249 | type_ignore_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 4250 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 4251 | Py_INCREF(tmp2); |
| 4252 | res = obj2ast_type_ignore(tmp2, &val, arena); |
| 4253 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 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; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 4294 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 4295 | Py_INCREF(tmp2); |
| 4296 | res = obj2ast_stmt(tmp2, &val, arena); |
| 4297 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4298 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4299 | if (len != PyList_GET_SIZE(tmp)) { |
| 4300 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 4301 | goto failed; |
| 4302 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4303 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4304 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4305 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4306 | } |
| 4307 | *out = Interactive(body, arena); |
| 4308 | if (*out == NULL) goto failed; |
| 4309 | return 0; |
| 4310 | } |
| 4311 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 4312 | if (isinstance == -1) { |
| 4313 | return 1; |
| 4314 | } |
| 4315 | if (isinstance) { |
| 4316 | expr_ty body; |
| 4317 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4318 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4319 | return 1; |
| 4320 | } |
| 4321 | if (tmp == NULL) { |
| 4322 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 4323 | return 1; |
| 4324 | } |
| 4325 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4326 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4327 | res = obj2ast_expr(tmp, &body, arena); |
| 4328 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4329 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4330 | } |
| 4331 | *out = Expression(body, arena); |
| 4332 | if (*out == NULL) goto failed; |
| 4333 | return 0; |
| 4334 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4335 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionType_type); |
| 4336 | if (isinstance == -1) { |
| 4337 | return 1; |
| 4338 | } |
| 4339 | if (isinstance) { |
| 4340 | asdl_seq* argtypes; |
| 4341 | expr_ty returns; |
| 4342 | |
| 4343 | if (_PyObject_LookupAttrId(obj, &PyId_argtypes, &tmp) < 0) { |
| 4344 | return 1; |
| 4345 | } |
| 4346 | if (tmp == NULL) { |
| 4347 | PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType"); |
| 4348 | return 1; |
| 4349 | } |
| 4350 | else { |
| 4351 | int res; |
| 4352 | Py_ssize_t len; |
| 4353 | Py_ssize_t i; |
| 4354 | if (!PyList_Check(tmp)) { |
| 4355 | PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4356 | goto failed; |
| 4357 | } |
| 4358 | len = PyList_GET_SIZE(tmp); |
| 4359 | argtypes = _Py_asdl_seq_new(len, arena); |
| 4360 | if (argtypes == NULL) goto failed; |
| 4361 | for (i = 0; i < len; i++) { |
| 4362 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 4363 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 4364 | Py_INCREF(tmp2); |
| 4365 | res = obj2ast_expr(tmp2, &val, arena); |
| 4366 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4367 | if (res != 0) goto failed; |
| 4368 | if (len != PyList_GET_SIZE(tmp)) { |
| 4369 | PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration"); |
| 4370 | goto failed; |
| 4371 | } |
| 4372 | asdl_seq_SET(argtypes, i, val); |
| 4373 | } |
| 4374 | Py_CLEAR(tmp); |
| 4375 | } |
| 4376 | if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) { |
| 4377 | return 1; |
| 4378 | } |
| 4379 | if (tmp == NULL) { |
| 4380 | PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType"); |
| 4381 | return 1; |
| 4382 | } |
| 4383 | else { |
| 4384 | int res; |
| 4385 | res = obj2ast_expr(tmp, &returns, arena); |
| 4386 | if (res != 0) goto failed; |
| 4387 | Py_CLEAR(tmp); |
| 4388 | } |
| 4389 | *out = FunctionType(argtypes, returns, arena); |
| 4390 | if (*out == NULL) goto failed; |
| 4391 | return 0; |
| 4392 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4393 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 4394 | if (isinstance == -1) { |
| 4395 | return 1; |
| 4396 | } |
| 4397 | if (isinstance) { |
| 4398 | asdl_seq* body; |
| 4399 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4400 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 4401 | return 1; |
| 4402 | } |
| 4403 | if (tmp == NULL) { |
| 4404 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 4405 | return 1; |
| 4406 | } |
| 4407 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4408 | int res; |
| 4409 | Py_ssize_t len; |
| 4410 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4411 | if (!PyList_Check(tmp)) { |
| 4412 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4413 | goto failed; |
| 4414 | } |
| 4415 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4416 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4417 | if (body == NULL) goto failed; |
| 4418 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4419 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 4420 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 4421 | Py_INCREF(tmp2); |
| 4422 | res = obj2ast_stmt(tmp2, &val, arena); |
| 4423 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4424 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4425 | if (len != PyList_GET_SIZE(tmp)) { |
| 4426 | PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration"); |
| 4427 | goto failed; |
| 4428 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4429 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4430 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4431 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4432 | } |
| 4433 | *out = Suite(body, arena); |
| 4434 | if (*out == NULL) goto failed; |
| 4435 | return 0; |
| 4436 | } |
| 4437 | |
| 4438 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 4439 | failed: |
| 4440 | Py_XDECREF(tmp); |
| 4441 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4442 | } |
| 4443 | |
| 4444 | int |
| 4445 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 4446 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4447 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4448 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4449 | PyObject *tmp = NULL; |
| 4450 | int lineno; |
| 4451 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4452 | int end_lineno; |
| 4453 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4454 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4455 | if (obj == Py_None) { |
| 4456 | *out = NULL; |
| 4457 | return 0; |
| 4458 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4459 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 4460 | return 1; |
| 4461 | } |
| 4462 | if (tmp == NULL) { |
| 4463 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 4464 | return 1; |
| 4465 | } |
| 4466 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4467 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4468 | res = obj2ast_int(tmp, &lineno, arena); |
| 4469 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4470 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4471 | } |
| 4472 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4473 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4474 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4475 | if (tmp == NULL) { |
| 4476 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 4477 | return 1; |
| 4478 | } |
| 4479 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4480 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4481 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4482 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4483 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4484 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4485 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 4486 | return 1; |
| 4487 | } |
| 4488 | if (tmp == NULL || tmp == Py_None) { |
| 4489 | Py_CLEAR(tmp); |
| 4490 | end_lineno = 0; |
| 4491 | } |
| 4492 | else { |
| 4493 | int res; |
| 4494 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 4495 | if (res != 0) goto failed; |
| 4496 | Py_CLEAR(tmp); |
| 4497 | } |
| 4498 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 4499 | return 1; |
| 4500 | } |
| 4501 | if (tmp == NULL || tmp == Py_None) { |
| 4502 | Py_CLEAR(tmp); |
| 4503 | end_col_offset = 0; |
| 4504 | } |
| 4505 | else { |
| 4506 | int res; |
| 4507 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 4508 | if (res != 0) goto failed; |
| 4509 | Py_CLEAR(tmp); |
| 4510 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4511 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 4512 | if (isinstance == -1) { |
| 4513 | return 1; |
| 4514 | } |
| 4515 | if (isinstance) { |
| 4516 | identifier name; |
| 4517 | arguments_ty args; |
| 4518 | asdl_seq* body; |
| 4519 | asdl_seq* decorator_list; |
| 4520 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4521 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4522 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4523 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4524 | return 1; |
| 4525 | } |
| 4526 | if (tmp == NULL) { |
| 4527 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 4528 | return 1; |
| 4529 | } |
| 4530 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4531 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4532 | res = obj2ast_identifier(tmp, &name, arena); |
| 4533 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4534 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4535 | } |
| 4536 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4537 | return 1; |
| 4538 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4539 | if (tmp == NULL) { |
| 4540 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 4541 | return 1; |
| 4542 | } |
| 4543 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4544 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4545 | res = obj2ast_arguments(tmp, &args, arena); |
| 4546 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4547 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4548 | } |
| 4549 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4550 | return 1; |
| 4551 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4552 | if (tmp == NULL) { |
| 4553 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 4554 | return 1; |
| 4555 | } |
| 4556 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4557 | int res; |
| 4558 | Py_ssize_t len; |
| 4559 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4560 | if (!PyList_Check(tmp)) { |
| 4561 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4562 | goto failed; |
| 4563 | } |
| 4564 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4565 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4566 | if (body == NULL) goto failed; |
| 4567 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4568 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 4569 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 4570 | Py_INCREF(tmp2); |
| 4571 | res = obj2ast_stmt(tmp2, &val, arena); |
| 4572 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4573 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4574 | if (len != PyList_GET_SIZE(tmp)) { |
| 4575 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 4576 | goto failed; |
| 4577 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4578 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4579 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4580 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4581 | } |
| 4582 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4583 | return 1; |
| 4584 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4585 | if (tmp == NULL) { |
| 4586 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 4587 | return 1; |
| 4588 | } |
| 4589 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4590 | int res; |
| 4591 | Py_ssize_t len; |
| 4592 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4593 | if (!PyList_Check(tmp)) { |
| 4594 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4595 | goto failed; |
| 4596 | } |
| 4597 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4598 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4599 | if (decorator_list == NULL) goto failed; |
| 4600 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4601 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 4602 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 4603 | Py_INCREF(tmp2); |
| 4604 | res = obj2ast_expr(tmp2, &val, arena); |
| 4605 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4606 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4607 | if (len != PyList_GET_SIZE(tmp)) { |
| 4608 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 4609 | goto failed; |
| 4610 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4611 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4612 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4613 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4614 | } |
| 4615 | if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4616 | return 1; |
| 4617 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4618 | if (tmp == NULL || tmp == Py_None) { |
| 4619 | Py_CLEAR(tmp); |
| 4620 | returns = NULL; |
| 4621 | } |
| 4622 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4623 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4624 | res = obj2ast_expr(tmp, &returns, arena); |
| 4625 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4626 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4627 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4628 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 4629 | return 1; |
| 4630 | } |
| 4631 | if (tmp == NULL || tmp == Py_None) { |
| 4632 | Py_CLEAR(tmp); |
| 4633 | type_comment = NULL; |
| 4634 | } |
| 4635 | else { |
| 4636 | int res; |
| 4637 | res = obj2ast_string(tmp, &type_comment, arena); |
| 4638 | if (res != 0) goto failed; |
| 4639 | Py_CLEAR(tmp); |
| 4640 | } |
| 4641 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 4642 | type_comment, lineno, col_offset, end_lineno, |
| 4643 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4644 | if (*out == NULL) goto failed; |
| 4645 | return 0; |
| 4646 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4647 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFunctionDef_type); |
| 4648 | if (isinstance == -1) { |
| 4649 | return 1; |
| 4650 | } |
| 4651 | if (isinstance) { |
| 4652 | identifier name; |
| 4653 | arguments_ty args; |
| 4654 | asdl_seq* body; |
| 4655 | asdl_seq* decorator_list; |
| 4656 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4657 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4658 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4659 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4660 | return 1; |
| 4661 | } |
| 4662 | if (tmp == NULL) { |
| 4663 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 4664 | return 1; |
| 4665 | } |
| 4666 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4667 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4668 | res = obj2ast_identifier(tmp, &name, arena); |
| 4669 | if (res != 0) goto failed; |
| 4670 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4671 | } |
| 4672 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4673 | return 1; |
| 4674 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4675 | if (tmp == NULL) { |
| 4676 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 4677 | return 1; |
| 4678 | } |
| 4679 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4680 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4681 | res = obj2ast_arguments(tmp, &args, arena); |
| 4682 | if (res != 0) goto failed; |
| 4683 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4684 | } |
| 4685 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4686 | return 1; |
| 4687 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4688 | if (tmp == NULL) { |
| 4689 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 4690 | return 1; |
| 4691 | } |
| 4692 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4693 | int res; |
| 4694 | Py_ssize_t len; |
| 4695 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4696 | if (!PyList_Check(tmp)) { |
| 4697 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4698 | goto failed; |
| 4699 | } |
| 4700 | len = PyList_GET_SIZE(tmp); |
| 4701 | body = _Py_asdl_seq_new(len, arena); |
| 4702 | if (body == NULL) goto failed; |
| 4703 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4704 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 4705 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 4706 | Py_INCREF(tmp2); |
| 4707 | res = obj2ast_stmt(tmp2, &val, arena); |
| 4708 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4709 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4710 | if (len != PyList_GET_SIZE(tmp)) { |
| 4711 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 4712 | goto failed; |
| 4713 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4714 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4715 | } |
| 4716 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4717 | } |
| 4718 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4719 | return 1; |
| 4720 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4721 | if (tmp == NULL) { |
| 4722 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 4723 | return 1; |
| 4724 | } |
| 4725 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4726 | int res; |
| 4727 | Py_ssize_t len; |
| 4728 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4729 | if (!PyList_Check(tmp)) { |
| 4730 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4731 | goto failed; |
| 4732 | } |
| 4733 | len = PyList_GET_SIZE(tmp); |
| 4734 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 4735 | if (decorator_list == NULL) goto failed; |
| 4736 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4737 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 4738 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 4739 | Py_INCREF(tmp2); |
| 4740 | res = obj2ast_expr(tmp2, &val, arena); |
| 4741 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4742 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4743 | if (len != PyList_GET_SIZE(tmp)) { |
| 4744 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 4745 | goto failed; |
| 4746 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4747 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4748 | } |
| 4749 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4750 | } |
| 4751 | if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4752 | return 1; |
| 4753 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4754 | if (tmp == NULL || tmp == Py_None) { |
| 4755 | Py_CLEAR(tmp); |
| 4756 | returns = NULL; |
| 4757 | } |
| 4758 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4759 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4760 | res = obj2ast_expr(tmp, &returns, arena); |
| 4761 | if (res != 0) goto failed; |
| 4762 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4763 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4764 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 4765 | return 1; |
| 4766 | } |
| 4767 | if (tmp == NULL || tmp == Py_None) { |
| 4768 | Py_CLEAR(tmp); |
| 4769 | type_comment = NULL; |
| 4770 | } |
| 4771 | else { |
| 4772 | int res; |
| 4773 | res = obj2ast_string(tmp, &type_comment, arena); |
| 4774 | if (res != 0) goto failed; |
| 4775 | Py_CLEAR(tmp); |
| 4776 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4777 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4778 | type_comment, lineno, col_offset, end_lineno, |
| 4779 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4780 | if (*out == NULL) goto failed; |
| 4781 | return 0; |
| 4782 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4783 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 4784 | if (isinstance == -1) { |
| 4785 | return 1; |
| 4786 | } |
| 4787 | if (isinstance) { |
| 4788 | identifier name; |
| 4789 | asdl_seq* bases; |
| 4790 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4791 | asdl_seq* body; |
| 4792 | asdl_seq* decorator_list; |
| 4793 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4794 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 4795 | return 1; |
| 4796 | } |
| 4797 | if (tmp == NULL) { |
| 4798 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 4799 | return 1; |
| 4800 | } |
| 4801 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4802 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4803 | res = obj2ast_identifier(tmp, &name, arena); |
| 4804 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4805 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4806 | } |
| 4807 | if (_PyObject_LookupAttrId(obj, &PyId_bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4808 | return 1; |
| 4809 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4810 | if (tmp == NULL) { |
| 4811 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 4812 | return 1; |
| 4813 | } |
| 4814 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4815 | int res; |
| 4816 | Py_ssize_t len; |
| 4817 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4818 | if (!PyList_Check(tmp)) { |
| 4819 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4820 | goto failed; |
| 4821 | } |
| 4822 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4823 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4824 | if (bases == NULL) goto failed; |
| 4825 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4826 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 4827 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 4828 | Py_INCREF(tmp2); |
| 4829 | res = obj2ast_expr(tmp2, &val, arena); |
| 4830 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4831 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4832 | if (len != PyList_GET_SIZE(tmp)) { |
| 4833 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 4834 | goto failed; |
| 4835 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4836 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4837 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4838 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4839 | } |
| 4840 | if (_PyObject_LookupAttrId(obj, &PyId_keywords, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4841 | return 1; |
| 4842 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4843 | if (tmp == NULL) { |
| 4844 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 4845 | return 1; |
| 4846 | } |
| 4847 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4848 | int res; |
| 4849 | Py_ssize_t len; |
| 4850 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4851 | if (!PyList_Check(tmp)) { |
| 4852 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4853 | goto failed; |
| 4854 | } |
| 4855 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4856 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4857 | if (keywords == NULL) goto failed; |
| 4858 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4859 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 4860 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 4861 | Py_INCREF(tmp2); |
| 4862 | res = obj2ast_keyword(tmp2, &val, arena); |
| 4863 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4864 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4865 | if (len != PyList_GET_SIZE(tmp)) { |
| 4866 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 4867 | goto failed; |
| 4868 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4869 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4870 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4871 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4872 | } |
| 4873 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4874 | return 1; |
| 4875 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4876 | if (tmp == NULL) { |
| 4877 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 4878 | return 1; |
| 4879 | } |
| 4880 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4881 | int res; |
| 4882 | Py_ssize_t len; |
| 4883 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4884 | if (!PyList_Check(tmp)) { |
| 4885 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4886 | goto failed; |
| 4887 | } |
| 4888 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4889 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4890 | if (body == NULL) goto failed; |
| 4891 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4892 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 4893 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 4894 | Py_INCREF(tmp2); |
| 4895 | res = obj2ast_stmt(tmp2, &val, arena); |
| 4896 | Py_DECREF(tmp2); |
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 \"body\" changed size during iteration"); |
| 4900 | goto failed; |
| 4901 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4902 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4903 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4904 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4905 | } |
| 4906 | if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4907 | return 1; |
| 4908 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4909 | if (tmp == NULL) { |
| 4910 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 4911 | return 1; |
| 4912 | } |
| 4913 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4914 | int res; |
| 4915 | Py_ssize_t len; |
| 4916 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4917 | if (!PyList_Check(tmp)) { |
| 4918 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4919 | goto failed; |
| 4920 | } |
| 4921 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4922 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4923 | if (decorator_list == NULL) goto failed; |
| 4924 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4925 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 4926 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 4927 | Py_INCREF(tmp2); |
| 4928 | res = obj2ast_expr(tmp2, &val, arena); |
| 4929 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4930 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4931 | if (len != PyList_GET_SIZE(tmp)) { |
| 4932 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
| 4933 | goto failed; |
| 4934 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4935 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4936 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4937 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4938 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 4939 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4940 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4941 | if (*out == NULL) goto failed; |
| 4942 | return 0; |
| 4943 | } |
| 4944 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 4945 | if (isinstance == -1) { |
| 4946 | return 1; |
| 4947 | } |
| 4948 | if (isinstance) { |
| 4949 | expr_ty value; |
| 4950 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4951 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 4952 | return 1; |
| 4953 | } |
| 4954 | if (tmp == NULL || tmp == Py_None) { |
| 4955 | Py_CLEAR(tmp); |
| 4956 | value = NULL; |
| 4957 | } |
| 4958 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4959 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4960 | res = obj2ast_expr(tmp, &value, arena); |
| 4961 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4962 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4963 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4964 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 4965 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4966 | if (*out == NULL) goto failed; |
| 4967 | return 0; |
| 4968 | } |
| 4969 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 4970 | if (isinstance == -1) { |
| 4971 | return 1; |
| 4972 | } |
| 4973 | if (isinstance) { |
| 4974 | asdl_seq* targets; |
| 4975 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4976 | if (_PyObject_LookupAttrId(obj, &PyId_targets, &tmp) < 0) { |
| 4977 | return 1; |
| 4978 | } |
| 4979 | if (tmp == NULL) { |
| 4980 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 4981 | return 1; |
| 4982 | } |
| 4983 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4984 | int res; |
| 4985 | Py_ssize_t len; |
| 4986 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4987 | if (!PyList_Check(tmp)) { |
| 4988 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4989 | goto failed; |
| 4990 | } |
| 4991 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4992 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4993 | if (targets == NULL) goto failed; |
| 4994 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4995 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 4996 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 4997 | Py_INCREF(tmp2); |
| 4998 | res = obj2ast_expr(tmp2, &val, arena); |
| 4999 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5000 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5001 | if (len != PyList_GET_SIZE(tmp)) { |
| 5002 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 5003 | goto failed; |
| 5004 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5005 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5006 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5007 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5008 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5009 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 5010 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5011 | if (*out == NULL) goto failed; |
| 5012 | return 0; |
| 5013 | } |
| 5014 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 5015 | if (isinstance == -1) { |
| 5016 | return 1; |
| 5017 | } |
| 5018 | if (isinstance) { |
| 5019 | asdl_seq* targets; |
| 5020 | expr_ty value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5021 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5022 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5023 | if (_PyObject_LookupAttrId(obj, &PyId_targets, &tmp) < 0) { |
| 5024 | return 1; |
| 5025 | } |
| 5026 | if (tmp == NULL) { |
| 5027 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 5028 | return 1; |
| 5029 | } |
| 5030 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5031 | int res; |
| 5032 | Py_ssize_t len; |
| 5033 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5034 | if (!PyList_Check(tmp)) { |
| 5035 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5036 | goto failed; |
| 5037 | } |
| 5038 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5039 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5040 | if (targets == NULL) goto failed; |
| 5041 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5042 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5043 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5044 | Py_INCREF(tmp2); |
| 5045 | res = obj2ast_expr(tmp2, &val, arena); |
| 5046 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5047 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5048 | if (len != PyList_GET_SIZE(tmp)) { |
| 5049 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 5050 | goto failed; |
| 5051 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5052 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5053 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5054 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5055 | } |
| 5056 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5057 | return 1; |
| 5058 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5059 | if (tmp == NULL) { |
| 5060 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 5061 | return 1; |
| 5062 | } |
| 5063 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5064 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5065 | res = obj2ast_expr(tmp, &value, arena); |
| 5066 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5067 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5068 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5069 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5070 | return 1; |
| 5071 | } |
| 5072 | if (tmp == NULL || tmp == Py_None) { |
| 5073 | Py_CLEAR(tmp); |
| 5074 | type_comment = NULL; |
| 5075 | } |
| 5076 | else { |
| 5077 | int res; |
| 5078 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5079 | if (res != 0) goto failed; |
| 5080 | Py_CLEAR(tmp); |
| 5081 | } |
| 5082 | *out = Assign(targets, value, type_comment, lineno, col_offset, |
| 5083 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5084 | if (*out == NULL) goto failed; |
| 5085 | return 0; |
| 5086 | } |
| 5087 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 5088 | if (isinstance == -1) { |
| 5089 | return 1; |
| 5090 | } |
| 5091 | if (isinstance) { |
| 5092 | expr_ty target; |
| 5093 | operator_ty op; |
| 5094 | expr_ty value; |
| 5095 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5096 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5097 | return 1; |
| 5098 | } |
| 5099 | if (tmp == NULL) { |
| 5100 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 5101 | return 1; |
| 5102 | } |
| 5103 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5104 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5105 | res = obj2ast_expr(tmp, &target, arena); |
| 5106 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5107 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5108 | } |
| 5109 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5110 | return 1; |
| 5111 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5112 | if (tmp == NULL) { |
| 5113 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 5114 | return 1; |
| 5115 | } |
| 5116 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5117 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5118 | res = obj2ast_operator(tmp, &op, arena); |
| 5119 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5120 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5121 | } |
| 5122 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5123 | return 1; |
| 5124 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5125 | if (tmp == NULL) { |
| 5126 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 5127 | return 1; |
| 5128 | } |
| 5129 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5130 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5131 | res = obj2ast_expr(tmp, &value, arena); |
| 5132 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5133 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5134 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5135 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 5136 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5137 | if (*out == NULL) goto failed; |
| 5138 | return 0; |
| 5139 | } |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5140 | isinstance = PyObject_IsInstance(obj, (PyObject*)AnnAssign_type); |
| 5141 | if (isinstance == -1) { |
| 5142 | return 1; |
| 5143 | } |
| 5144 | if (isinstance) { |
| 5145 | expr_ty target; |
| 5146 | expr_ty annotation; |
| 5147 | expr_ty value; |
| 5148 | int simple; |
| 5149 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5150 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5151 | return 1; |
| 5152 | } |
| 5153 | if (tmp == NULL) { |
| 5154 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from 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_expr(tmp, &target, arena); |
| 5160 | if (res != 0) goto failed; |
| 5161 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5162 | } |
| 5163 | if (_PyObject_LookupAttrId(obj, &PyId_annotation, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5164 | return 1; |
| 5165 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5166 | if (tmp == NULL) { |
| 5167 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 5168 | return 1; |
| 5169 | } |
| 5170 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5171 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5172 | res = obj2ast_expr(tmp, &annotation, arena); |
| 5173 | if (res != 0) goto failed; |
| 5174 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5175 | } |
| 5176 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5177 | return 1; |
| 5178 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5179 | if (tmp == NULL || tmp == Py_None) { |
| 5180 | Py_CLEAR(tmp); |
| 5181 | value = NULL; |
| 5182 | } |
| 5183 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5184 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5185 | res = obj2ast_expr(tmp, &value, arena); |
| 5186 | if (res != 0) goto failed; |
| 5187 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5188 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5189 | if (_PyObject_LookupAttrId(obj, &PyId_simple, &tmp) < 0) { |
| 5190 | return 1; |
| 5191 | } |
| 5192 | if (tmp == NULL) { |
| 5193 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 5194 | return 1; |
| 5195 | } |
| 5196 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5197 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5198 | res = obj2ast_int(tmp, &simple, arena); |
| 5199 | if (res != 0) goto failed; |
| 5200 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5201 | } |
| 5202 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5203 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5204 | if (*out == NULL) goto failed; |
| 5205 | return 0; |
| 5206 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5207 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 5208 | if (isinstance == -1) { |
| 5209 | return 1; |
| 5210 | } |
| 5211 | if (isinstance) { |
| 5212 | expr_ty target; |
| 5213 | expr_ty iter; |
| 5214 | asdl_seq* body; |
| 5215 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5216 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5217 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5218 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5219 | return 1; |
| 5220 | } |
| 5221 | if (tmp == NULL) { |
| 5222 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 5223 | return 1; |
| 5224 | } |
| 5225 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5226 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5227 | res = obj2ast_expr(tmp, &target, arena); |
| 5228 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5229 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5230 | } |
| 5231 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5232 | return 1; |
| 5233 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5234 | if (tmp == NULL) { |
| 5235 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 5236 | return 1; |
| 5237 | } |
| 5238 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5239 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5240 | res = obj2ast_expr(tmp, &iter, arena); |
| 5241 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5242 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5243 | } |
| 5244 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5245 | return 1; |
| 5246 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5247 | if (tmp == NULL) { |
| 5248 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 5249 | return 1; |
| 5250 | } |
| 5251 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5252 | int res; |
| 5253 | Py_ssize_t len; |
| 5254 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5255 | if (!PyList_Check(tmp)) { |
| 5256 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5257 | goto failed; |
| 5258 | } |
| 5259 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5260 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5261 | if (body == NULL) goto failed; |
| 5262 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5263 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5264 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5265 | Py_INCREF(tmp2); |
| 5266 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5267 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5268 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5269 | if (len != PyList_GET_SIZE(tmp)) { |
| 5270 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 5271 | goto failed; |
| 5272 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5273 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5274 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5275 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5276 | } |
| 5277 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5278 | return 1; |
| 5279 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5280 | if (tmp == NULL) { |
| 5281 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 5282 | return 1; |
| 5283 | } |
| 5284 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5285 | int res; |
| 5286 | Py_ssize_t len; |
| 5287 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5288 | if (!PyList_Check(tmp)) { |
| 5289 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5290 | goto failed; |
| 5291 | } |
| 5292 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5293 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5294 | if (orelse == NULL) goto failed; |
| 5295 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5296 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5297 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5298 | Py_INCREF(tmp2); |
| 5299 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5300 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5301 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5302 | if (len != PyList_GET_SIZE(tmp)) { |
| 5303 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 5304 | goto failed; |
| 5305 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5306 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5307 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5308 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5309 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5310 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5311 | return 1; |
| 5312 | } |
| 5313 | if (tmp == NULL || tmp == Py_None) { |
| 5314 | Py_CLEAR(tmp); |
| 5315 | type_comment = NULL; |
| 5316 | } |
| 5317 | else { |
| 5318 | int res; |
| 5319 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5320 | if (res != 0) goto failed; |
| 5321 | Py_CLEAR(tmp); |
| 5322 | } |
| 5323 | *out = For(target, iter, body, orelse, type_comment, lineno, |
| 5324 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5325 | if (*out == NULL) goto failed; |
| 5326 | return 0; |
| 5327 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5328 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFor_type); |
| 5329 | if (isinstance == -1) { |
| 5330 | return 1; |
| 5331 | } |
| 5332 | if (isinstance) { |
| 5333 | expr_ty target; |
| 5334 | expr_ty iter; |
| 5335 | asdl_seq* body; |
| 5336 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5337 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5338 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5339 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 5340 | return 1; |
| 5341 | } |
| 5342 | if (tmp == NULL) { |
| 5343 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 5344 | return 1; |
| 5345 | } |
| 5346 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5347 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5348 | res = obj2ast_expr(tmp, &target, arena); |
| 5349 | if (res != 0) goto failed; |
| 5350 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5351 | } |
| 5352 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5353 | return 1; |
| 5354 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5355 | if (tmp == NULL) { |
| 5356 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 5357 | return 1; |
| 5358 | } |
| 5359 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5360 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5361 | res = obj2ast_expr(tmp, &iter, arena); |
| 5362 | if (res != 0) goto failed; |
| 5363 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5364 | } |
| 5365 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5366 | return 1; |
| 5367 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5368 | if (tmp == NULL) { |
| 5369 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 5370 | return 1; |
| 5371 | } |
| 5372 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5373 | int res; |
| 5374 | Py_ssize_t len; |
| 5375 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5376 | if (!PyList_Check(tmp)) { |
| 5377 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5378 | goto failed; |
| 5379 | } |
| 5380 | len = PyList_GET_SIZE(tmp); |
| 5381 | body = _Py_asdl_seq_new(len, arena); |
| 5382 | if (body == NULL) goto failed; |
| 5383 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5384 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5385 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5386 | Py_INCREF(tmp2); |
| 5387 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5388 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5389 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5390 | if (len != PyList_GET_SIZE(tmp)) { |
| 5391 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 5392 | goto failed; |
| 5393 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5394 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5395 | } |
| 5396 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5397 | } |
| 5398 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5399 | return 1; |
| 5400 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5401 | if (tmp == NULL) { |
| 5402 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 5403 | return 1; |
| 5404 | } |
| 5405 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5406 | int res; |
| 5407 | Py_ssize_t len; |
| 5408 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5409 | if (!PyList_Check(tmp)) { |
| 5410 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5411 | goto failed; |
| 5412 | } |
| 5413 | len = PyList_GET_SIZE(tmp); |
| 5414 | orelse = _Py_asdl_seq_new(len, arena); |
| 5415 | if (orelse == NULL) goto failed; |
| 5416 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5417 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5418 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5419 | Py_INCREF(tmp2); |
| 5420 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5421 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5422 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5423 | if (len != PyList_GET_SIZE(tmp)) { |
| 5424 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 5425 | goto failed; |
| 5426 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5427 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5428 | } |
| 5429 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5430 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5431 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5432 | return 1; |
| 5433 | } |
| 5434 | if (tmp == NULL || tmp == Py_None) { |
| 5435 | Py_CLEAR(tmp); |
| 5436 | type_comment = NULL; |
| 5437 | } |
| 5438 | else { |
| 5439 | int res; |
| 5440 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5441 | if (res != 0) goto failed; |
| 5442 | Py_CLEAR(tmp); |
| 5443 | } |
| 5444 | *out = AsyncFor(target, iter, body, orelse, type_comment, lineno, |
| 5445 | col_offset, end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5446 | if (*out == NULL) goto failed; |
| 5447 | return 0; |
| 5448 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5449 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 5450 | if (isinstance == -1) { |
| 5451 | return 1; |
| 5452 | } |
| 5453 | if (isinstance) { |
| 5454 | expr_ty test; |
| 5455 | asdl_seq* body; |
| 5456 | asdl_seq* orelse; |
| 5457 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5458 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 5459 | return 1; |
| 5460 | } |
| 5461 | if (tmp == NULL) { |
| 5462 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 5463 | return 1; |
| 5464 | } |
| 5465 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5466 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5467 | res = obj2ast_expr(tmp, &test, arena); |
| 5468 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5469 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5470 | } |
| 5471 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5472 | return 1; |
| 5473 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5474 | if (tmp == NULL) { |
| 5475 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 5476 | return 1; |
| 5477 | } |
| 5478 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5479 | int res; |
| 5480 | Py_ssize_t len; |
| 5481 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5482 | if (!PyList_Check(tmp)) { |
| 5483 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5484 | goto failed; |
| 5485 | } |
| 5486 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5487 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5488 | if (body == NULL) goto failed; |
| 5489 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5490 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5491 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5492 | Py_INCREF(tmp2); |
| 5493 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5494 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5495 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5496 | if (len != PyList_GET_SIZE(tmp)) { |
| 5497 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 5498 | goto failed; |
| 5499 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5500 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5501 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5502 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5503 | } |
| 5504 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5505 | return 1; |
| 5506 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5507 | if (tmp == NULL) { |
| 5508 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 5509 | return 1; |
| 5510 | } |
| 5511 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5512 | int res; |
| 5513 | Py_ssize_t len; |
| 5514 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5515 | if (!PyList_Check(tmp)) { |
| 5516 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5517 | goto failed; |
| 5518 | } |
| 5519 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5520 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5521 | if (orelse == NULL) goto failed; |
| 5522 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5523 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5524 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5525 | Py_INCREF(tmp2); |
| 5526 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5527 | Py_DECREF(tmp2); |
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, "While field \"orelse\" 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(orelse, 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); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5536 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5537 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 5538 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5539 | if (*out == NULL) goto failed; |
| 5540 | return 0; |
| 5541 | } |
| 5542 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 5543 | if (isinstance == -1) { |
| 5544 | return 1; |
| 5545 | } |
| 5546 | if (isinstance) { |
| 5547 | expr_ty test; |
| 5548 | asdl_seq* body; |
| 5549 | asdl_seq* orelse; |
| 5550 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5551 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 5552 | return 1; |
| 5553 | } |
| 5554 | if (tmp == NULL) { |
| 5555 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 5556 | return 1; |
| 5557 | } |
| 5558 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5559 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5560 | res = obj2ast_expr(tmp, &test, arena); |
| 5561 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5562 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5563 | } |
| 5564 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5565 | return 1; |
| 5566 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5567 | if (tmp == NULL) { |
| 5568 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 5569 | return 1; |
| 5570 | } |
| 5571 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5572 | int res; |
| 5573 | Py_ssize_t len; |
| 5574 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5575 | if (!PyList_Check(tmp)) { |
| 5576 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5577 | goto failed; |
| 5578 | } |
| 5579 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5580 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5581 | if (body == NULL) goto failed; |
| 5582 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5583 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5584 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5585 | Py_INCREF(tmp2); |
| 5586 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5587 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5588 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5589 | if (len != PyList_GET_SIZE(tmp)) { |
| 5590 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 5591 | goto failed; |
| 5592 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5593 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5594 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5595 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5596 | } |
| 5597 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5598 | return 1; |
| 5599 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5600 | if (tmp == NULL) { |
| 5601 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 5602 | return 1; |
| 5603 | } |
| 5604 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5605 | int res; |
| 5606 | Py_ssize_t len; |
| 5607 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5608 | if (!PyList_Check(tmp)) { |
| 5609 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5610 | goto failed; |
| 5611 | } |
| 5612 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5613 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5614 | if (orelse == NULL) goto failed; |
| 5615 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5616 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5617 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5618 | Py_INCREF(tmp2); |
| 5619 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5620 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5621 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5622 | if (len != PyList_GET_SIZE(tmp)) { |
| 5623 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 5624 | goto failed; |
| 5625 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5626 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5627 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5628 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5629 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5630 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 5631 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5632 | if (*out == NULL) goto failed; |
| 5633 | return 0; |
| 5634 | } |
| 5635 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 5636 | if (isinstance == -1) { |
| 5637 | return 1; |
| 5638 | } |
| 5639 | if (isinstance) { |
| 5640 | asdl_seq* items; |
| 5641 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5642 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5643 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5644 | if (_PyObject_LookupAttrId(obj, &PyId_items, &tmp) < 0) { |
| 5645 | return 1; |
| 5646 | } |
| 5647 | if (tmp == NULL) { |
| 5648 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 5649 | return 1; |
| 5650 | } |
| 5651 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5652 | int res; |
| 5653 | Py_ssize_t len; |
| 5654 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5655 | if (!PyList_Check(tmp)) { |
| 5656 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5657 | goto failed; |
| 5658 | } |
| 5659 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5660 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5661 | if (items == NULL) goto failed; |
| 5662 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5663 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5664 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5665 | Py_INCREF(tmp2); |
| 5666 | res = obj2ast_withitem(tmp2, &val, arena); |
| 5667 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5668 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5669 | if (len != PyList_GET_SIZE(tmp)) { |
| 5670 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 5671 | goto failed; |
| 5672 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5673 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5674 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5675 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5676 | } |
| 5677 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5678 | return 1; |
| 5679 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5680 | if (tmp == NULL) { |
| 5681 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 5682 | return 1; |
| 5683 | } |
| 5684 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5685 | int res; |
| 5686 | Py_ssize_t len; |
| 5687 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5688 | if (!PyList_Check(tmp)) { |
| 5689 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5690 | goto failed; |
| 5691 | } |
| 5692 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5693 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5694 | if (body == NULL) goto failed; |
| 5695 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5696 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5697 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5698 | Py_INCREF(tmp2); |
| 5699 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5700 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5701 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5702 | if (len != PyList_GET_SIZE(tmp)) { |
| 5703 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 5704 | goto failed; |
| 5705 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5706 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5707 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5708 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5709 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5710 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5711 | return 1; |
| 5712 | } |
| 5713 | if (tmp == NULL || tmp == Py_None) { |
| 5714 | Py_CLEAR(tmp); |
| 5715 | type_comment = NULL; |
| 5716 | } |
| 5717 | else { |
| 5718 | int res; |
| 5719 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5720 | if (res != 0) goto failed; |
| 5721 | Py_CLEAR(tmp); |
| 5722 | } |
| 5723 | *out = With(items, body, type_comment, lineno, col_offset, end_lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5724 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5725 | if (*out == NULL) goto failed; |
| 5726 | return 0; |
| 5727 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5728 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncWith_type); |
| 5729 | if (isinstance == -1) { |
| 5730 | return 1; |
| 5731 | } |
| 5732 | if (isinstance) { |
| 5733 | asdl_seq* items; |
| 5734 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5735 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5736 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5737 | if (_PyObject_LookupAttrId(obj, &PyId_items, &tmp) < 0) { |
| 5738 | return 1; |
| 5739 | } |
| 5740 | if (tmp == NULL) { |
| 5741 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 5742 | return 1; |
| 5743 | } |
| 5744 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5745 | int res; |
| 5746 | Py_ssize_t len; |
| 5747 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5748 | if (!PyList_Check(tmp)) { |
| 5749 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5750 | goto failed; |
| 5751 | } |
| 5752 | len = PyList_GET_SIZE(tmp); |
| 5753 | items = _Py_asdl_seq_new(len, arena); |
| 5754 | if (items == NULL) goto failed; |
| 5755 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5756 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5757 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5758 | Py_INCREF(tmp2); |
| 5759 | res = obj2ast_withitem(tmp2, &val, arena); |
| 5760 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5761 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5762 | if (len != PyList_GET_SIZE(tmp)) { |
| 5763 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 5764 | goto failed; |
| 5765 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5766 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5767 | } |
| 5768 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5769 | } |
| 5770 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5771 | return 1; |
| 5772 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5773 | if (tmp == NULL) { |
| 5774 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 5775 | return 1; |
| 5776 | } |
| 5777 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5778 | int res; |
| 5779 | Py_ssize_t len; |
| 5780 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5781 | if (!PyList_Check(tmp)) { |
| 5782 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5783 | goto failed; |
| 5784 | } |
| 5785 | len = PyList_GET_SIZE(tmp); |
| 5786 | body = _Py_asdl_seq_new(len, arena); |
| 5787 | if (body == NULL) goto failed; |
| 5788 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5789 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5790 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5791 | Py_INCREF(tmp2); |
| 5792 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5793 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5794 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5795 | if (len != PyList_GET_SIZE(tmp)) { |
| 5796 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 5797 | goto failed; |
| 5798 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5799 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5800 | } |
| 5801 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5802 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5803 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 5804 | return 1; |
| 5805 | } |
| 5806 | if (tmp == NULL || tmp == Py_None) { |
| 5807 | Py_CLEAR(tmp); |
| 5808 | type_comment = NULL; |
| 5809 | } |
| 5810 | else { |
| 5811 | int res; |
| 5812 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5813 | if (res != 0) goto failed; |
| 5814 | Py_CLEAR(tmp); |
| 5815 | } |
| 5816 | *out = AsyncWith(items, body, type_comment, lineno, col_offset, |
| 5817 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5818 | if (*out == NULL) goto failed; |
| 5819 | return 0; |
| 5820 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5821 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 5822 | if (isinstance == -1) { |
| 5823 | return 1; |
| 5824 | } |
| 5825 | if (isinstance) { |
| 5826 | expr_ty exc; |
| 5827 | expr_ty cause; |
| 5828 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5829 | if (_PyObject_LookupAttrId(obj, &PyId_exc, &tmp) < 0) { |
| 5830 | return 1; |
| 5831 | } |
| 5832 | if (tmp == NULL || tmp == Py_None) { |
| 5833 | Py_CLEAR(tmp); |
| 5834 | exc = NULL; |
| 5835 | } |
| 5836 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5837 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5838 | res = obj2ast_expr(tmp, &exc, arena); |
| 5839 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5840 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5841 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5842 | if (_PyObject_LookupAttrId(obj, &PyId_cause, &tmp) < 0) { |
| 5843 | return 1; |
| 5844 | } |
| 5845 | if (tmp == NULL || tmp == Py_None) { |
| 5846 | Py_CLEAR(tmp); |
| 5847 | cause = NULL; |
| 5848 | } |
| 5849 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5850 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5851 | res = obj2ast_expr(tmp, &cause, arena); |
| 5852 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5853 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5854 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5855 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 5856 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5857 | if (*out == NULL) goto failed; |
| 5858 | return 0; |
| 5859 | } |
| 5860 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
| 5861 | if (isinstance == -1) { |
| 5862 | return 1; |
| 5863 | } |
| 5864 | if (isinstance) { |
| 5865 | asdl_seq* body; |
| 5866 | asdl_seq* handlers; |
| 5867 | asdl_seq* orelse; |
| 5868 | asdl_seq* finalbody; |
| 5869 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5870 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 5871 | return 1; |
| 5872 | } |
| 5873 | if (tmp == NULL) { |
| 5874 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 5875 | return 1; |
| 5876 | } |
| 5877 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5878 | int res; |
| 5879 | Py_ssize_t len; |
| 5880 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5881 | if (!PyList_Check(tmp)) { |
| 5882 | PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5883 | goto failed; |
| 5884 | } |
| 5885 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5886 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5887 | if (body == NULL) goto failed; |
| 5888 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5889 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5890 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5891 | Py_INCREF(tmp2); |
| 5892 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5893 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5894 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5895 | if (len != PyList_GET_SIZE(tmp)) { |
| 5896 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 5897 | goto failed; |
| 5898 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5899 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5900 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5901 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5902 | } |
| 5903 | if (_PyObject_LookupAttrId(obj, &PyId_handlers, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5904 | return 1; |
| 5905 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5906 | if (tmp == NULL) { |
| 5907 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 5908 | return 1; |
| 5909 | } |
| 5910 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5911 | int res; |
| 5912 | Py_ssize_t len; |
| 5913 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5914 | if (!PyList_Check(tmp)) { |
| 5915 | PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5916 | goto failed; |
| 5917 | } |
| 5918 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5919 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5920 | if (handlers == NULL) goto failed; |
| 5921 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5922 | excepthandler_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5923 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5924 | Py_INCREF(tmp2); |
| 5925 | res = obj2ast_excepthandler(tmp2, &val, arena); |
| 5926 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5927 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5928 | if (len != PyList_GET_SIZE(tmp)) { |
| 5929 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 5930 | goto failed; |
| 5931 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5932 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5933 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5934 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5935 | } |
| 5936 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5937 | return 1; |
| 5938 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5939 | if (tmp == NULL) { |
| 5940 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 5941 | return 1; |
| 5942 | } |
| 5943 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5944 | int res; |
| 5945 | Py_ssize_t len; |
| 5946 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5947 | if (!PyList_Check(tmp)) { |
| 5948 | PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5949 | goto failed; |
| 5950 | } |
| 5951 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5952 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5953 | if (orelse == NULL) goto failed; |
| 5954 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5955 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5956 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5957 | Py_INCREF(tmp2); |
| 5958 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5959 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5960 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5961 | if (len != PyList_GET_SIZE(tmp)) { |
| 5962 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 5963 | goto failed; |
| 5964 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5965 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5966 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5967 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5968 | } |
| 5969 | if (_PyObject_LookupAttrId(obj, &PyId_finalbody, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5970 | return 1; |
| 5971 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5972 | if (tmp == NULL) { |
| 5973 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 5974 | return 1; |
| 5975 | } |
| 5976 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5977 | int res; |
| 5978 | Py_ssize_t len; |
| 5979 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5980 | if (!PyList_Check(tmp)) { |
| 5981 | PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5982 | goto failed; |
| 5983 | } |
| 5984 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5985 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5986 | if (finalbody == NULL) goto failed; |
| 5987 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5988 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5989 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5990 | Py_INCREF(tmp2); |
| 5991 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5992 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5993 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5994 | if (len != PyList_GET_SIZE(tmp)) { |
| 5995 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 5996 | goto failed; |
| 5997 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5998 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5999 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6000 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6001 | } |
| 6002 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6003 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6004 | if (*out == NULL) goto failed; |
| 6005 | return 0; |
| 6006 | } |
| 6007 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 6008 | if (isinstance == -1) { |
| 6009 | return 1; |
| 6010 | } |
| 6011 | if (isinstance) { |
| 6012 | expr_ty test; |
| 6013 | expr_ty msg; |
| 6014 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6015 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 6016 | return 1; |
| 6017 | } |
| 6018 | if (tmp == NULL) { |
| 6019 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 6020 | return 1; |
| 6021 | } |
| 6022 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6023 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6024 | res = obj2ast_expr(tmp, &test, arena); |
| 6025 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6026 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6027 | } |
| 6028 | if (_PyObject_LookupAttrId(obj, &PyId_msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6029 | return 1; |
| 6030 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6031 | if (tmp == NULL || tmp == Py_None) { |
| 6032 | Py_CLEAR(tmp); |
| 6033 | msg = NULL; |
| 6034 | } |
| 6035 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6036 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6037 | res = obj2ast_expr(tmp, &msg, arena); |
| 6038 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6039 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6040 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6041 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 6042 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6043 | if (*out == NULL) goto failed; |
| 6044 | return 0; |
| 6045 | } |
| 6046 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 6047 | if (isinstance == -1) { |
| 6048 | return 1; |
| 6049 | } |
| 6050 | if (isinstance) { |
| 6051 | asdl_seq* names; |
| 6052 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6053 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 6054 | return 1; |
| 6055 | } |
| 6056 | if (tmp == NULL) { |
| 6057 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 6058 | return 1; |
| 6059 | } |
| 6060 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6061 | int res; |
| 6062 | Py_ssize_t len; |
| 6063 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6064 | if (!PyList_Check(tmp)) { |
| 6065 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6066 | goto failed; |
| 6067 | } |
| 6068 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6069 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6070 | if (names == NULL) goto failed; |
| 6071 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6072 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6073 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6074 | Py_INCREF(tmp2); |
| 6075 | res = obj2ast_alias(tmp2, &val, arena); |
| 6076 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6077 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6078 | if (len != PyList_GET_SIZE(tmp)) { |
| 6079 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 6080 | goto failed; |
| 6081 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6082 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6083 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6084 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6085 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6086 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6087 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6088 | if (*out == NULL) goto failed; |
| 6089 | return 0; |
| 6090 | } |
| 6091 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 6092 | if (isinstance == -1) { |
| 6093 | return 1; |
| 6094 | } |
| 6095 | if (isinstance) { |
| 6096 | identifier module; |
| 6097 | asdl_seq* names; |
| 6098 | int level; |
| 6099 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6100 | if (_PyObject_LookupAttrId(obj, &PyId_module, &tmp) < 0) { |
| 6101 | return 1; |
| 6102 | } |
| 6103 | if (tmp == NULL || tmp == Py_None) { |
| 6104 | Py_CLEAR(tmp); |
| 6105 | module = NULL; |
| 6106 | } |
| 6107 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6108 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6109 | res = obj2ast_identifier(tmp, &module, arena); |
| 6110 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6111 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6112 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6113 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 6114 | return 1; |
| 6115 | } |
| 6116 | if (tmp == NULL) { |
| 6117 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 6118 | return 1; |
| 6119 | } |
| 6120 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6121 | int res; |
| 6122 | Py_ssize_t len; |
| 6123 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6124 | if (!PyList_Check(tmp)) { |
| 6125 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6126 | goto failed; |
| 6127 | } |
| 6128 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6129 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6130 | if (names == NULL) goto failed; |
| 6131 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6132 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6133 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6134 | Py_INCREF(tmp2); |
| 6135 | res = obj2ast_alias(tmp2, &val, arena); |
| 6136 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6137 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6138 | if (len != PyList_GET_SIZE(tmp)) { |
| 6139 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 6140 | goto failed; |
| 6141 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6142 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6143 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6144 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6145 | } |
| 6146 | if (_PyObject_LookupAttrId(obj, &PyId_level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6147 | return 1; |
| 6148 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6149 | if (tmp == NULL || tmp == Py_None) { |
| 6150 | Py_CLEAR(tmp); |
| 6151 | level = 0; |
| 6152 | } |
| 6153 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6154 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6155 | res = obj2ast_int(tmp, &level, arena); |
| 6156 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6157 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6158 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6159 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 6160 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6161 | if (*out == NULL) goto failed; |
| 6162 | return 0; |
| 6163 | } |
| 6164 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 6165 | if (isinstance == -1) { |
| 6166 | return 1; |
| 6167 | } |
| 6168 | if (isinstance) { |
| 6169 | asdl_seq* names; |
| 6170 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6171 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 6172 | return 1; |
| 6173 | } |
| 6174 | if (tmp == NULL) { |
| 6175 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 6176 | return 1; |
| 6177 | } |
| 6178 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6179 | int res; |
| 6180 | Py_ssize_t len; |
| 6181 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6182 | if (!PyList_Check(tmp)) { |
| 6183 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6184 | goto failed; |
| 6185 | } |
| 6186 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6187 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6188 | if (names == NULL) goto failed; |
| 6189 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6190 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6191 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6192 | Py_INCREF(tmp2); |
| 6193 | res = obj2ast_identifier(tmp2, &val, arena); |
| 6194 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6195 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6196 | if (len != PyList_GET_SIZE(tmp)) { |
| 6197 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 6198 | goto failed; |
| 6199 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6200 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6201 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6202 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6203 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6204 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6205 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6206 | if (*out == NULL) goto failed; |
| 6207 | return 0; |
| 6208 | } |
| 6209 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 6210 | if (isinstance == -1) { |
| 6211 | return 1; |
| 6212 | } |
| 6213 | if (isinstance) { |
| 6214 | asdl_seq* names; |
| 6215 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6216 | if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) { |
| 6217 | return 1; |
| 6218 | } |
| 6219 | if (tmp == NULL) { |
| 6220 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 6221 | return 1; |
| 6222 | } |
| 6223 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6224 | int res; |
| 6225 | Py_ssize_t len; |
| 6226 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6227 | if (!PyList_Check(tmp)) { |
| 6228 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6229 | goto failed; |
| 6230 | } |
| 6231 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6232 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6233 | if (names == NULL) goto failed; |
| 6234 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6235 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6236 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6237 | Py_INCREF(tmp2); |
| 6238 | res = obj2ast_identifier(tmp2, &val, arena); |
| 6239 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6240 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6241 | if (len != PyList_GET_SIZE(tmp)) { |
| 6242 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 6243 | goto failed; |
| 6244 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6245 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6246 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6247 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6248 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6249 | *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6250 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6251 | if (*out == NULL) goto failed; |
| 6252 | return 0; |
| 6253 | } |
| 6254 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 6255 | if (isinstance == -1) { |
| 6256 | return 1; |
| 6257 | } |
| 6258 | if (isinstance) { |
| 6259 | expr_ty value; |
| 6260 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6261 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6262 | return 1; |
| 6263 | } |
| 6264 | if (tmp == NULL) { |
| 6265 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 6266 | return 1; |
| 6267 | } |
| 6268 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6269 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6270 | res = obj2ast_expr(tmp, &value, arena); |
| 6271 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6272 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6273 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6274 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 6275 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6276 | if (*out == NULL) goto failed; |
| 6277 | return 0; |
| 6278 | } |
| 6279 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 6280 | if (isinstance == -1) { |
| 6281 | return 1; |
| 6282 | } |
| 6283 | if (isinstance) { |
| 6284 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6285 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6286 | if (*out == NULL) goto failed; |
| 6287 | return 0; |
| 6288 | } |
| 6289 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 6290 | if (isinstance == -1) { |
| 6291 | return 1; |
| 6292 | } |
| 6293 | if (isinstance) { |
| 6294 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6295 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6296 | if (*out == NULL) goto failed; |
| 6297 | return 0; |
| 6298 | } |
| 6299 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 6300 | if (isinstance == -1) { |
| 6301 | return 1; |
| 6302 | } |
| 6303 | if (isinstance) { |
| 6304 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6305 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6306 | if (*out == NULL) goto failed; |
| 6307 | return 0; |
| 6308 | } |
| 6309 | |
| 6310 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 6311 | failed: |
| 6312 | Py_XDECREF(tmp); |
| 6313 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6314 | } |
| 6315 | |
| 6316 | int |
| 6317 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 6318 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6319 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6320 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6321 | PyObject *tmp = NULL; |
| 6322 | int lineno; |
| 6323 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6324 | int end_lineno; |
| 6325 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6326 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6327 | if (obj == Py_None) { |
| 6328 | *out = NULL; |
| 6329 | return 0; |
| 6330 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6331 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 6332 | return 1; |
| 6333 | } |
| 6334 | if (tmp == NULL) { |
| 6335 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 6336 | return 1; |
| 6337 | } |
| 6338 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6339 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6340 | res = obj2ast_int(tmp, &lineno, arena); |
| 6341 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6342 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6343 | } |
| 6344 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6345 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6346 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6347 | if (tmp == NULL) { |
| 6348 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 6349 | return 1; |
| 6350 | } |
| 6351 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6352 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6353 | res = obj2ast_int(tmp, &col_offset, arena); |
| 6354 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6355 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6356 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6357 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 6358 | return 1; |
| 6359 | } |
| 6360 | if (tmp == NULL || tmp == Py_None) { |
| 6361 | Py_CLEAR(tmp); |
| 6362 | end_lineno = 0; |
| 6363 | } |
| 6364 | else { |
| 6365 | int res; |
| 6366 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 6367 | if (res != 0) goto failed; |
| 6368 | Py_CLEAR(tmp); |
| 6369 | } |
| 6370 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 6371 | return 1; |
| 6372 | } |
| 6373 | if (tmp == NULL || tmp == Py_None) { |
| 6374 | Py_CLEAR(tmp); |
| 6375 | end_col_offset = 0; |
| 6376 | } |
| 6377 | else { |
| 6378 | int res; |
| 6379 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 6380 | if (res != 0) goto failed; |
| 6381 | Py_CLEAR(tmp); |
| 6382 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6383 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 6384 | if (isinstance == -1) { |
| 6385 | return 1; |
| 6386 | } |
| 6387 | if (isinstance) { |
| 6388 | boolop_ty op; |
| 6389 | asdl_seq* values; |
| 6390 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6391 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
| 6392 | return 1; |
| 6393 | } |
| 6394 | if (tmp == NULL) { |
| 6395 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 6396 | return 1; |
| 6397 | } |
| 6398 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6399 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6400 | res = obj2ast_boolop(tmp, &op, arena); |
| 6401 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6402 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6403 | } |
| 6404 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6405 | return 1; |
| 6406 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6407 | if (tmp == NULL) { |
| 6408 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 6409 | return 1; |
| 6410 | } |
| 6411 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6412 | int res; |
| 6413 | Py_ssize_t len; |
| 6414 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6415 | if (!PyList_Check(tmp)) { |
| 6416 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6417 | goto failed; |
| 6418 | } |
| 6419 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6420 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6421 | if (values == NULL) goto failed; |
| 6422 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6423 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6424 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6425 | Py_INCREF(tmp2); |
| 6426 | res = obj2ast_expr(tmp2, &val, arena); |
| 6427 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6428 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6429 | if (len != PyList_GET_SIZE(tmp)) { |
| 6430 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 6431 | goto failed; |
| 6432 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6433 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6434 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6435 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6436 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6437 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 6438 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6439 | if (*out == NULL) goto failed; |
| 6440 | return 0; |
| 6441 | } |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 6442 | isinstance = PyObject_IsInstance(obj, (PyObject*)NamedExpr_type); |
| 6443 | if (isinstance == -1) { |
| 6444 | return 1; |
| 6445 | } |
| 6446 | if (isinstance) { |
| 6447 | expr_ty target; |
| 6448 | expr_ty value; |
| 6449 | |
| 6450 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 6451 | return 1; |
| 6452 | } |
| 6453 | if (tmp == NULL) { |
| 6454 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); |
| 6455 | return 1; |
| 6456 | } |
| 6457 | else { |
| 6458 | int res; |
| 6459 | res = obj2ast_expr(tmp, &target, arena); |
| 6460 | if (res != 0) goto failed; |
| 6461 | Py_CLEAR(tmp); |
| 6462 | } |
| 6463 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 6464 | return 1; |
| 6465 | } |
| 6466 | if (tmp == NULL) { |
| 6467 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); |
| 6468 | return 1; |
| 6469 | } |
| 6470 | else { |
| 6471 | int res; |
| 6472 | res = obj2ast_expr(tmp, &value, arena); |
| 6473 | if (res != 0) goto failed; |
| 6474 | Py_CLEAR(tmp); |
| 6475 | } |
| 6476 | *out = NamedExpr(target, value, lineno, col_offset, end_lineno, |
| 6477 | end_col_offset, arena); |
| 6478 | if (*out == NULL) goto failed; |
| 6479 | return 0; |
| 6480 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6481 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 6482 | if (isinstance == -1) { |
| 6483 | return 1; |
| 6484 | } |
| 6485 | if (isinstance) { |
| 6486 | expr_ty left; |
| 6487 | operator_ty op; |
| 6488 | expr_ty right; |
| 6489 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6490 | if (_PyObject_LookupAttrId(obj, &PyId_left, &tmp) < 0) { |
| 6491 | return 1; |
| 6492 | } |
| 6493 | if (tmp == NULL) { |
| 6494 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 6495 | return 1; |
| 6496 | } |
| 6497 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6498 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6499 | res = obj2ast_expr(tmp, &left, arena); |
| 6500 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6501 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6502 | } |
| 6503 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6504 | return 1; |
| 6505 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6506 | if (tmp == NULL) { |
| 6507 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 6508 | return 1; |
| 6509 | } |
| 6510 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6511 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6512 | res = obj2ast_operator(tmp, &op, arena); |
| 6513 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6514 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6515 | } |
| 6516 | if (_PyObject_LookupAttrId(obj, &PyId_right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6517 | return 1; |
| 6518 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6519 | if (tmp == NULL) { |
| 6520 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 6521 | return 1; |
| 6522 | } |
| 6523 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6524 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6525 | res = obj2ast_expr(tmp, &right, arena); |
| 6526 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6527 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6528 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6529 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 6530 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6531 | if (*out == NULL) goto failed; |
| 6532 | return 0; |
| 6533 | } |
| 6534 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 6535 | if (isinstance == -1) { |
| 6536 | return 1; |
| 6537 | } |
| 6538 | if (isinstance) { |
| 6539 | unaryop_ty op; |
| 6540 | expr_ty operand; |
| 6541 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6542 | if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) { |
| 6543 | return 1; |
| 6544 | } |
| 6545 | if (tmp == NULL) { |
| 6546 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 6547 | return 1; |
| 6548 | } |
| 6549 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6550 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6551 | res = obj2ast_unaryop(tmp, &op, arena); |
| 6552 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6553 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6554 | } |
| 6555 | if (_PyObject_LookupAttrId(obj, &PyId_operand, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6556 | return 1; |
| 6557 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6558 | if (tmp == NULL) { |
| 6559 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 6560 | return 1; |
| 6561 | } |
| 6562 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6563 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6564 | res = obj2ast_expr(tmp, &operand, arena); |
| 6565 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6566 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6567 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6568 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 6569 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6570 | if (*out == NULL) goto failed; |
| 6571 | return 0; |
| 6572 | } |
| 6573 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 6574 | if (isinstance == -1) { |
| 6575 | return 1; |
| 6576 | } |
| 6577 | if (isinstance) { |
| 6578 | arguments_ty args; |
| 6579 | expr_ty body; |
| 6580 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6581 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
| 6582 | return 1; |
| 6583 | } |
| 6584 | if (tmp == NULL) { |
| 6585 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 6586 | return 1; |
| 6587 | } |
| 6588 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6589 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6590 | res = obj2ast_arguments(tmp, &args, arena); |
| 6591 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6592 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6593 | } |
| 6594 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6595 | return 1; |
| 6596 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6597 | if (tmp == NULL) { |
| 6598 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 6599 | return 1; |
| 6600 | } |
| 6601 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6602 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6603 | res = obj2ast_expr(tmp, &body, arena); |
| 6604 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6605 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6606 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6607 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 6608 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6609 | if (*out == NULL) goto failed; |
| 6610 | return 0; |
| 6611 | } |
| 6612 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 6613 | if (isinstance == -1) { |
| 6614 | return 1; |
| 6615 | } |
| 6616 | if (isinstance) { |
| 6617 | expr_ty test; |
| 6618 | expr_ty body; |
| 6619 | expr_ty orelse; |
| 6620 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6621 | if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) { |
| 6622 | return 1; |
| 6623 | } |
| 6624 | if (tmp == NULL) { |
| 6625 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 6626 | return 1; |
| 6627 | } |
| 6628 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6629 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6630 | res = obj2ast_expr(tmp, &test, arena); |
| 6631 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6632 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6633 | } |
| 6634 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6635 | return 1; |
| 6636 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6637 | if (tmp == NULL) { |
| 6638 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 6639 | return 1; |
| 6640 | } |
| 6641 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6642 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6643 | res = obj2ast_expr(tmp, &body, arena); |
| 6644 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6645 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6646 | } |
| 6647 | if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6648 | return 1; |
| 6649 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6650 | if (tmp == NULL) { |
| 6651 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 6652 | return 1; |
| 6653 | } |
| 6654 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6655 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6656 | res = obj2ast_expr(tmp, &orelse, arena); |
| 6657 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6658 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6659 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6660 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 6661 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6662 | if (*out == NULL) goto failed; |
| 6663 | return 0; |
| 6664 | } |
| 6665 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 6666 | if (isinstance == -1) { |
| 6667 | return 1; |
| 6668 | } |
| 6669 | if (isinstance) { |
| 6670 | asdl_seq* keys; |
| 6671 | asdl_seq* values; |
| 6672 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6673 | if (_PyObject_LookupAttrId(obj, &PyId_keys, &tmp) < 0) { |
| 6674 | return 1; |
| 6675 | } |
| 6676 | if (tmp == NULL) { |
| 6677 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 6678 | return 1; |
| 6679 | } |
| 6680 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6681 | int res; |
| 6682 | Py_ssize_t len; |
| 6683 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6684 | if (!PyList_Check(tmp)) { |
| 6685 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6686 | goto failed; |
| 6687 | } |
| 6688 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6689 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6690 | if (keys == NULL) goto failed; |
| 6691 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6692 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6693 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6694 | Py_INCREF(tmp2); |
| 6695 | res = obj2ast_expr(tmp2, &val, arena); |
| 6696 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6697 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6698 | if (len != PyList_GET_SIZE(tmp)) { |
| 6699 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 6700 | goto failed; |
| 6701 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6702 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6703 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6704 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6705 | } |
| 6706 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6707 | return 1; |
| 6708 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6709 | if (tmp == NULL) { |
| 6710 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 6711 | return 1; |
| 6712 | } |
| 6713 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6714 | int res; |
| 6715 | Py_ssize_t len; |
| 6716 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6717 | if (!PyList_Check(tmp)) { |
| 6718 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6719 | goto failed; |
| 6720 | } |
| 6721 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6722 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6723 | if (values == NULL) goto failed; |
| 6724 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6725 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6726 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6727 | Py_INCREF(tmp2); |
| 6728 | res = obj2ast_expr(tmp2, &val, arena); |
| 6729 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6730 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6731 | if (len != PyList_GET_SIZE(tmp)) { |
| 6732 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 6733 | goto failed; |
| 6734 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6735 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6736 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6737 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6738 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6739 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 6740 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6741 | if (*out == NULL) goto failed; |
| 6742 | return 0; |
| 6743 | } |
| 6744 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 6745 | if (isinstance == -1) { |
| 6746 | return 1; |
| 6747 | } |
| 6748 | if (isinstance) { |
| 6749 | asdl_seq* elts; |
| 6750 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6751 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 6752 | return 1; |
| 6753 | } |
| 6754 | if (tmp == NULL) { |
| 6755 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 6756 | return 1; |
| 6757 | } |
| 6758 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6759 | int res; |
| 6760 | Py_ssize_t len; |
| 6761 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6762 | if (!PyList_Check(tmp)) { |
| 6763 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6764 | goto failed; |
| 6765 | } |
| 6766 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6767 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6768 | if (elts == NULL) goto failed; |
| 6769 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6770 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6771 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6772 | Py_INCREF(tmp2); |
| 6773 | res = obj2ast_expr(tmp2, &val, arena); |
| 6774 | Py_DECREF(tmp2); |
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, "Set field \"elts\" 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(elts, 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 = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6785 | if (*out == NULL) goto failed; |
| 6786 | return 0; |
| 6787 | } |
| 6788 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 6789 | if (isinstance == -1) { |
| 6790 | return 1; |
| 6791 | } |
| 6792 | if (isinstance) { |
| 6793 | expr_ty elt; |
| 6794 | asdl_seq* generators; |
| 6795 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6796 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6797 | return 1; |
| 6798 | } |
| 6799 | if (tmp == NULL) { |
| 6800 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 6801 | return 1; |
| 6802 | } |
| 6803 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6804 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6805 | res = obj2ast_expr(tmp, &elt, arena); |
| 6806 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6807 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6808 | } |
| 6809 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6810 | return 1; |
| 6811 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6812 | if (tmp == NULL) { |
| 6813 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 6814 | return 1; |
| 6815 | } |
| 6816 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6817 | int res; |
| 6818 | Py_ssize_t len; |
| 6819 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6820 | if (!PyList_Check(tmp)) { |
| 6821 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6822 | goto failed; |
| 6823 | } |
| 6824 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6825 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6826 | if (generators == NULL) goto failed; |
| 6827 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6828 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6829 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6830 | Py_INCREF(tmp2); |
| 6831 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 6832 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6833 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6834 | if (len != PyList_GET_SIZE(tmp)) { |
| 6835 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 6836 | goto failed; |
| 6837 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6838 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6839 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6840 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6841 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6842 | *out = ListComp(elt, generators, lineno, col_offset, end_lineno, |
| 6843 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6844 | if (*out == NULL) goto failed; |
| 6845 | return 0; |
| 6846 | } |
| 6847 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 6848 | if (isinstance == -1) { |
| 6849 | return 1; |
| 6850 | } |
| 6851 | if (isinstance) { |
| 6852 | expr_ty elt; |
| 6853 | asdl_seq* generators; |
| 6854 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6855 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6856 | return 1; |
| 6857 | } |
| 6858 | if (tmp == NULL) { |
| 6859 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 6860 | return 1; |
| 6861 | } |
| 6862 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6863 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6864 | res = obj2ast_expr(tmp, &elt, arena); |
| 6865 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6866 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6867 | } |
| 6868 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6869 | return 1; |
| 6870 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6871 | if (tmp == NULL) { |
| 6872 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 6873 | return 1; |
| 6874 | } |
| 6875 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6876 | int res; |
| 6877 | Py_ssize_t len; |
| 6878 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6879 | if (!PyList_Check(tmp)) { |
| 6880 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6881 | goto failed; |
| 6882 | } |
| 6883 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6884 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6885 | if (generators == NULL) goto failed; |
| 6886 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6887 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6888 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6889 | Py_INCREF(tmp2); |
| 6890 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 6891 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6892 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6893 | if (len != PyList_GET_SIZE(tmp)) { |
| 6894 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 6895 | goto failed; |
| 6896 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6897 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6898 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6899 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6900 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6901 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 6902 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6903 | if (*out == NULL) goto failed; |
| 6904 | return 0; |
| 6905 | } |
| 6906 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 6907 | if (isinstance == -1) { |
| 6908 | return 1; |
| 6909 | } |
| 6910 | if (isinstance) { |
| 6911 | expr_ty key; |
| 6912 | expr_ty value; |
| 6913 | asdl_seq* generators; |
| 6914 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6915 | if (_PyObject_LookupAttrId(obj, &PyId_key, &tmp) < 0) { |
| 6916 | return 1; |
| 6917 | } |
| 6918 | if (tmp == NULL) { |
| 6919 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 6920 | return 1; |
| 6921 | } |
| 6922 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6923 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6924 | res = obj2ast_expr(tmp, &key, arena); |
| 6925 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6926 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6927 | } |
| 6928 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6929 | return 1; |
| 6930 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6931 | if (tmp == NULL) { |
| 6932 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 6933 | return 1; |
| 6934 | } |
| 6935 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6936 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6937 | res = obj2ast_expr(tmp, &value, arena); |
| 6938 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6939 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6940 | } |
| 6941 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6942 | return 1; |
| 6943 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6944 | if (tmp == NULL) { |
| 6945 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 6946 | return 1; |
| 6947 | } |
| 6948 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6949 | int res; |
| 6950 | Py_ssize_t len; |
| 6951 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6952 | if (!PyList_Check(tmp)) { |
| 6953 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6954 | goto failed; |
| 6955 | } |
| 6956 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6957 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6958 | if (generators == NULL) goto failed; |
| 6959 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6960 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6961 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6962 | Py_INCREF(tmp2); |
| 6963 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 6964 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6965 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6966 | if (len != PyList_GET_SIZE(tmp)) { |
| 6967 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 6968 | goto failed; |
| 6969 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6970 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6971 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6972 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6973 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6974 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 6975 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6976 | if (*out == NULL) goto failed; |
| 6977 | return 0; |
| 6978 | } |
| 6979 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 6980 | if (isinstance == -1) { |
| 6981 | return 1; |
| 6982 | } |
| 6983 | if (isinstance) { |
| 6984 | expr_ty elt; |
| 6985 | asdl_seq* generators; |
| 6986 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6987 | if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) { |
| 6988 | return 1; |
| 6989 | } |
| 6990 | if (tmp == NULL) { |
| 6991 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 6992 | return 1; |
| 6993 | } |
| 6994 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6995 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6996 | res = obj2ast_expr(tmp, &elt, arena); |
| 6997 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6998 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6999 | } |
| 7000 | if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7001 | return 1; |
| 7002 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7003 | if (tmp == NULL) { |
| 7004 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 7005 | return 1; |
| 7006 | } |
| 7007 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7008 | int res; |
| 7009 | Py_ssize_t len; |
| 7010 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7011 | if (!PyList_Check(tmp)) { |
| 7012 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7013 | goto failed; |
| 7014 | } |
| 7015 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7016 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7017 | if (generators == NULL) goto failed; |
| 7018 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7019 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7020 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7021 | Py_INCREF(tmp2); |
| 7022 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7023 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7024 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7025 | if (len != PyList_GET_SIZE(tmp)) { |
| 7026 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 7027 | goto failed; |
| 7028 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7029 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7030 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7031 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7032 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7033 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 7034 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7035 | if (*out == NULL) goto failed; |
| 7036 | return 0; |
| 7037 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7038 | isinstance = PyObject_IsInstance(obj, (PyObject*)Await_type); |
| 7039 | if (isinstance == -1) { |
| 7040 | return 1; |
| 7041 | } |
| 7042 | if (isinstance) { |
| 7043 | expr_ty value; |
| 7044 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7045 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7046 | return 1; |
| 7047 | } |
| 7048 | if (tmp == NULL) { |
| 7049 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 7050 | return 1; |
| 7051 | } |
| 7052 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7053 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7054 | res = obj2ast_expr(tmp, &value, arena); |
| 7055 | if (res != 0) goto failed; |
| 7056 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7057 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7058 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7059 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7060 | if (*out == NULL) goto failed; |
| 7061 | return 0; |
| 7062 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7063 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 7064 | if (isinstance == -1) { |
| 7065 | return 1; |
| 7066 | } |
| 7067 | if (isinstance) { |
| 7068 | expr_ty value; |
| 7069 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7070 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7071 | return 1; |
| 7072 | } |
| 7073 | if (tmp == NULL || tmp == Py_None) { |
| 7074 | Py_CLEAR(tmp); |
| 7075 | value = NULL; |
| 7076 | } |
| 7077 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7078 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7079 | res = obj2ast_expr(tmp, &value, arena); |
| 7080 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7081 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7082 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7083 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7084 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7085 | if (*out == NULL) goto failed; |
| 7086 | return 0; |
| 7087 | } |
| 7088 | isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); |
| 7089 | if (isinstance == -1) { |
| 7090 | return 1; |
| 7091 | } |
| 7092 | if (isinstance) { |
| 7093 | expr_ty value; |
| 7094 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7095 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7096 | return 1; |
| 7097 | } |
| 7098 | if (tmp == NULL) { |
| 7099 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 7100 | return 1; |
| 7101 | } |
| 7102 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7103 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7104 | res = obj2ast_expr(tmp, &value, arena); |
| 7105 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7106 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7107 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7108 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7109 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7110 | if (*out == NULL) goto failed; |
| 7111 | return 0; |
| 7112 | } |
| 7113 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 7114 | if (isinstance == -1) { |
| 7115 | return 1; |
| 7116 | } |
| 7117 | if (isinstance) { |
| 7118 | expr_ty left; |
| 7119 | asdl_int_seq* ops; |
| 7120 | asdl_seq* comparators; |
| 7121 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7122 | if (_PyObject_LookupAttrId(obj, &PyId_left, &tmp) < 0) { |
| 7123 | return 1; |
| 7124 | } |
| 7125 | if (tmp == NULL) { |
| 7126 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 7127 | return 1; |
| 7128 | } |
| 7129 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7130 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7131 | res = obj2ast_expr(tmp, &left, arena); |
| 7132 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7133 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7134 | } |
| 7135 | if (_PyObject_LookupAttrId(obj, &PyId_ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7136 | return 1; |
| 7137 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7138 | if (tmp == NULL) { |
| 7139 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 7140 | return 1; |
| 7141 | } |
| 7142 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7143 | int res; |
| 7144 | Py_ssize_t len; |
| 7145 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7146 | if (!PyList_Check(tmp)) { |
| 7147 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7148 | goto failed; |
| 7149 | } |
| 7150 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7151 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7152 | if (ops == NULL) goto failed; |
| 7153 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7154 | cmpop_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7155 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7156 | Py_INCREF(tmp2); |
| 7157 | res = obj2ast_cmpop(tmp2, &val, arena); |
| 7158 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7159 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7160 | if (len != PyList_GET_SIZE(tmp)) { |
| 7161 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 7162 | goto failed; |
| 7163 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7164 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7165 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7166 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7167 | } |
| 7168 | if (_PyObject_LookupAttrId(obj, &PyId_comparators, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7169 | return 1; |
| 7170 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7171 | if (tmp == NULL) { |
| 7172 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 7173 | return 1; |
| 7174 | } |
| 7175 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7176 | int res; |
| 7177 | Py_ssize_t len; |
| 7178 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7179 | if (!PyList_Check(tmp)) { |
| 7180 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7181 | goto failed; |
| 7182 | } |
| 7183 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7184 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7185 | if (comparators == NULL) goto failed; |
| 7186 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7187 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7188 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7189 | Py_INCREF(tmp2); |
| 7190 | res = obj2ast_expr(tmp2, &val, arena); |
| 7191 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7192 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7193 | if (len != PyList_GET_SIZE(tmp)) { |
| 7194 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 7195 | goto failed; |
| 7196 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7197 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7198 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7199 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7200 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7201 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 7202 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7203 | if (*out == NULL) goto failed; |
| 7204 | return 0; |
| 7205 | } |
| 7206 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 7207 | if (isinstance == -1) { |
| 7208 | return 1; |
| 7209 | } |
| 7210 | if (isinstance) { |
| 7211 | expr_ty func; |
| 7212 | asdl_seq* args; |
| 7213 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7214 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7215 | if (_PyObject_LookupAttrId(obj, &PyId_func, &tmp) < 0) { |
| 7216 | return 1; |
| 7217 | } |
| 7218 | if (tmp == NULL) { |
| 7219 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 7220 | return 1; |
| 7221 | } |
| 7222 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7223 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7224 | res = obj2ast_expr(tmp, &func, arena); |
| 7225 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7226 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7227 | } |
| 7228 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7229 | return 1; |
| 7230 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7231 | if (tmp == NULL) { |
| 7232 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 7233 | return 1; |
| 7234 | } |
| 7235 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7236 | int res; |
| 7237 | Py_ssize_t len; |
| 7238 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7239 | if (!PyList_Check(tmp)) { |
| 7240 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7241 | goto failed; |
| 7242 | } |
| 7243 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7244 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7245 | if (args == NULL) goto failed; |
| 7246 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7247 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7248 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7249 | Py_INCREF(tmp2); |
| 7250 | res = obj2ast_expr(tmp2, &val, arena); |
| 7251 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7252 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7253 | if (len != PyList_GET_SIZE(tmp)) { |
| 7254 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 7255 | goto failed; |
| 7256 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7257 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7258 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7259 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7260 | } |
| 7261 | if (_PyObject_LookupAttrId(obj, &PyId_keywords, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7262 | return 1; |
| 7263 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7264 | if (tmp == NULL) { |
| 7265 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 7266 | return 1; |
| 7267 | } |
| 7268 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7269 | int res; |
| 7270 | Py_ssize_t len; |
| 7271 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7272 | if (!PyList_Check(tmp)) { |
| 7273 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7274 | goto failed; |
| 7275 | } |
| 7276 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7277 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7278 | if (keywords == NULL) goto failed; |
| 7279 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7280 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7281 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7282 | Py_INCREF(tmp2); |
| 7283 | res = obj2ast_keyword(tmp2, &val, arena); |
| 7284 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7285 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7286 | if (len != PyList_GET_SIZE(tmp)) { |
| 7287 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 7288 | goto failed; |
| 7289 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7290 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7291 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7292 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7293 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7294 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 7295 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7296 | if (*out == NULL) goto failed; |
| 7297 | return 0; |
| 7298 | } |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7299 | isinstance = PyObject_IsInstance(obj, (PyObject*)FormattedValue_type); |
| 7300 | if (isinstance == -1) { |
| 7301 | return 1; |
| 7302 | } |
| 7303 | if (isinstance) { |
| 7304 | expr_ty value; |
| 7305 | int conversion; |
| 7306 | expr_ty format_spec; |
| 7307 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7308 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7309 | return 1; |
| 7310 | } |
| 7311 | if (tmp == NULL) { |
| 7312 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 7313 | return 1; |
| 7314 | } |
| 7315 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7316 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7317 | res = obj2ast_expr(tmp, &value, arena); |
| 7318 | if (res != 0) goto failed; |
| 7319 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7320 | } |
| 7321 | if (_PyObject_LookupAttrId(obj, &PyId_conversion, &tmp) < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7322 | return 1; |
| 7323 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7324 | if (tmp == NULL || tmp == Py_None) { |
| 7325 | Py_CLEAR(tmp); |
| 7326 | conversion = 0; |
| 7327 | } |
| 7328 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7329 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7330 | res = obj2ast_int(tmp, &conversion, arena); |
| 7331 | if (res != 0) goto failed; |
| 7332 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7333 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7334 | if (_PyObject_LookupAttrId(obj, &PyId_format_spec, &tmp) < 0) { |
| 7335 | return 1; |
| 7336 | } |
| 7337 | if (tmp == NULL || tmp == Py_None) { |
| 7338 | Py_CLEAR(tmp); |
| 7339 | format_spec = NULL; |
| 7340 | } |
| 7341 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7342 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7343 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 7344 | if (res != 0) goto failed; |
| 7345 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7346 | } |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 7347 | *out = FormattedValue(value, conversion, format_spec, lineno, |
| 7348 | col_offset, end_lineno, end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7349 | if (*out == NULL) goto failed; |
| 7350 | return 0; |
| 7351 | } |
| 7352 | isinstance = PyObject_IsInstance(obj, (PyObject*)JoinedStr_type); |
| 7353 | if (isinstance == -1) { |
| 7354 | return 1; |
| 7355 | } |
| 7356 | if (isinstance) { |
| 7357 | asdl_seq* values; |
| 7358 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7359 | if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) { |
| 7360 | return 1; |
| 7361 | } |
| 7362 | if (tmp == NULL) { |
| 7363 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 7364 | return 1; |
| 7365 | } |
| 7366 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7367 | int res; |
| 7368 | Py_ssize_t len; |
| 7369 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7370 | if (!PyList_Check(tmp)) { |
| 7371 | PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7372 | goto failed; |
| 7373 | } |
| 7374 | len = PyList_GET_SIZE(tmp); |
| 7375 | values = _Py_asdl_seq_new(len, arena); |
| 7376 | if (values == NULL) goto failed; |
| 7377 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7378 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7379 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7380 | Py_INCREF(tmp2); |
| 7381 | res = obj2ast_expr(tmp2, &val, arena); |
| 7382 | Py_DECREF(tmp2); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7383 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 7384 | if (len != PyList_GET_SIZE(tmp)) { |
| 7385 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 7386 | goto failed; |
| 7387 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7388 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7389 | } |
| 7390 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7391 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7392 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 7393 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7394 | if (*out == NULL) goto failed; |
| 7395 | return 0; |
| 7396 | } |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7397 | isinstance = PyObject_IsInstance(obj, (PyObject*)Constant_type); |
| 7398 | if (isinstance == -1) { |
| 7399 | return 1; |
| 7400 | } |
| 7401 | if (isinstance) { |
| 7402 | constant value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 7403 | string kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7404 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7405 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7406 | return 1; |
| 7407 | } |
| 7408 | if (tmp == NULL) { |
| 7409 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 7410 | return 1; |
| 7411 | } |
| 7412 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7413 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7414 | res = obj2ast_constant(tmp, &value, arena); |
| 7415 | if (res != 0) goto failed; |
| 7416 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7417 | } |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 7418 | if (_PyObject_LookupAttrId(obj, &PyId_kind, &tmp) < 0) { |
| 7419 | return 1; |
| 7420 | } |
| 7421 | if (tmp == NULL || tmp == Py_None) { |
| 7422 | Py_CLEAR(tmp); |
| 7423 | kind = NULL; |
| 7424 | } |
| 7425 | else { |
| 7426 | int res; |
| 7427 | res = obj2ast_string(tmp, &kind, arena); |
| 7428 | if (res != 0) goto failed; |
| 7429 | Py_CLEAR(tmp); |
| 7430 | } |
| 7431 | *out = Constant(value, kind, lineno, col_offset, end_lineno, |
| 7432 | end_col_offset, arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 7433 | if (*out == NULL) goto failed; |
| 7434 | return 0; |
| 7435 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7436 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 7437 | if (isinstance == -1) { |
| 7438 | return 1; |
| 7439 | } |
| 7440 | if (isinstance) { |
| 7441 | expr_ty value; |
| 7442 | identifier attr; |
| 7443 | expr_context_ty ctx; |
| 7444 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7445 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7446 | return 1; |
| 7447 | } |
| 7448 | if (tmp == NULL) { |
| 7449 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 7450 | return 1; |
| 7451 | } |
| 7452 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7453 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7454 | res = obj2ast_expr(tmp, &value, arena); |
| 7455 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7456 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7457 | } |
| 7458 | if (_PyObject_LookupAttrId(obj, &PyId_attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7459 | return 1; |
| 7460 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7461 | if (tmp == NULL) { |
| 7462 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 7463 | return 1; |
| 7464 | } |
| 7465 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7466 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7467 | res = obj2ast_identifier(tmp, &attr, arena); |
| 7468 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7469 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7470 | } |
| 7471 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7472 | return 1; |
| 7473 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7474 | if (tmp == NULL) { |
| 7475 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 7476 | return 1; |
| 7477 | } |
| 7478 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7479 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7480 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7481 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7482 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7483 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7484 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 7485 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7486 | if (*out == NULL) goto failed; |
| 7487 | return 0; |
| 7488 | } |
| 7489 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 7490 | if (isinstance == -1) { |
| 7491 | return 1; |
| 7492 | } |
| 7493 | if (isinstance) { |
| 7494 | expr_ty value; |
| 7495 | slice_ty slice; |
| 7496 | expr_context_ty ctx; |
| 7497 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7498 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7499 | return 1; |
| 7500 | } |
| 7501 | if (tmp == NULL) { |
| 7502 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 7503 | return 1; |
| 7504 | } |
| 7505 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7506 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7507 | res = obj2ast_expr(tmp, &value, arena); |
| 7508 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7509 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7510 | } |
| 7511 | if (_PyObject_LookupAttrId(obj, &PyId_slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7512 | return 1; |
| 7513 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7514 | if (tmp == NULL) { |
| 7515 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 7516 | return 1; |
| 7517 | } |
| 7518 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7519 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7520 | res = obj2ast_slice(tmp, &slice, arena); |
| 7521 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7522 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7523 | } |
| 7524 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7525 | return 1; |
| 7526 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7527 | if (tmp == NULL) { |
| 7528 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 7529 | return 1; |
| 7530 | } |
| 7531 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7532 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7533 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7534 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7535 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7536 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7537 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 7538 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7539 | if (*out == NULL) goto failed; |
| 7540 | return 0; |
| 7541 | } |
| 7542 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 7543 | if (isinstance == -1) { |
| 7544 | return 1; |
| 7545 | } |
| 7546 | if (isinstance) { |
| 7547 | expr_ty value; |
| 7548 | expr_context_ty ctx; |
| 7549 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7550 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7551 | return 1; |
| 7552 | } |
| 7553 | if (tmp == NULL) { |
| 7554 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 7555 | return 1; |
| 7556 | } |
| 7557 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7558 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7559 | res = obj2ast_expr(tmp, &value, arena); |
| 7560 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7561 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7562 | } |
| 7563 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7564 | return 1; |
| 7565 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7566 | if (tmp == NULL) { |
| 7567 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 7568 | return 1; |
| 7569 | } |
| 7570 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7571 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7572 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7573 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7574 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7575 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7576 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 7577 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7578 | if (*out == NULL) goto failed; |
| 7579 | return 0; |
| 7580 | } |
| 7581 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 7582 | if (isinstance == -1) { |
| 7583 | return 1; |
| 7584 | } |
| 7585 | if (isinstance) { |
| 7586 | identifier id; |
| 7587 | expr_context_ty ctx; |
| 7588 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7589 | if (_PyObject_LookupAttrId(obj, &PyId_id, &tmp) < 0) { |
| 7590 | return 1; |
| 7591 | } |
| 7592 | if (tmp == NULL) { |
| 7593 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 7594 | return 1; |
| 7595 | } |
| 7596 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7597 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7598 | res = obj2ast_identifier(tmp, &id, arena); |
| 7599 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7600 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7601 | } |
| 7602 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7603 | return 1; |
| 7604 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7605 | if (tmp == NULL) { |
| 7606 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 7607 | return 1; |
| 7608 | } |
| 7609 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7610 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7611 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7612 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7613 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7614 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7615 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7616 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7617 | if (*out == NULL) goto failed; |
| 7618 | return 0; |
| 7619 | } |
| 7620 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 7621 | if (isinstance == -1) { |
| 7622 | return 1; |
| 7623 | } |
| 7624 | if (isinstance) { |
| 7625 | asdl_seq* elts; |
| 7626 | expr_context_ty ctx; |
| 7627 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7628 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 7629 | return 1; |
| 7630 | } |
| 7631 | if (tmp == NULL) { |
| 7632 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 7633 | return 1; |
| 7634 | } |
| 7635 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7636 | int res; |
| 7637 | Py_ssize_t len; |
| 7638 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7639 | if (!PyList_Check(tmp)) { |
| 7640 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7641 | goto failed; |
| 7642 | } |
| 7643 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7644 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7645 | if (elts == NULL) goto failed; |
| 7646 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7647 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7648 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7649 | Py_INCREF(tmp2); |
| 7650 | res = obj2ast_expr(tmp2, &val, arena); |
| 7651 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7652 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7653 | if (len != PyList_GET_SIZE(tmp)) { |
| 7654 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 7655 | goto failed; |
| 7656 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7657 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7658 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7659 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7660 | } |
| 7661 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7662 | return 1; |
| 7663 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7664 | if (tmp == NULL) { |
| 7665 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 7666 | return 1; |
| 7667 | } |
| 7668 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7669 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7670 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7671 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7672 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7673 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7674 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7675 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7676 | if (*out == NULL) goto failed; |
| 7677 | return 0; |
| 7678 | } |
| 7679 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 7680 | if (isinstance == -1) { |
| 7681 | return 1; |
| 7682 | } |
| 7683 | if (isinstance) { |
| 7684 | asdl_seq* elts; |
| 7685 | expr_context_ty ctx; |
| 7686 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7687 | if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) { |
| 7688 | return 1; |
| 7689 | } |
| 7690 | if (tmp == NULL) { |
| 7691 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 7692 | return 1; |
| 7693 | } |
| 7694 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7695 | int res; |
| 7696 | Py_ssize_t len; |
| 7697 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7698 | if (!PyList_Check(tmp)) { |
| 7699 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7700 | goto failed; |
| 7701 | } |
| 7702 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7703 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7704 | if (elts == NULL) goto failed; |
| 7705 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7706 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7707 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7708 | Py_INCREF(tmp2); |
| 7709 | res = obj2ast_expr(tmp2, &val, arena); |
| 7710 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7711 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7712 | if (len != PyList_GET_SIZE(tmp)) { |
| 7713 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 7714 | goto failed; |
| 7715 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7716 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7717 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7718 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7719 | } |
| 7720 | if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7721 | return 1; |
| 7722 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7723 | if (tmp == NULL) { |
| 7724 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 7725 | return 1; |
| 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_context(tmp, &ctx, 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 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7733 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 7734 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7735 | if (*out == NULL) goto failed; |
| 7736 | return 0; |
| 7737 | } |
| 7738 | |
| 7739 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 7740 | failed: |
| 7741 | Py_XDECREF(tmp); |
| 7742 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7743 | } |
| 7744 | |
| 7745 | int |
| 7746 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 7747 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7748 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7749 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7750 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 7751 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7752 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7753 | } |
| 7754 | if (isinstance) { |
| 7755 | *out = Load; |
| 7756 | return 0; |
| 7757 | } |
| 7758 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 7759 | if (isinstance == -1) { |
| 7760 | return 1; |
| 7761 | } |
| 7762 | if (isinstance) { |
| 7763 | *out = Store; |
| 7764 | return 0; |
| 7765 | } |
| 7766 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 7767 | if (isinstance == -1) { |
| 7768 | return 1; |
| 7769 | } |
| 7770 | if (isinstance) { |
| 7771 | *out = Del; |
| 7772 | return 0; |
| 7773 | } |
| 7774 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 7775 | if (isinstance == -1) { |
| 7776 | return 1; |
| 7777 | } |
| 7778 | if (isinstance) { |
| 7779 | *out = AugLoad; |
| 7780 | return 0; |
| 7781 | } |
| 7782 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 7783 | if (isinstance == -1) { |
| 7784 | return 1; |
| 7785 | } |
| 7786 | if (isinstance) { |
| 7787 | *out = AugStore; |
| 7788 | return 0; |
| 7789 | } |
| 7790 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 7791 | if (isinstance == -1) { |
| 7792 | return 1; |
| 7793 | } |
| 7794 | if (isinstance) { |
| 7795 | *out = Param; |
| 7796 | return 0; |
| 7797 | } |
| 7798 | |
| 7799 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 7800 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7801 | } |
| 7802 | |
| 7803 | int |
| 7804 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 7805 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7806 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7807 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7808 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7809 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7810 | if (obj == Py_None) { |
| 7811 | *out = NULL; |
| 7812 | return 0; |
| 7813 | } |
| 7814 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_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 | expr_ty lower; |
| 7820 | expr_ty upper; |
| 7821 | expr_ty step; |
| 7822 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7823 | if (_PyObject_LookupAttrId(obj, &PyId_lower, &tmp) < 0) { |
| 7824 | return 1; |
| 7825 | } |
| 7826 | if (tmp == NULL || tmp == Py_None) { |
| 7827 | Py_CLEAR(tmp); |
| 7828 | lower = NULL; |
| 7829 | } |
| 7830 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7831 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7832 | res = obj2ast_expr(tmp, &lower, arena); |
| 7833 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7834 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7835 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7836 | if (_PyObject_LookupAttrId(obj, &PyId_upper, &tmp) < 0) { |
| 7837 | return 1; |
| 7838 | } |
| 7839 | if (tmp == NULL || tmp == Py_None) { |
| 7840 | Py_CLEAR(tmp); |
| 7841 | upper = NULL; |
| 7842 | } |
| 7843 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7844 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7845 | res = obj2ast_expr(tmp, &upper, arena); |
| 7846 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7847 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7848 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7849 | if (_PyObject_LookupAttrId(obj, &PyId_step, &tmp) < 0) { |
| 7850 | return 1; |
| 7851 | } |
| 7852 | if (tmp == NULL || tmp == Py_None) { |
| 7853 | Py_CLEAR(tmp); |
| 7854 | step = NULL; |
| 7855 | } |
| 7856 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7857 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7858 | res = obj2ast_expr(tmp, &step, arena); |
| 7859 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7860 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7861 | } |
| 7862 | *out = Slice(lower, upper, step, arena); |
| 7863 | if (*out == NULL) goto failed; |
| 7864 | return 0; |
| 7865 | } |
| 7866 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 7867 | if (isinstance == -1) { |
| 7868 | return 1; |
| 7869 | } |
| 7870 | if (isinstance) { |
| 7871 | asdl_seq* dims; |
| 7872 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7873 | if (_PyObject_LookupAttrId(obj, &PyId_dims, &tmp) < 0) { |
| 7874 | return 1; |
| 7875 | } |
| 7876 | if (tmp == NULL) { |
| 7877 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 7878 | return 1; |
| 7879 | } |
| 7880 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7881 | int res; |
| 7882 | Py_ssize_t len; |
| 7883 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7884 | if (!PyList_Check(tmp)) { |
| 7885 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7886 | goto failed; |
| 7887 | } |
| 7888 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7889 | dims = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7890 | if (dims == NULL) goto failed; |
| 7891 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7892 | slice_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7893 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7894 | Py_INCREF(tmp2); |
| 7895 | res = obj2ast_slice(tmp2, &val, arena); |
| 7896 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7897 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7898 | if (len != PyList_GET_SIZE(tmp)) { |
| 7899 | PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration"); |
| 7900 | goto failed; |
| 7901 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7902 | asdl_seq_SET(dims, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7903 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7904 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7905 | } |
| 7906 | *out = ExtSlice(dims, arena); |
| 7907 | if (*out == NULL) goto failed; |
| 7908 | return 0; |
| 7909 | } |
| 7910 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 7911 | if (isinstance == -1) { |
| 7912 | return 1; |
| 7913 | } |
| 7914 | if (isinstance) { |
| 7915 | expr_ty value; |
| 7916 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7917 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 7918 | return 1; |
| 7919 | } |
| 7920 | if (tmp == NULL) { |
| 7921 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 7922 | return 1; |
| 7923 | } |
| 7924 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7925 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7926 | res = obj2ast_expr(tmp, &value, arena); |
| 7927 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7928 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7929 | } |
| 7930 | *out = Index(value, arena); |
| 7931 | if (*out == NULL) goto failed; |
| 7932 | return 0; |
| 7933 | } |
| 7934 | |
| 7935 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 7936 | failed: |
| 7937 | Py_XDECREF(tmp); |
| 7938 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7939 | } |
| 7940 | |
| 7941 | int |
| 7942 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 7943 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7944 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7945 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7946 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 7947 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7948 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7949 | } |
| 7950 | if (isinstance) { |
| 7951 | *out = And; |
| 7952 | return 0; |
| 7953 | } |
| 7954 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 7955 | if (isinstance == -1) { |
| 7956 | return 1; |
| 7957 | } |
| 7958 | if (isinstance) { |
| 7959 | *out = Or; |
| 7960 | return 0; |
| 7961 | } |
| 7962 | |
| 7963 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 7964 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7965 | } |
| 7966 | |
| 7967 | int |
| 7968 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 7969 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7970 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7971 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7972 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 7973 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7974 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7975 | } |
| 7976 | if (isinstance) { |
| 7977 | *out = Add; |
| 7978 | return 0; |
| 7979 | } |
| 7980 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 7981 | if (isinstance == -1) { |
| 7982 | return 1; |
| 7983 | } |
| 7984 | if (isinstance) { |
| 7985 | *out = Sub; |
| 7986 | return 0; |
| 7987 | } |
| 7988 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 7989 | if (isinstance == -1) { |
| 7990 | return 1; |
| 7991 | } |
| 7992 | if (isinstance) { |
| 7993 | *out = Mult; |
| 7994 | return 0; |
| 7995 | } |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 7996 | isinstance = PyObject_IsInstance(obj, (PyObject *)MatMult_type); |
| 7997 | if (isinstance == -1) { |
| 7998 | return 1; |
| 7999 | } |
| 8000 | if (isinstance) { |
| 8001 | *out = MatMult; |
| 8002 | return 0; |
| 8003 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8004 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 8005 | if (isinstance == -1) { |
| 8006 | return 1; |
| 8007 | } |
| 8008 | if (isinstance) { |
| 8009 | *out = Div; |
| 8010 | return 0; |
| 8011 | } |
| 8012 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 8013 | if (isinstance == -1) { |
| 8014 | return 1; |
| 8015 | } |
| 8016 | if (isinstance) { |
| 8017 | *out = Mod; |
| 8018 | return 0; |
| 8019 | } |
| 8020 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 8021 | if (isinstance == -1) { |
| 8022 | return 1; |
| 8023 | } |
| 8024 | if (isinstance) { |
| 8025 | *out = Pow; |
| 8026 | return 0; |
| 8027 | } |
| 8028 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 8029 | if (isinstance == -1) { |
| 8030 | return 1; |
| 8031 | } |
| 8032 | if (isinstance) { |
| 8033 | *out = LShift; |
| 8034 | return 0; |
| 8035 | } |
| 8036 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 8037 | if (isinstance == -1) { |
| 8038 | return 1; |
| 8039 | } |
| 8040 | if (isinstance) { |
| 8041 | *out = RShift; |
| 8042 | return 0; |
| 8043 | } |
| 8044 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 8045 | if (isinstance == -1) { |
| 8046 | return 1; |
| 8047 | } |
| 8048 | if (isinstance) { |
| 8049 | *out = BitOr; |
| 8050 | return 0; |
| 8051 | } |
| 8052 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 8053 | if (isinstance == -1) { |
| 8054 | return 1; |
| 8055 | } |
| 8056 | if (isinstance) { |
| 8057 | *out = BitXor; |
| 8058 | return 0; |
| 8059 | } |
| 8060 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 8061 | if (isinstance == -1) { |
| 8062 | return 1; |
| 8063 | } |
| 8064 | if (isinstance) { |
| 8065 | *out = BitAnd; |
| 8066 | return 0; |
| 8067 | } |
| 8068 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 8069 | if (isinstance == -1) { |
| 8070 | return 1; |
| 8071 | } |
| 8072 | if (isinstance) { |
| 8073 | *out = FloorDiv; |
| 8074 | return 0; |
| 8075 | } |
| 8076 | |
| 8077 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, 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_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 8083 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8084 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8085 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8086 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 8087 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8088 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8089 | } |
| 8090 | if (isinstance) { |
| 8091 | *out = Invert; |
| 8092 | return 0; |
| 8093 | } |
| 8094 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 8095 | if (isinstance == -1) { |
| 8096 | return 1; |
| 8097 | } |
| 8098 | if (isinstance) { |
| 8099 | *out = Not; |
| 8100 | return 0; |
| 8101 | } |
| 8102 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 8103 | if (isinstance == -1) { |
| 8104 | return 1; |
| 8105 | } |
| 8106 | if (isinstance) { |
| 8107 | *out = UAdd; |
| 8108 | return 0; |
| 8109 | } |
| 8110 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 8111 | if (isinstance == -1) { |
| 8112 | return 1; |
| 8113 | } |
| 8114 | if (isinstance) { |
| 8115 | *out = USub; |
| 8116 | return 0; |
| 8117 | } |
| 8118 | |
| 8119 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 8120 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8121 | } |
| 8122 | |
| 8123 | int |
| 8124 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 8125 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8126 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8127 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8128 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 8129 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8130 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8131 | } |
| 8132 | if (isinstance) { |
| 8133 | *out = Eq; |
| 8134 | return 0; |
| 8135 | } |
| 8136 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 8137 | if (isinstance == -1) { |
| 8138 | return 1; |
| 8139 | } |
| 8140 | if (isinstance) { |
| 8141 | *out = NotEq; |
| 8142 | return 0; |
| 8143 | } |
| 8144 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 8145 | if (isinstance == -1) { |
| 8146 | return 1; |
| 8147 | } |
| 8148 | if (isinstance) { |
| 8149 | *out = Lt; |
| 8150 | return 0; |
| 8151 | } |
| 8152 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 8153 | if (isinstance == -1) { |
| 8154 | return 1; |
| 8155 | } |
| 8156 | if (isinstance) { |
| 8157 | *out = LtE; |
| 8158 | return 0; |
| 8159 | } |
| 8160 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 8161 | if (isinstance == -1) { |
| 8162 | return 1; |
| 8163 | } |
| 8164 | if (isinstance) { |
| 8165 | *out = Gt; |
| 8166 | return 0; |
| 8167 | } |
| 8168 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 8169 | if (isinstance == -1) { |
| 8170 | return 1; |
| 8171 | } |
| 8172 | if (isinstance) { |
| 8173 | *out = GtE; |
| 8174 | return 0; |
| 8175 | } |
| 8176 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 8177 | if (isinstance == -1) { |
| 8178 | return 1; |
| 8179 | } |
| 8180 | if (isinstance) { |
| 8181 | *out = Is; |
| 8182 | return 0; |
| 8183 | } |
| 8184 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 8185 | if (isinstance == -1) { |
| 8186 | return 1; |
| 8187 | } |
| 8188 | if (isinstance) { |
| 8189 | *out = IsNot; |
| 8190 | return 0; |
| 8191 | } |
| 8192 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 8193 | if (isinstance == -1) { |
| 8194 | return 1; |
| 8195 | } |
| 8196 | if (isinstance) { |
| 8197 | *out = In; |
| 8198 | return 0; |
| 8199 | } |
| 8200 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 8201 | if (isinstance == -1) { |
| 8202 | return 1; |
| 8203 | } |
| 8204 | if (isinstance) { |
| 8205 | *out = NotIn; |
| 8206 | return 0; |
| 8207 | } |
| 8208 | |
| 8209 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 8210 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8211 | } |
| 8212 | |
| 8213 | int |
| 8214 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 8215 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8216 | PyObject* tmp = NULL; |
| 8217 | expr_ty target; |
| 8218 | expr_ty iter; |
| 8219 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8220 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8221 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8222 | if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) { |
| 8223 | return 1; |
| 8224 | } |
| 8225 | if (tmp == NULL) { |
| 8226 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 8227 | return 1; |
| 8228 | } |
| 8229 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8230 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8231 | res = obj2ast_expr(tmp, &target, arena); |
| 8232 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8233 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8234 | } |
| 8235 | if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8236 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8237 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8238 | if (tmp == NULL) { |
| 8239 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 8240 | return 1; |
| 8241 | } |
| 8242 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8243 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8244 | res = obj2ast_expr(tmp, &iter, arena); |
| 8245 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8246 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8247 | } |
| 8248 | if (_PyObject_LookupAttrId(obj, &PyId_ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8249 | return 1; |
| 8250 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8251 | if (tmp == NULL) { |
| 8252 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 8253 | return 1; |
| 8254 | } |
| 8255 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8256 | int res; |
| 8257 | Py_ssize_t len; |
| 8258 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8259 | if (!PyList_Check(tmp)) { |
| 8260 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8261 | goto failed; |
| 8262 | } |
| 8263 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8264 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8265 | if (ifs == NULL) goto failed; |
| 8266 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8267 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8268 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8269 | Py_INCREF(tmp2); |
| 8270 | res = obj2ast_expr(tmp2, &val, arena); |
| 8271 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8272 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8273 | if (len != PyList_GET_SIZE(tmp)) { |
| 8274 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 8275 | goto failed; |
| 8276 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8277 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8278 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8279 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8280 | } |
| 8281 | if (_PyObject_LookupAttrId(obj, &PyId_is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8282 | return 1; |
| 8283 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8284 | if (tmp == NULL) { |
| 8285 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 8286 | return 1; |
| 8287 | } |
| 8288 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8289 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8290 | res = obj2ast_int(tmp, &is_async, arena); |
| 8291 | if (res != 0) goto failed; |
| 8292 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8293 | } |
| 8294 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8295 | return 0; |
| 8296 | failed: |
| 8297 | Py_XDECREF(tmp); |
| 8298 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8299 | } |
| 8300 | |
| 8301 | int |
| 8302 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 8303 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8304 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 8305 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8306 | PyObject *tmp = NULL; |
| 8307 | int lineno; |
| 8308 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8309 | int end_lineno; |
| 8310 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8311 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8312 | if (obj == Py_None) { |
| 8313 | *out = NULL; |
| 8314 | return 0; |
| 8315 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8316 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 8317 | return 1; |
| 8318 | } |
| 8319 | if (tmp == NULL) { |
| 8320 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 8321 | return 1; |
| 8322 | } |
| 8323 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8324 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8325 | res = obj2ast_int(tmp, &lineno, arena); |
| 8326 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8327 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8328 | } |
| 8329 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8330 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8331 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8332 | if (tmp == NULL) { |
| 8333 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 8334 | return 1; |
| 8335 | } |
| 8336 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8337 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8338 | res = obj2ast_int(tmp, &col_offset, arena); |
| 8339 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8340 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8341 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8342 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 8343 | return 1; |
| 8344 | } |
| 8345 | if (tmp == NULL || tmp == Py_None) { |
| 8346 | Py_CLEAR(tmp); |
| 8347 | end_lineno = 0; |
| 8348 | } |
| 8349 | else { |
| 8350 | int res; |
| 8351 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 8352 | if (res != 0) goto failed; |
| 8353 | Py_CLEAR(tmp); |
| 8354 | } |
| 8355 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 8356 | return 1; |
| 8357 | } |
| 8358 | if (tmp == NULL || tmp == Py_None) { |
| 8359 | Py_CLEAR(tmp); |
| 8360 | end_col_offset = 0; |
| 8361 | } |
| 8362 | else { |
| 8363 | int res; |
| 8364 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 8365 | if (res != 0) goto failed; |
| 8366 | Py_CLEAR(tmp); |
| 8367 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8368 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 8369 | if (isinstance == -1) { |
| 8370 | return 1; |
| 8371 | } |
| 8372 | if (isinstance) { |
| 8373 | expr_ty type; |
| 8374 | identifier name; |
| 8375 | asdl_seq* body; |
| 8376 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8377 | if (_PyObject_LookupAttrId(obj, &PyId_type, &tmp) < 0) { |
| 8378 | return 1; |
| 8379 | } |
| 8380 | if (tmp == NULL || tmp == Py_None) { |
| 8381 | Py_CLEAR(tmp); |
| 8382 | type = NULL; |
| 8383 | } |
| 8384 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8385 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8386 | res = obj2ast_expr(tmp, &type, arena); |
| 8387 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8388 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8389 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8390 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 8391 | return 1; |
| 8392 | } |
| 8393 | if (tmp == NULL || tmp == Py_None) { |
| 8394 | Py_CLEAR(tmp); |
| 8395 | name = NULL; |
| 8396 | } |
| 8397 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8398 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8399 | res = obj2ast_identifier(tmp, &name, arena); |
| 8400 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8401 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8402 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8403 | if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) { |
| 8404 | return 1; |
| 8405 | } |
| 8406 | if (tmp == NULL) { |
| 8407 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 8408 | return 1; |
| 8409 | } |
| 8410 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8411 | int res; |
| 8412 | Py_ssize_t len; |
| 8413 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8414 | if (!PyList_Check(tmp)) { |
| 8415 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8416 | goto failed; |
| 8417 | } |
| 8418 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8419 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8420 | if (body == NULL) goto failed; |
| 8421 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8422 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8423 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8424 | Py_INCREF(tmp2); |
| 8425 | res = obj2ast_stmt(tmp2, &val, arena); |
| 8426 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8427 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8428 | if (len != PyList_GET_SIZE(tmp)) { |
| 8429 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 8430 | goto failed; |
| 8431 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8432 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8433 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8434 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8435 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8436 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 8437 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8438 | if (*out == NULL) goto failed; |
| 8439 | return 0; |
| 8440 | } |
| 8441 | |
| 8442 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 8443 | failed: |
| 8444 | Py_XDECREF(tmp); |
| 8445 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8446 | } |
| 8447 | |
| 8448 | int |
| 8449 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 8450 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8451 | PyObject* tmp = NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 8452 | asdl_seq* posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 8453 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8454 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8455 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8456 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8457 | arg_ty kwarg; |
| 8458 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8459 | |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 8460 | if (_PyObject_LookupAttrId(obj, &PyId_posonlyargs, &tmp) < 0) { |
| 8461 | return 1; |
| 8462 | } |
| 8463 | if (tmp == NULL) { |
| 8464 | PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments"); |
| 8465 | return 1; |
| 8466 | } |
| 8467 | else { |
| 8468 | int res; |
| 8469 | Py_ssize_t len; |
| 8470 | Py_ssize_t i; |
| 8471 | if (!PyList_Check(tmp)) { |
| 8472 | PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8473 | goto failed; |
| 8474 | } |
| 8475 | len = PyList_GET_SIZE(tmp); |
| 8476 | posonlyargs = _Py_asdl_seq_new(len, arena); |
| 8477 | if (posonlyargs == NULL) goto failed; |
| 8478 | for (i = 0; i < len; i++) { |
| 8479 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8480 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8481 | Py_INCREF(tmp2); |
| 8482 | res = obj2ast_arg(tmp2, &val, arena); |
| 8483 | Py_DECREF(tmp2); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 8484 | if (res != 0) goto failed; |
| 8485 | if (len != PyList_GET_SIZE(tmp)) { |
| 8486 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration"); |
| 8487 | goto failed; |
| 8488 | } |
| 8489 | asdl_seq_SET(posonlyargs, i, val); |
| 8490 | } |
| 8491 | Py_CLEAR(tmp); |
| 8492 | } |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 8493 | if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) { |
| 8494 | return 1; |
| 8495 | } |
| 8496 | if (tmp == NULL) { |
| 8497 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 8498 | return 1; |
| 8499 | } |
| 8500 | else { |
| 8501 | int res; |
| 8502 | Py_ssize_t len; |
| 8503 | Py_ssize_t i; |
| 8504 | if (!PyList_Check(tmp)) { |
| 8505 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8506 | goto failed; |
| 8507 | } |
| 8508 | len = PyList_GET_SIZE(tmp); |
| 8509 | args = _Py_asdl_seq_new(len, arena); |
| 8510 | if (args == NULL) goto failed; |
| 8511 | for (i = 0; i < len; i++) { |
| 8512 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8513 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8514 | Py_INCREF(tmp2); |
| 8515 | res = obj2ast_arg(tmp2, &val, arena); |
| 8516 | Py_DECREF(tmp2); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 8517 | if (res != 0) goto failed; |
| 8518 | if (len != PyList_GET_SIZE(tmp)) { |
| 8519 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 8520 | goto failed; |
| 8521 | } |
| 8522 | asdl_seq_SET(args, i, val); |
| 8523 | } |
| 8524 | Py_CLEAR(tmp); |
| 8525 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8526 | if (_PyObject_LookupAttrId(obj, &PyId_vararg, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8527 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8528 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8529 | if (tmp == NULL || tmp == Py_None) { |
| 8530 | Py_CLEAR(tmp); |
| 8531 | vararg = NULL; |
| 8532 | } |
| 8533 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8534 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8535 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8536 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8537 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8538 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8539 | if (_PyObject_LookupAttrId(obj, &PyId_kwonlyargs, &tmp) < 0) { |
| 8540 | return 1; |
| 8541 | } |
| 8542 | if (tmp == NULL) { |
| 8543 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 8544 | return 1; |
| 8545 | } |
| 8546 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8547 | int res; |
| 8548 | Py_ssize_t len; |
| 8549 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8550 | if (!PyList_Check(tmp)) { |
| 8551 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8552 | goto failed; |
| 8553 | } |
| 8554 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8555 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8556 | if (kwonlyargs == NULL) goto failed; |
| 8557 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8558 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8559 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8560 | Py_INCREF(tmp2); |
| 8561 | res = obj2ast_arg(tmp2, &val, arena); |
| 8562 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8563 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8564 | if (len != PyList_GET_SIZE(tmp)) { |
| 8565 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 8566 | goto failed; |
| 8567 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8568 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8569 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8570 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8571 | } |
| 8572 | if (_PyObject_LookupAttrId(obj, &PyId_kw_defaults, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8573 | return 1; |
| 8574 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8575 | if (tmp == NULL) { |
| 8576 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 8577 | return 1; |
| 8578 | } |
| 8579 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8580 | int res; |
| 8581 | Py_ssize_t len; |
| 8582 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8583 | if (!PyList_Check(tmp)) { |
| 8584 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8585 | goto failed; |
| 8586 | } |
| 8587 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8588 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8589 | if (kw_defaults == NULL) goto failed; |
| 8590 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8591 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8592 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8593 | Py_INCREF(tmp2); |
| 8594 | res = obj2ast_expr(tmp2, &val, arena); |
| 8595 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8596 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8597 | if (len != PyList_GET_SIZE(tmp)) { |
| 8598 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 8599 | goto failed; |
| 8600 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8601 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8602 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8603 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8604 | } |
| 8605 | if (_PyObject_LookupAttrId(obj, &PyId_kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8606 | return 1; |
| 8607 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8608 | if (tmp == NULL || tmp == Py_None) { |
| 8609 | Py_CLEAR(tmp); |
| 8610 | kwarg = NULL; |
| 8611 | } |
| 8612 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8613 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8614 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 8615 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 8616 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8617 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8618 | if (_PyObject_LookupAttrId(obj, &PyId_defaults, &tmp) < 0) { |
| 8619 | return 1; |
| 8620 | } |
| 8621 | if (tmp == NULL) { |
| 8622 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 8623 | return 1; |
| 8624 | } |
| 8625 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8626 | int res; |
| 8627 | Py_ssize_t len; |
| 8628 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8629 | if (!PyList_Check(tmp)) { |
| 8630 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 8631 | goto failed; |
| 8632 | } |
| 8633 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8634 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8635 | if (defaults == NULL) goto failed; |
| 8636 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8637 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8638 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8639 | Py_INCREF(tmp2); |
| 8640 | res = obj2ast_expr(tmp2, &val, arena); |
| 8641 | Py_DECREF(tmp2); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8642 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8643 | if (len != PyList_GET_SIZE(tmp)) { |
| 8644 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 8645 | goto failed; |
| 8646 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8647 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8648 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 8649 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8650 | } |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 8651 | *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 8652 | defaults, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8653 | return 0; |
| 8654 | failed: |
| 8655 | Py_XDECREF(tmp); |
| 8656 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8657 | } |
| 8658 | |
| 8659 | int |
| 8660 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 8661 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8662 | PyObject* tmp = NULL; |
| 8663 | identifier arg; |
| 8664 | expr_ty annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8665 | string type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8666 | int lineno; |
| 8667 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8668 | int end_lineno; |
| 8669 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8670 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8671 | if (_PyObject_LookupAttrId(obj, &PyId_arg, &tmp) < 0) { |
| 8672 | return 1; |
| 8673 | } |
| 8674 | if (tmp == NULL) { |
| 8675 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 8676 | return 1; |
| 8677 | } |
| 8678 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8679 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8680 | res = obj2ast_identifier(tmp, &arg, arena); |
| 8681 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8682 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8683 | } |
| 8684 | if (_PyObject_LookupAttrId(obj, &PyId_annotation, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8685 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8686 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8687 | if (tmp == NULL || tmp == Py_None) { |
| 8688 | Py_CLEAR(tmp); |
| 8689 | annotation = NULL; |
| 8690 | } |
| 8691 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8692 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8693 | res = obj2ast_expr(tmp, &annotation, arena); |
| 8694 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8695 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8696 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8697 | if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) { |
| 8698 | return 1; |
| 8699 | } |
| 8700 | if (tmp == NULL || tmp == Py_None) { |
| 8701 | Py_CLEAR(tmp); |
| 8702 | type_comment = NULL; |
| 8703 | } |
| 8704 | else { |
| 8705 | int res; |
| 8706 | res = obj2ast_string(tmp, &type_comment, arena); |
| 8707 | if (res != 0) goto failed; |
| 8708 | Py_CLEAR(tmp); |
| 8709 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8710 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 8711 | return 1; |
| 8712 | } |
| 8713 | if (tmp == NULL) { |
| 8714 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 8715 | return 1; |
| 8716 | } |
| 8717 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8718 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8719 | res = obj2ast_int(tmp, &lineno, arena); |
| 8720 | if (res != 0) goto failed; |
| 8721 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8722 | } |
| 8723 | if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8724 | return 1; |
| 8725 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8726 | if (tmp == NULL) { |
| 8727 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 8728 | return 1; |
| 8729 | } |
| 8730 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8731 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8732 | res = obj2ast_int(tmp, &col_offset, arena); |
| 8733 | if (res != 0) goto failed; |
| 8734 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 8735 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8736 | if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) { |
| 8737 | return 1; |
| 8738 | } |
| 8739 | if (tmp == NULL || tmp == Py_None) { |
| 8740 | Py_CLEAR(tmp); |
| 8741 | end_lineno = 0; |
| 8742 | } |
| 8743 | else { |
| 8744 | int res; |
| 8745 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 8746 | if (res != 0) goto failed; |
| 8747 | Py_CLEAR(tmp); |
| 8748 | } |
| 8749 | if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) { |
| 8750 | return 1; |
| 8751 | } |
| 8752 | if (tmp == NULL || tmp == Py_None) { |
| 8753 | Py_CLEAR(tmp); |
| 8754 | end_col_offset = 0; |
| 8755 | } |
| 8756 | else { |
| 8757 | int res; |
| 8758 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 8759 | if (res != 0) goto failed; |
| 8760 | Py_CLEAR(tmp); |
| 8761 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8762 | *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno, |
| 8763 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8764 | return 0; |
| 8765 | failed: |
| 8766 | Py_XDECREF(tmp); |
| 8767 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8768 | } |
| 8769 | |
| 8770 | int |
| 8771 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 8772 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8773 | PyObject* tmp = NULL; |
| 8774 | identifier arg; |
| 8775 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8776 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8777 | if (_PyObject_LookupAttrId(obj, &PyId_arg, &tmp) < 0) { |
| 8778 | return 1; |
| 8779 | } |
| 8780 | if (tmp == NULL || tmp == Py_None) { |
| 8781 | Py_CLEAR(tmp); |
| 8782 | arg = NULL; |
| 8783 | } |
| 8784 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8785 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8786 | res = obj2ast_identifier(tmp, &arg, arena); |
| 8787 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8788 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8789 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8790 | if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) { |
| 8791 | return 1; |
| 8792 | } |
| 8793 | if (tmp == NULL) { |
| 8794 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 8795 | return 1; |
| 8796 | } |
| 8797 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8798 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8799 | res = obj2ast_expr(tmp, &value, arena); |
| 8800 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8801 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8802 | } |
| 8803 | *out = keyword(arg, value, arena); |
| 8804 | return 0; |
| 8805 | failed: |
| 8806 | Py_XDECREF(tmp); |
| 8807 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8808 | } |
| 8809 | |
| 8810 | int |
| 8811 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 8812 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8813 | PyObject* tmp = NULL; |
| 8814 | identifier name; |
| 8815 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8816 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8817 | if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) { |
| 8818 | return 1; |
| 8819 | } |
| 8820 | if (tmp == NULL) { |
| 8821 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 8822 | return 1; |
| 8823 | } |
| 8824 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8825 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8826 | res = obj2ast_identifier(tmp, &name, arena); |
| 8827 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8828 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8829 | } |
| 8830 | if (_PyObject_LookupAttrId(obj, &PyId_asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8831 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8832 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8833 | if (tmp == NULL || tmp == Py_None) { |
| 8834 | Py_CLEAR(tmp); |
| 8835 | asname = NULL; |
| 8836 | } |
| 8837 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8838 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8839 | res = obj2ast_identifier(tmp, &asname, arena); |
| 8840 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8841 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8842 | } |
| 8843 | *out = alias(name, asname, arena); |
| 8844 | return 0; |
| 8845 | failed: |
| 8846 | Py_XDECREF(tmp); |
| 8847 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8848 | } |
| 8849 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8850 | int |
| 8851 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 8852 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8853 | PyObject* tmp = NULL; |
| 8854 | expr_ty context_expr; |
| 8855 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8856 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8857 | if (_PyObject_LookupAttrId(obj, &PyId_context_expr, &tmp) < 0) { |
| 8858 | return 1; |
| 8859 | } |
| 8860 | if (tmp == NULL) { |
| 8861 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 8862 | return 1; |
| 8863 | } |
| 8864 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8865 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8866 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 8867 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8868 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8869 | } |
| 8870 | if (_PyObject_LookupAttrId(obj, &PyId_optional_vars, &tmp) < 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8871 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8872 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8873 | if (tmp == NULL || tmp == Py_None) { |
| 8874 | Py_CLEAR(tmp); |
| 8875 | optional_vars = NULL; |
| 8876 | } |
| 8877 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8878 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8879 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 8880 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8881 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8882 | } |
| 8883 | *out = withitem(context_expr, optional_vars, arena); |
| 8884 | return 0; |
| 8885 | failed: |
| 8886 | Py_XDECREF(tmp); |
| 8887 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8888 | } |
| 8889 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8890 | int |
| 8891 | obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) |
| 8892 | { |
| 8893 | int isinstance; |
| 8894 | |
| 8895 | PyObject *tmp = NULL; |
| 8896 | |
| 8897 | if (obj == Py_None) { |
| 8898 | *out = NULL; |
| 8899 | return 0; |
| 8900 | } |
| 8901 | isinstance = PyObject_IsInstance(obj, (PyObject*)TypeIgnore_type); |
| 8902 | if (isinstance == -1) { |
| 8903 | return 1; |
| 8904 | } |
| 8905 | if (isinstance) { |
| 8906 | int lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 8907 | string tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8908 | |
| 8909 | if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) { |
| 8910 | return 1; |
| 8911 | } |
| 8912 | if (tmp == NULL) { |
| 8913 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore"); |
| 8914 | return 1; |
| 8915 | } |
| 8916 | else { |
| 8917 | int res; |
| 8918 | res = obj2ast_int(tmp, &lineno, arena); |
| 8919 | if (res != 0) goto failed; |
| 8920 | Py_CLEAR(tmp); |
| 8921 | } |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 8922 | if (_PyObject_LookupAttrId(obj, &PyId_tag, &tmp) < 0) { |
| 8923 | return 1; |
| 8924 | } |
| 8925 | if (tmp == NULL) { |
| 8926 | PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore"); |
| 8927 | return 1; |
| 8928 | } |
| 8929 | else { |
| 8930 | int res; |
| 8931 | res = obj2ast_string(tmp, &tag, arena); |
| 8932 | if (res != 0) goto failed; |
| 8933 | Py_CLEAR(tmp); |
| 8934 | } |
| 8935 | *out = TypeIgnore(lineno, tag, arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8936 | if (*out == NULL) goto failed; |
| 8937 | return 0; |
| 8938 | } |
| 8939 | |
| 8940 | PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj); |
| 8941 | failed: |
| 8942 | Py_XDECREF(tmp); |
| 8943 | return 1; |
| 8944 | } |
| 8945 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8946 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 8947 | static struct PyModuleDef _astmodule = { |
| 8948 | PyModuleDef_HEAD_INIT, "_ast" |
| 8949 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8950 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 8951 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8952 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8953 | PyObject *m, *d; |
| 8954 | if (!init_types()) return NULL; |
| 8955 | m = PyModule_Create(&_astmodule); |
| 8956 | if (!m) return NULL; |
| 8957 | d = PyModule_GetDict(m); |
| 8958 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL; |
Matthias Bussonnier | 565b4f1 | 2019-05-21 13:12:03 -0700 | [diff] [blame] | 8959 | if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) |
| 8960 | return NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8961 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8962 | return NULL; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8963 | if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) |
| 8964 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8965 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; |
| 8966 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return |
| 8967 | NULL; |
| 8968 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) < |
| 8969 | 0) return NULL; |
| 8970 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0) |
| 8971 | return NULL; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 8972 | if (PyDict_SetItemString(d, "FunctionType", (PyObject*)FunctionType_type) < |
| 8973 | 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8974 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 8975 | NULL; |
| 8976 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL; |
| 8977 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) < |
| 8978 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8979 | if (PyDict_SetItemString(d, "AsyncFunctionDef", |
| 8980 | (PyObject*)AsyncFunctionDef_type) < 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8981 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 8982 | return NULL; |
| 8983 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return |
| 8984 | NULL; |
| 8985 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return |
| 8986 | NULL; |
| 8987 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return |
| 8988 | NULL; |
| 8989 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0) |
| 8990 | return NULL; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 8991 | if (PyDict_SetItemString(d, "AnnAssign", (PyObject*)AnnAssign_type) < 0) |
| 8992 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8993 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8994 | if (PyDict_SetItemString(d, "AsyncFor", (PyObject*)AsyncFor_type) < 0) |
| 8995 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8996 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 8997 | NULL; |
| 8998 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 8999 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 9000 | if (PyDict_SetItemString(d, "AsyncWith", (PyObject*)AsyncWith_type) < 0) |
| 9001 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9002 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 9003 | NULL; |
| 9004 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL; |
| 9005 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return |
| 9006 | NULL; |
| 9007 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return |
| 9008 | NULL; |
| 9009 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0) |
| 9010 | return NULL; |
| 9011 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return |
| 9012 | NULL; |
| 9013 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
| 9014 | return NULL; |
| 9015 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL; |
| 9016 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL; |
| 9017 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 9018 | NULL; |
| 9019 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 9020 | return NULL; |
| 9021 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL; |
| 9022 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return |
| 9023 | NULL; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 9024 | if (PyDict_SetItemString(d, "NamedExpr", (PyObject*)NamedExpr_type) < 0) |
| 9025 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9026 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 9027 | NULL; |
| 9028 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return |
| 9029 | NULL; |
| 9030 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return |
| 9031 | NULL; |
| 9032 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 9033 | NULL; |
| 9034 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL; |
| 9035 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL; |
| 9036 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 9037 | return NULL; |
| 9038 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return |
| 9039 | NULL; |
| 9040 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
| 9041 | return NULL; |
| 9042 | if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) < |
| 9043 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 9044 | if (PyDict_SetItemString(d, "Await", (PyObject*)Await_type) < 0) return |
| 9045 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9046 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 9047 | NULL; |
| 9048 | if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0) |
| 9049 | return NULL; |
| 9050 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return |
| 9051 | NULL; |
| 9052 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 9053 | if (PyDict_SetItemString(d, "FormattedValue", |
| 9054 | (PyObject*)FormattedValue_type) < 0) return NULL; |
| 9055 | if (PyDict_SetItemString(d, "JoinedStr", (PyObject*)JoinedStr_type) < 0) |
| 9056 | return NULL; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 9057 | if (PyDict_SetItemString(d, "Constant", (PyObject*)Constant_type) < 0) |
| 9058 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9059 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0) |
| 9060 | return NULL; |
| 9061 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0) |
| 9062 | return NULL; |
| 9063 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return |
| 9064 | NULL; |
| 9065 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL; |
| 9066 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL; |
| 9067 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 9068 | NULL; |
| 9069 | if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) < |
| 9070 | 0) return NULL; |
| 9071 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL; |
| 9072 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 9073 | NULL; |
| 9074 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL; |
| 9075 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return |
| 9076 | NULL; |
| 9077 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 9078 | return NULL; |
| 9079 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 9080 | NULL; |
| 9081 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 9082 | NULL; |
| 9083 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 9084 | NULL; |
| 9085 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 9086 | return NULL; |
| 9087 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 9088 | NULL; |
| 9089 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return |
| 9090 | NULL; |
| 9091 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL; |
| 9092 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
| 9093 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 9094 | return NULL; |
| 9095 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL; |
| 9096 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL; |
| 9097 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 9098 | if (PyDict_SetItemString(d, "MatMult", (PyObject*)MatMult_type) < 0) return |
| 9099 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9100 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL; |
| 9101 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL; |
| 9102 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL; |
| 9103 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return |
| 9104 | NULL; |
| 9105 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return |
| 9106 | NULL; |
| 9107 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 9108 | NULL; |
| 9109 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return |
| 9110 | NULL; |
| 9111 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return |
| 9112 | NULL; |
| 9113 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 9114 | return NULL; |
| 9115 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return |
| 9116 | NULL; |
| 9117 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return |
| 9118 | NULL; |
| 9119 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL; |
| 9120 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL; |
| 9121 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL; |
| 9122 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 9123 | NULL; |
| 9124 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 9125 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 9126 | NULL; |
| 9127 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 9128 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL; |
| 9129 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 9130 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL; |
| 9131 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 9132 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 9133 | NULL; |
| 9134 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 9135 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 9136 | NULL; |
| 9137 | if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type) |
| 9138 | < 0) return NULL; |
| 9139 | if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type) |
| 9140 | < 0) return NULL; |
| 9141 | if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type) |
| 9142 | < 0) return NULL; |
| 9143 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0) |
| 9144 | return NULL; |
| 9145 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL; |
| 9146 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return |
| 9147 | NULL; |
| 9148 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 9149 | NULL; |
| 9150 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 9151 | return NULL; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9152 | if (PyDict_SetItemString(d, "type_ignore", (PyObject*)type_ignore_type) < |
| 9153 | 0) return NULL; |
| 9154 | if (PyDict_SetItemString(d, "TypeIgnore", (PyObject*)TypeIgnore_type) < 0) |
| 9155 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9156 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9157 | } |
| 9158 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 9159 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 9160 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 9161 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 9162 | if (!init_types()) |
| 9163 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 9164 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 9165 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 9166 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 9167 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 9168 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9169 | { |
| 9170 | mod_ty res; |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 9171 | PyObject *req_type[3]; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9172 | const char * const req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 9173 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 9174 | |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 9175 | if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { |
| 9176 | return NULL; |
| 9177 | } |
| 9178 | |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 9179 | req_type[0] = (PyObject*)Module_type; |
| 9180 | req_type[1] = (PyObject*)Expression_type; |
| 9181 | req_type[2] = (PyObject*)Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 9182 | |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 9183 | assert(0 <= mode && mode <= 2); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 9184 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 9185 | if (!init_types()) |
| 9186 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 9187 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 9188 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 9189 | if (isinstance == -1) |
| 9190 | return NULL; |
| 9191 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 9192 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 9193 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9194 | return NULL; |
| 9195 | } |
| 9196 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 9197 | return NULL; |
| 9198 | else |
| 9199 | return res; |
| 9200 | } |
| 9201 | |
| 9202 | int PyAST_Check(PyObject* obj) |
| 9203 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 9204 | if (!init_types()) |
| 9205 | return -1; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 9206 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9207 | } |
| 9208 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 9209 | |