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); |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 13 | _Py_IDENTIFIER(docstring); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 14 | static char *Module_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 15 | "body", |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 16 | "docstring", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 17 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 18 | static PyTypeObject *Interactive_type; |
| 19 | static char *Interactive_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 20 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 21 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 22 | static PyTypeObject *Expression_type; |
| 23 | static char *Expression_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 24 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 25 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 26 | static PyTypeObject *Suite_type; |
| 27 | static char *Suite_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 28 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 29 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 30 | static PyTypeObject *stmt_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 31 | _Py_IDENTIFIER(lineno); |
| 32 | _Py_IDENTIFIER(col_offset); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 33 | static char *stmt_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 34 | "lineno", |
| 35 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 36 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 37 | static PyObject* ast2obj_stmt(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 38 | static PyTypeObject *FunctionDef_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 39 | _Py_IDENTIFIER(name); |
| 40 | _Py_IDENTIFIER(args); |
| 41 | _Py_IDENTIFIER(decorator_list); |
| 42 | _Py_IDENTIFIER(returns); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 43 | static char *FunctionDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 44 | "name", |
| 45 | "args", |
| 46 | "body", |
| 47 | "decorator_list", |
| 48 | "returns", |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 49 | "docstring", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 50 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 51 | static PyTypeObject *AsyncFunctionDef_type; |
| 52 | static char *AsyncFunctionDef_fields[]={ |
| 53 | "name", |
| 54 | "args", |
| 55 | "body", |
| 56 | "decorator_list", |
| 57 | "returns", |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 58 | "docstring", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 59 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 60 | static PyTypeObject *ClassDef_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 61 | _Py_IDENTIFIER(bases); |
| 62 | _Py_IDENTIFIER(keywords); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 63 | static char *ClassDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 64 | "name", |
| 65 | "bases", |
| 66 | "keywords", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 67 | "body", |
| 68 | "decorator_list", |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 69 | "docstring", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 70 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 71 | static PyTypeObject *Return_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 72 | _Py_IDENTIFIER(value); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 73 | static char *Return_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 74 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 75 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 76 | static PyTypeObject *Delete_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 77 | _Py_IDENTIFIER(targets); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 78 | static char *Delete_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 79 | "targets", |
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 *Assign_type; |
| 82 | static char *Assign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 83 | "targets", |
| 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 *AugAssign_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 87 | _Py_IDENTIFIER(target); |
| 88 | _Py_IDENTIFIER(op); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 89 | static char *AugAssign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 90 | "target", |
| 91 | "op", |
| 92 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 93 | }; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 94 | static PyTypeObject *AnnAssign_type; |
| 95 | _Py_IDENTIFIER(annotation); |
| 96 | _Py_IDENTIFIER(simple); |
| 97 | static char *AnnAssign_fields[]={ |
| 98 | "target", |
| 99 | "annotation", |
| 100 | "value", |
| 101 | "simple", |
| 102 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 103 | static PyTypeObject *For_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 104 | _Py_IDENTIFIER(iter); |
| 105 | _Py_IDENTIFIER(orelse); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 106 | static char *For_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 107 | "target", |
| 108 | "iter", |
| 109 | "body", |
| 110 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 111 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 112 | static PyTypeObject *AsyncFor_type; |
| 113 | static char *AsyncFor_fields[]={ |
| 114 | "target", |
| 115 | "iter", |
| 116 | "body", |
| 117 | "orelse", |
| 118 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 119 | static PyTypeObject *While_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 120 | _Py_IDENTIFIER(test); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 121 | static char *While_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 122 | "test", |
| 123 | "body", |
| 124 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 125 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 126 | static PyTypeObject *If_type; |
| 127 | static char *If_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 128 | "test", |
| 129 | "body", |
| 130 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 131 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 132 | static PyTypeObject *With_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 133 | _Py_IDENTIFIER(items); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 134 | static char *With_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 135 | "items", |
| 136 | "body", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 137 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 138 | static PyTypeObject *AsyncWith_type; |
| 139 | static char *AsyncWith_fields[]={ |
| 140 | "items", |
| 141 | "body", |
| 142 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 143 | static PyTypeObject *Raise_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 144 | _Py_IDENTIFIER(exc); |
| 145 | _Py_IDENTIFIER(cause); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 146 | static char *Raise_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 147 | "exc", |
| 148 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 149 | }; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 150 | static PyTypeObject *Try_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 151 | _Py_IDENTIFIER(handlers); |
| 152 | _Py_IDENTIFIER(finalbody); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 153 | static char *Try_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 154 | "body", |
| 155 | "handlers", |
| 156 | "orelse", |
| 157 | "finalbody", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 158 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 159 | static PyTypeObject *Assert_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 160 | _Py_IDENTIFIER(msg); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 161 | static char *Assert_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 162 | "test", |
| 163 | "msg", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 164 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 165 | static PyTypeObject *Import_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 166 | _Py_IDENTIFIER(names); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 167 | static char *Import_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 168 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 169 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 170 | static PyTypeObject *ImportFrom_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 171 | _Py_IDENTIFIER(module); |
| 172 | _Py_IDENTIFIER(level); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 173 | static char *ImportFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 174 | "module", |
| 175 | "names", |
| 176 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 177 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 178 | static PyTypeObject *Global_type; |
| 179 | static char *Global_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 180 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 181 | }; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 182 | static PyTypeObject *Nonlocal_type; |
| 183 | static char *Nonlocal_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 184 | "names", |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 185 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 186 | static PyTypeObject *Expr_type; |
| 187 | static char *Expr_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 188 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 189 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 190 | static PyTypeObject *Pass_type; |
| 191 | static PyTypeObject *Break_type; |
| 192 | static PyTypeObject *Continue_type; |
| 193 | static PyTypeObject *expr_type; |
| 194 | static char *expr_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 195 | "lineno", |
| 196 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 197 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 198 | static PyObject* ast2obj_expr(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 199 | static PyTypeObject *BoolOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 200 | _Py_IDENTIFIER(values); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 201 | static char *BoolOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 202 | "op", |
| 203 | "values", |
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 *BinOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 206 | _Py_IDENTIFIER(left); |
| 207 | _Py_IDENTIFIER(right); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 208 | static char *BinOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 209 | "left", |
| 210 | "op", |
| 211 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 212 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 213 | static PyTypeObject *UnaryOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 214 | _Py_IDENTIFIER(operand); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 215 | static char *UnaryOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 216 | "op", |
| 217 | "operand", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 218 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 219 | static PyTypeObject *Lambda_type; |
| 220 | static char *Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 221 | "args", |
| 222 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 223 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 224 | static PyTypeObject *IfExp_type; |
| 225 | static char *IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 226 | "test", |
| 227 | "body", |
| 228 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 229 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 230 | static PyTypeObject *Dict_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 231 | _Py_IDENTIFIER(keys); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 232 | static char *Dict_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 233 | "keys", |
| 234 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 235 | }; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 236 | static PyTypeObject *Set_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 237 | _Py_IDENTIFIER(elts); |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 238 | static char *Set_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 239 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 240 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 241 | static PyTypeObject *ListComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 242 | _Py_IDENTIFIER(elt); |
| 243 | _Py_IDENTIFIER(generators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 244 | static char *ListComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 245 | "elt", |
| 246 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 247 | }; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 248 | static PyTypeObject *SetComp_type; |
| 249 | static char *SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 250 | "elt", |
| 251 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 252 | }; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 253 | static PyTypeObject *DictComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 254 | _Py_IDENTIFIER(key); |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 255 | static char *DictComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 256 | "key", |
| 257 | "value", |
| 258 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 259 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 260 | static PyTypeObject *GeneratorExp_type; |
| 261 | static char *GeneratorExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 262 | "elt", |
| 263 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 264 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 265 | static PyTypeObject *Await_type; |
| 266 | static char *Await_fields[]={ |
| 267 | "value", |
| 268 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 269 | static PyTypeObject *Yield_type; |
| 270 | static char *Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 271 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 272 | }; |
| 273 | static PyTypeObject *YieldFrom_type; |
| 274 | static char *YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 275 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 276 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 277 | static PyTypeObject *Compare_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 278 | _Py_IDENTIFIER(ops); |
| 279 | _Py_IDENTIFIER(comparators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 280 | static char *Compare_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 281 | "left", |
| 282 | "ops", |
| 283 | "comparators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 284 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 285 | static PyTypeObject *Call_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 286 | _Py_IDENTIFIER(func); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 287 | static char *Call_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 288 | "func", |
| 289 | "args", |
| 290 | "keywords", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 291 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 292 | static PyTypeObject *Num_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 293 | _Py_IDENTIFIER(n); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 294 | static char *Num_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 295 | "n", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 296 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 297 | static PyTypeObject *Str_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 298 | _Py_IDENTIFIER(s); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 299 | static char *Str_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 300 | "s", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 301 | }; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 302 | static PyTypeObject *FormattedValue_type; |
| 303 | _Py_IDENTIFIER(conversion); |
| 304 | _Py_IDENTIFIER(format_spec); |
| 305 | static char *FormattedValue_fields[]={ |
| 306 | "value", |
| 307 | "conversion", |
| 308 | "format_spec", |
| 309 | }; |
| 310 | static PyTypeObject *JoinedStr_type; |
| 311 | static char *JoinedStr_fields[]={ |
| 312 | "values", |
| 313 | }; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 314 | static PyTypeObject *Bytes_type; |
| 315 | static char *Bytes_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 316 | "s", |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 317 | }; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 318 | static PyTypeObject *NameConstant_type; |
| 319 | static char *NameConstant_fields[]={ |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 320 | "value", |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 321 | }; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 322 | static PyTypeObject *Ellipsis_type; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 323 | static PyTypeObject *Constant_type; |
| 324 | static char *Constant_fields[]={ |
| 325 | "value", |
| 326 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 327 | static PyTypeObject *Attribute_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 328 | _Py_IDENTIFIER(attr); |
| 329 | _Py_IDENTIFIER(ctx); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 330 | static char *Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 331 | "value", |
| 332 | "attr", |
| 333 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 334 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 335 | static PyTypeObject *Subscript_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 336 | _Py_IDENTIFIER(slice); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 337 | static char *Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 338 | "value", |
| 339 | "slice", |
| 340 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 341 | }; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 342 | static PyTypeObject *Starred_type; |
| 343 | static char *Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 344 | "value", |
| 345 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 346 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 347 | static PyTypeObject *Name_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 348 | _Py_IDENTIFIER(id); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 349 | static char *Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 350 | "id", |
| 351 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 352 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 353 | static PyTypeObject *List_type; |
| 354 | static char *List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 355 | "elts", |
| 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 *Tuple_type; |
| 359 | static char *Tuple_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 *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 364 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
| 365 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
| 366 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 367 | static PyTypeObject *Load_type; |
| 368 | static PyTypeObject *Store_type; |
| 369 | static PyTypeObject *Del_type; |
| 370 | static PyTypeObject *AugLoad_type; |
| 371 | static PyTypeObject *AugStore_type; |
| 372 | static PyTypeObject *Param_type; |
| 373 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 374 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 375 | static PyTypeObject *Slice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 376 | _Py_IDENTIFIER(lower); |
| 377 | _Py_IDENTIFIER(upper); |
| 378 | _Py_IDENTIFIER(step); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 379 | static char *Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 380 | "lower", |
| 381 | "upper", |
| 382 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 383 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 384 | static PyTypeObject *ExtSlice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 385 | _Py_IDENTIFIER(dims); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 386 | static char *ExtSlice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 387 | "dims", |
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 *Index_type; |
| 390 | static char *Index_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 391 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 392 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 393 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 394 | static PyObject *And_singleton, *Or_singleton; |
| 395 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 396 | static PyTypeObject *And_type; |
| 397 | static PyTypeObject *Or_type; |
| 398 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 399 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 400 | *MatMult_singleton, *Div_singleton, *Mod_singleton, *Pow_singleton, |
| 401 | *LShift_singleton, *RShift_singleton, *BitOr_singleton, *BitXor_singleton, |
| 402 | *BitAnd_singleton, *FloorDiv_singleton; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 403 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 404 | static PyTypeObject *Add_type; |
| 405 | static PyTypeObject *Sub_type; |
| 406 | static PyTypeObject *Mult_type; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 407 | static PyTypeObject *MatMult_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 408 | static PyTypeObject *Div_type; |
| 409 | static PyTypeObject *Mod_type; |
| 410 | static PyTypeObject *Pow_type; |
| 411 | static PyTypeObject *LShift_type; |
| 412 | static PyTypeObject *RShift_type; |
| 413 | static PyTypeObject *BitOr_type; |
| 414 | static PyTypeObject *BitXor_type; |
| 415 | static PyTypeObject *BitAnd_type; |
| 416 | static PyTypeObject *FloorDiv_type; |
| 417 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 418 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 419 | *USub_singleton; |
| 420 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 421 | static PyTypeObject *Invert_type; |
| 422 | static PyTypeObject *Not_type; |
| 423 | static PyTypeObject *UAdd_type; |
| 424 | static PyTypeObject *USub_type; |
| 425 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 426 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 427 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 428 | *NotIn_singleton; |
| 429 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 430 | static PyTypeObject *Eq_type; |
| 431 | static PyTypeObject *NotEq_type; |
| 432 | static PyTypeObject *Lt_type; |
| 433 | static PyTypeObject *LtE_type; |
| 434 | static PyTypeObject *Gt_type; |
| 435 | static PyTypeObject *GtE_type; |
| 436 | static PyTypeObject *Is_type; |
| 437 | static PyTypeObject *IsNot_type; |
| 438 | static PyTypeObject *In_type; |
| 439 | static PyTypeObject *NotIn_type; |
| 440 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 441 | static PyObject* ast2obj_comprehension(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 442 | _Py_IDENTIFIER(ifs); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 443 | _Py_IDENTIFIER(is_async); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 444 | static char *comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 445 | "target", |
| 446 | "iter", |
| 447 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 448 | "is_async", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 449 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 450 | static PyTypeObject *excepthandler_type; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 451 | static char *excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 452 | "lineno", |
| 453 | "col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 454 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 455 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 456 | static PyTypeObject *ExceptHandler_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 457 | _Py_IDENTIFIER(type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 458 | static char *ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 459 | "type", |
| 460 | "name", |
| 461 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 462 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 463 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 464 | static PyObject* ast2obj_arguments(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 465 | _Py_IDENTIFIER(vararg); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 466 | _Py_IDENTIFIER(kwonlyargs); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 467 | _Py_IDENTIFIER(kw_defaults); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 468 | _Py_IDENTIFIER(kwarg); |
| 469 | _Py_IDENTIFIER(defaults); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 470 | static char *arguments_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 471 | "args", |
| 472 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 473 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 474 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 475 | "kwarg", |
| 476 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 477 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 478 | static PyTypeObject *arg_type; |
| 479 | static PyObject* ast2obj_arg(void*); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 480 | static char *arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 481 | "lineno", |
| 482 | "col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 483 | }; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 484 | _Py_IDENTIFIER(arg); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 485 | static char *arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 486 | "arg", |
| 487 | "annotation", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 488 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 489 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 490 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 491 | static char *keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 492 | "arg", |
| 493 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 494 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 495 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 496 | static PyObject* ast2obj_alias(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 497 | _Py_IDENTIFIER(asname); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 498 | static char *alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 499 | "name", |
| 500 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 501 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 502 | static PyTypeObject *withitem_type; |
| 503 | static PyObject* ast2obj_withitem(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 504 | _Py_IDENTIFIER(context_expr); |
| 505 | _Py_IDENTIFIER(optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 506 | static char *withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 507 | "context_expr", |
| 508 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 509 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 510 | |
| 511 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 512 | _Py_IDENTIFIER(_fields); |
| 513 | _Py_IDENTIFIER(_attributes); |
| 514 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 515 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 516 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 517 | PyObject *dict; |
| 518 | } AST_object; |
| 519 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 520 | static void |
| 521 | ast_dealloc(AST_object *self) |
| 522 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 523 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
| 524 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 525 | Py_CLEAR(self->dict); |
Antoine Pitrou | 5075074 | 2012-07-08 12:43:32 +0200 | [diff] [blame] | 526 | Py_TYPE(self)->tp_free(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 527 | } |
| 528 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 529 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 530 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 531 | { |
| 532 | Py_VISIT(self->dict); |
| 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | static void |
| 537 | ast_clear(AST_object *self) |
| 538 | { |
| 539 | Py_CLEAR(self->dict); |
| 540 | } |
| 541 | |
| 542 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 543 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 544 | { |
| 545 | Py_ssize_t i, numfields = 0; |
| 546 | int res = -1; |
| 547 | PyObject *key, *value, *fields; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 548 | fields = _PyObject_GetAttrId((PyObject*)Py_TYPE(self), &PyId__fields); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 549 | if (fields) { |
| 550 | numfields = PySequence_Size(fields); |
| 551 | if (numfields == -1) |
| 552 | goto cleanup; |
| 553 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 554 | else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 555 | PyErr_Clear(); |
| 556 | } |
| 557 | else { |
| 558 | goto cleanup; |
| 559 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 560 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 561 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 562 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 563 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 564 | "%zd positional argument%s", |
| 565 | Py_TYPE(self)->tp_name, |
| 566 | numfields, numfields == 1 ? "" : "s"); |
| 567 | res = -1; |
| 568 | goto cleanup; |
| 569 | } |
| 570 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 571 | /* cannot be reached when fields is NULL */ |
| 572 | PyObject *name = PySequence_GetItem(fields, i); |
| 573 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 574 | res = -1; |
| 575 | goto cleanup; |
| 576 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 577 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 578 | Py_DECREF(name); |
| 579 | if (res < 0) |
| 580 | goto cleanup; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 581 | } |
| 582 | if (kw) { |
| 583 | i = 0; /* needed by PyDict_Next */ |
| 584 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 585 | res = PyObject_SetAttr(self, key, value); |
| 586 | if (res < 0) |
| 587 | goto cleanup; |
| 588 | } |
| 589 | } |
| 590 | cleanup: |
| 591 | Py_XDECREF(fields); |
| 592 | return res; |
| 593 | } |
| 594 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 595 | /* Pickling support */ |
| 596 | static PyObject * |
| 597 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 598 | { |
| 599 | PyObject *res; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 600 | _Py_IDENTIFIER(__dict__); |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 601 | PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 602 | if (dict == NULL) { |
| 603 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
| 604 | PyErr_Clear(); |
| 605 | else |
| 606 | return NULL; |
| 607 | } |
| 608 | if (dict) { |
| 609 | res = Py_BuildValue("O()O", Py_TYPE(self), dict); |
| 610 | Py_DECREF(dict); |
| 611 | return res; |
| 612 | } |
| 613 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 614 | } |
| 615 | |
| 616 | static PyMethodDef ast_type_methods[] = { |
| 617 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 618 | {NULL} |
| 619 | }; |
| 620 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 621 | static PyGetSetDef ast_type_getsets[] = { |
| 622 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 623 | {NULL} |
| 624 | }; |
| 625 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 626 | static PyTypeObject AST_type = { |
| 627 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 628 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 629 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 630 | 0, |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 631 | (destructor)ast_dealloc, /* tp_dealloc */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 632 | 0, /* tp_print */ |
| 633 | 0, /* tp_getattr */ |
| 634 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 635 | 0, /* tp_reserved */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 636 | 0, /* tp_repr */ |
| 637 | 0, /* tp_as_number */ |
| 638 | 0, /* tp_as_sequence */ |
| 639 | 0, /* tp_as_mapping */ |
| 640 | 0, /* tp_hash */ |
| 641 | 0, /* tp_call */ |
| 642 | 0, /* tp_str */ |
| 643 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 644 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 645 | 0, /* tp_as_buffer */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 646 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 647 | 0, /* tp_doc */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 648 | (traverseproc)ast_traverse, /* tp_traverse */ |
| 649 | (inquiry)ast_clear, /* tp_clear */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 650 | 0, /* tp_richcompare */ |
| 651 | 0, /* tp_weaklistoffset */ |
| 652 | 0, /* tp_iter */ |
| 653 | 0, /* tp_iternext */ |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 654 | ast_type_methods, /* tp_methods */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 655 | 0, /* tp_members */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 656 | ast_type_getsets, /* tp_getset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 657 | 0, /* tp_base */ |
| 658 | 0, /* tp_dict */ |
| 659 | 0, /* tp_descr_get */ |
| 660 | 0, /* tp_descr_set */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 661 | offsetof(AST_object, dict),/* tp_dictoffset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 662 | (initproc)ast_type_init, /* tp_init */ |
| 663 | PyType_GenericAlloc, /* tp_alloc */ |
| 664 | PyType_GenericNew, /* tp_new */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 665 | PyObject_GC_Del, /* tp_free */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 666 | }; |
| 667 | |
| 668 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 669 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 670 | { |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 671 | _Py_IDENTIFIER(__module__); |
| 672 | _Py_IDENTIFIER(_ast); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 673 | PyObject *fnames, *result; |
| 674 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 675 | fnames = PyTuple_New(num_fields); |
| 676 | if (!fnames) return NULL; |
| 677 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 678 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 679 | if (!field) { |
| 680 | Py_DECREF(fnames); |
| 681 | return NULL; |
| 682 | } |
| 683 | PyTuple_SET_ITEM(fnames, i, field); |
| 684 | } |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 685 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}", |
| 686 | type, base, |
| 687 | _PyUnicode_FromId(&PyId__fields), fnames, |
| 688 | _PyUnicode_FromId(&PyId___module__), |
| 689 | _PyUnicode_FromId(&PyId__ast)); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 690 | Py_DECREF(fnames); |
| 691 | return (PyTypeObject*)result; |
| 692 | } |
| 693 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 694 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 695 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 696 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 697 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 698 | if (!l) |
| 699 | return 0; |
| 700 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 701 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 702 | if (!s) { |
| 703 | Py_DECREF(l); |
| 704 | return 0; |
| 705 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 706 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 707 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 708 | result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 709 | Py_DECREF(l); |
| 710 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 711 | } |
| 712 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 713 | /* Conversion AST -> Python */ |
| 714 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 715 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 716 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 717 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 718 | PyObject *result = PyList_New(n); |
| 719 | PyObject *value; |
| 720 | if (!result) |
| 721 | return NULL; |
| 722 | for (i = 0; i < n; i++) { |
| 723 | value = func(asdl_seq_GET(seq, i)); |
| 724 | if (!value) { |
| 725 | Py_DECREF(result); |
| 726 | return NULL; |
| 727 | } |
| 728 | PyList_SET_ITEM(result, i, value); |
| 729 | } |
| 730 | return result; |
| 731 | } |
| 732 | |
| 733 | static PyObject* ast2obj_object(void *o) |
| 734 | { |
| 735 | if (!o) |
| 736 | o = Py_None; |
| 737 | Py_INCREF((PyObject*)o); |
| 738 | return (PyObject*)o; |
| 739 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 740 | #define ast2obj_singleton ast2obj_object |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 741 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 742 | #define ast2obj_identifier ast2obj_object |
| 743 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 744 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 745 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 746 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 747 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 748 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 749 | } |
| 750 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 751 | /* Conversion Python -> AST */ |
| 752 | |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 753 | static int obj2ast_singleton(PyObject *obj, PyObject** out, PyArena* arena) |
| 754 | { |
| 755 | if (obj != Py_None && obj != Py_True && obj != Py_False) { |
| 756 | PyErr_SetString(PyExc_ValueError, |
| 757 | "AST singleton must be True, False, or None"); |
| 758 | return 1; |
| 759 | } |
| 760 | *out = obj; |
| 761 | return 0; |
| 762 | } |
| 763 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 764 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 765 | { |
| 766 | if (obj == Py_None) |
| 767 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 768 | if (obj) { |
| 769 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 770 | *out = NULL; |
| 771 | return -1; |
| 772 | } |
| 773 | Py_INCREF(obj); |
| 774 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 775 | *out = obj; |
| 776 | return 0; |
| 777 | } |
| 778 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 779 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 780 | { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 781 | if (obj) { |
| 782 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 783 | *out = NULL; |
| 784 | return -1; |
| 785 | } |
| 786 | Py_INCREF(obj); |
| 787 | } |
| 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 | |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 801 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 802 | { |
Benjamin Peterson | 0224d4e | 2011-08-31 22:13:03 -0400 | [diff] [blame] | 803 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 804 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 805 | return 1; |
| 806 | } |
| 807 | return obj2ast_object(obj, out, arena); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 808 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 809 | |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 810 | static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena) |
| 811 | { |
| 812 | if (!PyBytes_CheckExact(obj)) { |
| 813 | PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes"); |
| 814 | return 1; |
| 815 | } |
| 816 | return obj2ast_object(obj, out, arena); |
| 817 | } |
| 818 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 819 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 820 | { |
| 821 | int i; |
| 822 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 823 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 824 | return 1; |
| 825 | } |
| 826 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 827 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 828 | if (i == -1 && PyErr_Occurred()) |
| 829 | return 1; |
| 830 | *out = i; |
| 831 | return 0; |
| 832 | } |
| 833 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 834 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 835 | { |
| 836 | PyObject *empty_tuple, *d; |
| 837 | if (PyType_Ready(&AST_type) < 0) |
| 838 | return -1; |
| 839 | d = AST_type.tp_dict; |
| 840 | empty_tuple = PyTuple_New(0); |
| 841 | if (!empty_tuple || |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 842 | _PyDict_SetItemId(d, &PyId__fields, empty_tuple) < 0 || |
| 843 | _PyDict_SetItemId(d, &PyId__attributes, empty_tuple) < 0) { |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 844 | Py_XDECREF(empty_tuple); |
| 845 | return -1; |
| 846 | } |
| 847 | Py_DECREF(empty_tuple); |
| 848 | return 0; |
| 849 | } |
| 850 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 851 | static PyObject *get_not_none(PyObject *obj, _Py_Identifier *id) |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 852 | { |
| 853 | PyObject *attr = _PyObject_GetAttrId(obj, id); |
| 854 | if (!attr) { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 855 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 856 | PyErr_Clear(); |
| 857 | } |
| 858 | return NULL; |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 859 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 860 | else if (attr == Py_None) { |
| 861 | Py_DECREF(attr); |
| 862 | return NULL; |
| 863 | } |
| 864 | return attr; |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 867 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 868 | static int init_types(void) |
| 869 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 870 | static int initialized; |
| 871 | if (initialized) return 1; |
| 872 | if (add_ast_fields() < 0) return 0; |
| 873 | mod_type = make_type("mod", &AST_type, NULL, 0); |
| 874 | if (!mod_type) return 0; |
| 875 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 876 | Module_type = make_type("Module", mod_type, Module_fields, 2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 877 | if (!Module_type) return 0; |
| 878 | Interactive_type = make_type("Interactive", mod_type, Interactive_fields, |
| 879 | 1); |
| 880 | if (!Interactive_type) return 0; |
| 881 | Expression_type = make_type("Expression", mod_type, Expression_fields, 1); |
| 882 | if (!Expression_type) return 0; |
| 883 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
| 884 | if (!Suite_type) return 0; |
| 885 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
| 886 | if (!stmt_type) return 0; |
| 887 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
| 888 | FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields, |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 889 | 6); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 890 | if (!FunctionDef_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 891 | AsyncFunctionDef_type = make_type("AsyncFunctionDef", stmt_type, |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 892 | AsyncFunctionDef_fields, 6); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 893 | if (!AsyncFunctionDef_type) return 0; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 894 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 6); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 895 | if (!ClassDef_type) return 0; |
| 896 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
| 897 | if (!Return_type) return 0; |
| 898 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
| 899 | if (!Delete_type) return 0; |
| 900 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
| 901 | if (!Assign_type) return 0; |
| 902 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
| 903 | if (!AugAssign_type) return 0; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 904 | AnnAssign_type = make_type("AnnAssign", stmt_type, AnnAssign_fields, 4); |
| 905 | if (!AnnAssign_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 906 | For_type = make_type("For", stmt_type, For_fields, 4); |
| 907 | if (!For_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 908 | AsyncFor_type = make_type("AsyncFor", stmt_type, AsyncFor_fields, 4); |
| 909 | if (!AsyncFor_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 910 | While_type = make_type("While", stmt_type, While_fields, 3); |
| 911 | if (!While_type) return 0; |
| 912 | If_type = make_type("If", stmt_type, If_fields, 3); |
| 913 | if (!If_type) return 0; |
| 914 | With_type = make_type("With", stmt_type, With_fields, 2); |
| 915 | if (!With_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 916 | AsyncWith_type = make_type("AsyncWith", stmt_type, AsyncWith_fields, 2); |
| 917 | if (!AsyncWith_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 918 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
| 919 | if (!Raise_type) return 0; |
| 920 | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
| 921 | if (!Try_type) return 0; |
| 922 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
| 923 | if (!Assert_type) return 0; |
| 924 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
| 925 | if (!Import_type) return 0; |
| 926 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, 3); |
| 927 | if (!ImportFrom_type) return 0; |
| 928 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
| 929 | if (!Global_type) return 0; |
| 930 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 931 | if (!Nonlocal_type) return 0; |
| 932 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
| 933 | if (!Expr_type) return 0; |
| 934 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
| 935 | if (!Pass_type) return 0; |
| 936 | Break_type = make_type("Break", stmt_type, NULL, 0); |
| 937 | if (!Break_type) return 0; |
| 938 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
| 939 | if (!Continue_type) return 0; |
| 940 | expr_type = make_type("expr", &AST_type, NULL, 0); |
| 941 | if (!expr_type) return 0; |
| 942 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
| 943 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
| 944 | if (!BoolOp_type) return 0; |
| 945 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
| 946 | if (!BinOp_type) return 0; |
| 947 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
| 948 | if (!UnaryOp_type) return 0; |
| 949 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
| 950 | if (!Lambda_type) return 0; |
| 951 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
| 952 | if (!IfExp_type) return 0; |
| 953 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
| 954 | if (!Dict_type) return 0; |
| 955 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 956 | if (!Set_type) return 0; |
| 957 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
| 958 | if (!ListComp_type) return 0; |
| 959 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 960 | if (!SetComp_type) return 0; |
| 961 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 962 | if (!DictComp_type) return 0; |
| 963 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 964 | GeneratorExp_fields, 2); |
| 965 | if (!GeneratorExp_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 966 | Await_type = make_type("Await", expr_type, Await_fields, 1); |
| 967 | if (!Await_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 968 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
| 969 | if (!Yield_type) return 0; |
| 970 | YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); |
| 971 | if (!YieldFrom_type) return 0; |
| 972 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
| 973 | if (!Compare_type) return 0; |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 974 | Call_type = make_type("Call", expr_type, Call_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 975 | if (!Call_type) return 0; |
| 976 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
| 977 | if (!Num_type) return 0; |
| 978 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
| 979 | if (!Str_type) return 0; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 980 | FormattedValue_type = make_type("FormattedValue", expr_type, |
| 981 | FormattedValue_fields, 3); |
| 982 | if (!FormattedValue_type) return 0; |
| 983 | JoinedStr_type = make_type("JoinedStr", expr_type, JoinedStr_fields, 1); |
| 984 | if (!JoinedStr_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 985 | Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); |
| 986 | if (!Bytes_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 987 | NameConstant_type = make_type("NameConstant", expr_type, |
| 988 | NameConstant_fields, 1); |
| 989 | if (!NameConstant_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 990 | Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); |
| 991 | if (!Ellipsis_type) return 0; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 992 | Constant_type = make_type("Constant", expr_type, Constant_fields, 1); |
| 993 | if (!Constant_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 994 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
| 995 | if (!Attribute_type) return 0; |
| 996 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
| 997 | if (!Subscript_type) return 0; |
| 998 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 999 | if (!Starred_type) return 0; |
| 1000 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
| 1001 | if (!Name_type) return 0; |
| 1002 | List_type = make_type("List", expr_type, List_fields, 2); |
| 1003 | if (!List_type) return 0; |
| 1004 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
| 1005 | if (!Tuple_type) return 0; |
| 1006 | expr_context_type = make_type("expr_context", &AST_type, NULL, 0); |
| 1007 | if (!expr_context_type) return 0; |
| 1008 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
| 1009 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
| 1010 | if (!Load_type) return 0; |
| 1011 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
| 1012 | if (!Load_singleton) return 0; |
| 1013 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
| 1014 | if (!Store_type) return 0; |
| 1015 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
| 1016 | if (!Store_singleton) return 0; |
| 1017 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
| 1018 | if (!Del_type) return 0; |
| 1019 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
| 1020 | if (!Del_singleton) return 0; |
| 1021 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
| 1022 | if (!AugLoad_type) return 0; |
| 1023 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
| 1024 | if (!AugLoad_singleton) return 0; |
| 1025 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
| 1026 | if (!AugStore_type) return 0; |
| 1027 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
| 1028 | if (!AugStore_singleton) return 0; |
| 1029 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
| 1030 | if (!Param_type) return 0; |
| 1031 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
| 1032 | if (!Param_singleton) return 0; |
| 1033 | slice_type = make_type("slice", &AST_type, NULL, 0); |
| 1034 | if (!slice_type) return 0; |
| 1035 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
| 1036 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
| 1037 | if (!Slice_type) return 0; |
| 1038 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
| 1039 | if (!ExtSlice_type) return 0; |
| 1040 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
| 1041 | if (!Index_type) return 0; |
| 1042 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
| 1043 | if (!boolop_type) return 0; |
| 1044 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
| 1045 | And_type = make_type("And", boolop_type, NULL, 0); |
| 1046 | if (!And_type) return 0; |
| 1047 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
| 1048 | if (!And_singleton) return 0; |
| 1049 | Or_type = make_type("Or", boolop_type, NULL, 0); |
| 1050 | if (!Or_type) return 0; |
| 1051 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
| 1052 | if (!Or_singleton) return 0; |
| 1053 | operator_type = make_type("operator", &AST_type, NULL, 0); |
| 1054 | if (!operator_type) return 0; |
| 1055 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
| 1056 | Add_type = make_type("Add", operator_type, NULL, 0); |
| 1057 | if (!Add_type) return 0; |
| 1058 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
| 1059 | if (!Add_singleton) return 0; |
| 1060 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
| 1061 | if (!Sub_type) return 0; |
| 1062 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
| 1063 | if (!Sub_singleton) return 0; |
| 1064 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
| 1065 | if (!Mult_type) return 0; |
| 1066 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
| 1067 | if (!Mult_singleton) return 0; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 1068 | MatMult_type = make_type("MatMult", operator_type, NULL, 0); |
| 1069 | if (!MatMult_type) return 0; |
| 1070 | MatMult_singleton = PyType_GenericNew(MatMult_type, NULL, NULL); |
| 1071 | if (!MatMult_singleton) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1072 | Div_type = make_type("Div", operator_type, NULL, 0); |
| 1073 | if (!Div_type) return 0; |
| 1074 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
| 1075 | if (!Div_singleton) return 0; |
| 1076 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
| 1077 | if (!Mod_type) return 0; |
| 1078 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
| 1079 | if (!Mod_singleton) return 0; |
| 1080 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
| 1081 | if (!Pow_type) return 0; |
| 1082 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
| 1083 | if (!Pow_singleton) return 0; |
| 1084 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
| 1085 | if (!LShift_type) return 0; |
| 1086 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
| 1087 | if (!LShift_singleton) return 0; |
| 1088 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
| 1089 | if (!RShift_type) return 0; |
| 1090 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
| 1091 | if (!RShift_singleton) return 0; |
| 1092 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
| 1093 | if (!BitOr_type) return 0; |
| 1094 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
| 1095 | if (!BitOr_singleton) return 0; |
| 1096 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
| 1097 | if (!BitXor_type) return 0; |
| 1098 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
| 1099 | if (!BitXor_singleton) return 0; |
| 1100 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
| 1101 | if (!BitAnd_type) return 0; |
| 1102 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
| 1103 | if (!BitAnd_singleton) return 0; |
| 1104 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
| 1105 | if (!FloorDiv_type) return 0; |
| 1106 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
| 1107 | if (!FloorDiv_singleton) return 0; |
| 1108 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
| 1109 | if (!unaryop_type) return 0; |
| 1110 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
| 1111 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
| 1112 | if (!Invert_type) return 0; |
| 1113 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
| 1114 | if (!Invert_singleton) return 0; |
| 1115 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
| 1116 | if (!Not_type) return 0; |
| 1117 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
| 1118 | if (!Not_singleton) return 0; |
| 1119 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
| 1120 | if (!UAdd_type) return 0; |
| 1121 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
| 1122 | if (!UAdd_singleton) return 0; |
| 1123 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
| 1124 | if (!USub_type) return 0; |
| 1125 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
| 1126 | if (!USub_singleton) return 0; |
| 1127 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
| 1128 | if (!cmpop_type) return 0; |
| 1129 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
| 1130 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
| 1131 | if (!Eq_type) return 0; |
| 1132 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
| 1133 | if (!Eq_singleton) return 0; |
| 1134 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
| 1135 | if (!NotEq_type) return 0; |
| 1136 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
| 1137 | if (!NotEq_singleton) return 0; |
| 1138 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
| 1139 | if (!Lt_type) return 0; |
| 1140 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
| 1141 | if (!Lt_singleton) return 0; |
| 1142 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
| 1143 | if (!LtE_type) return 0; |
| 1144 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
| 1145 | if (!LtE_singleton) return 0; |
| 1146 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
| 1147 | if (!Gt_type) return 0; |
| 1148 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
| 1149 | if (!Gt_singleton) return 0; |
| 1150 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
| 1151 | if (!GtE_type) return 0; |
| 1152 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
| 1153 | if (!GtE_singleton) return 0; |
| 1154 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
| 1155 | if (!Is_type) return 0; |
| 1156 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
| 1157 | if (!Is_singleton) return 0; |
| 1158 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
| 1159 | if (!IsNot_type) return 0; |
| 1160 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
| 1161 | if (!IsNot_singleton) return 0; |
| 1162 | In_type = make_type("In", cmpop_type, NULL, 0); |
| 1163 | if (!In_type) return 0; |
| 1164 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
| 1165 | if (!In_singleton) return 0; |
| 1166 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
| 1167 | if (!NotIn_type) return 0; |
| 1168 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
| 1169 | if (!NotIn_singleton) return 0; |
| 1170 | comprehension_type = make_type("comprehension", &AST_type, |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 1171 | comprehension_fields, 4); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1172 | if (!comprehension_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1173 | if (!add_attributes(comprehension_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1174 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
| 1175 | if (!excepthandler_type) return 0; |
| 1176 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
| 1177 | return 0; |
| 1178 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 1179 | ExceptHandler_fields, 3); |
| 1180 | if (!ExceptHandler_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1181 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 6); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1182 | if (!arguments_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1183 | if (!add_attributes(arguments_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1184 | arg_type = make_type("arg", &AST_type, arg_fields, 2); |
| 1185 | if (!arg_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1186 | if (!add_attributes(arg_type, arg_attributes, 2)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1187 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
| 1188 | if (!keyword_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1189 | if (!add_attributes(keyword_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1190 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
| 1191 | if (!alias_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1192 | if (!add_attributes(alias_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1193 | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
| 1194 | if (!withitem_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1195 | if (!add_attributes(withitem_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1196 | initialized = 1; |
| 1197 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1198 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1199 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1200 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1201 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1202 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1203 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1204 | arena); |
| 1205 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1206 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1207 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1208 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1209 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1210 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1211 | arena); |
| 1212 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1213 | arena); |
| 1214 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1215 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1216 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1217 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1218 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1219 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1220 | mod_ty |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 1221 | Module(asdl_seq * body, string docstring, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1222 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1223 | mod_ty p; |
| 1224 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1225 | if (!p) |
| 1226 | return NULL; |
| 1227 | p->kind = Module_kind; |
| 1228 | p->v.Module.body = body; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 1229 | p->v.Module.docstring = docstring; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1230 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1234 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1235 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1236 | mod_ty p; |
| 1237 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1238 | if (!p) |
| 1239 | return NULL; |
| 1240 | p->kind = Interactive_kind; |
| 1241 | p->v.Interactive.body = body; |
| 1242 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1246 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1247 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1248 | mod_ty p; |
| 1249 | if (!body) { |
| 1250 | PyErr_SetString(PyExc_ValueError, |
| 1251 | "field body is required for Expression"); |
| 1252 | return NULL; |
| 1253 | } |
| 1254 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1255 | if (!p) |
| 1256 | return NULL; |
| 1257 | p->kind = Expression_kind; |
| 1258 | p->v.Expression.body = body; |
| 1259 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1263 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1264 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1265 | mod_ty p; |
| 1266 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1267 | if (!p) |
| 1268 | return NULL; |
| 1269 | p->kind = Suite_kind; |
| 1270 | p->v.Suite.body = body; |
| 1271 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | stmt_ty |
| 1275 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 1276 | decorator_list, expr_ty returns, string docstring, int lineno, int |
| 1277 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1278 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1279 | stmt_ty p; |
| 1280 | if (!name) { |
| 1281 | PyErr_SetString(PyExc_ValueError, |
| 1282 | "field name is required for FunctionDef"); |
| 1283 | return NULL; |
| 1284 | } |
| 1285 | if (!args) { |
| 1286 | PyErr_SetString(PyExc_ValueError, |
| 1287 | "field args is required for FunctionDef"); |
| 1288 | return NULL; |
| 1289 | } |
| 1290 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1291 | if (!p) |
| 1292 | return NULL; |
| 1293 | p->kind = FunctionDef_kind; |
| 1294 | p->v.FunctionDef.name = name; |
| 1295 | p->v.FunctionDef.args = args; |
| 1296 | p->v.FunctionDef.body = body; |
| 1297 | p->v.FunctionDef.decorator_list = decorator_list; |
| 1298 | p->v.FunctionDef.returns = returns; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 1299 | p->v.FunctionDef.docstring = docstring; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1300 | p->lineno = lineno; |
| 1301 | p->col_offset = col_offset; |
| 1302 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1306 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 1307 | * decorator_list, expr_ty returns, string docstring, int |
| 1308 | lineno, int col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1309 | { |
| 1310 | stmt_ty p; |
| 1311 | if (!name) { |
| 1312 | PyErr_SetString(PyExc_ValueError, |
| 1313 | "field name is required for AsyncFunctionDef"); |
| 1314 | return NULL; |
| 1315 | } |
| 1316 | if (!args) { |
| 1317 | PyErr_SetString(PyExc_ValueError, |
| 1318 | "field args is required for AsyncFunctionDef"); |
| 1319 | return NULL; |
| 1320 | } |
| 1321 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1322 | if (!p) |
| 1323 | return NULL; |
| 1324 | p->kind = AsyncFunctionDef_kind; |
| 1325 | p->v.AsyncFunctionDef.name = name; |
| 1326 | p->v.AsyncFunctionDef.args = args; |
| 1327 | p->v.AsyncFunctionDef.body = body; |
| 1328 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 1329 | p->v.AsyncFunctionDef.returns = returns; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 1330 | p->v.AsyncFunctionDef.docstring = docstring; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1331 | p->lineno = lineno; |
| 1332 | p->col_offset = col_offset; |
| 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 * |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 1338 | body, asdl_seq * decorator_list, string docstring, int lineno, int |
| 1339 | 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; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 1356 | p->v.ClassDef.docstring = docstring; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1357 | p->lineno = lineno; |
| 1358 | p->col_offset = col_offset; |
| 1359 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1363 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1364 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1365 | stmt_ty p; |
| 1366 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1367 | if (!p) |
| 1368 | return NULL; |
| 1369 | p->kind = Return_kind; |
| 1370 | p->v.Return.value = value; |
| 1371 | p->lineno = lineno; |
| 1372 | p->col_offset = col_offset; |
| 1373 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1377 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1378 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1379 | stmt_ty p; |
| 1380 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1381 | if (!p) |
| 1382 | return NULL; |
| 1383 | p->kind = Delete_kind; |
| 1384 | p->v.Delete.targets = targets; |
| 1385 | p->lineno = lineno; |
| 1386 | p->col_offset = col_offset; |
| 1387 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1391 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 1392 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1393 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1394 | stmt_ty p; |
| 1395 | if (!value) { |
| 1396 | PyErr_SetString(PyExc_ValueError, |
| 1397 | "field value is required for Assign"); |
| 1398 | return NULL; |
| 1399 | } |
| 1400 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1401 | if (!p) |
| 1402 | return NULL; |
| 1403 | p->kind = Assign_kind; |
| 1404 | p->v.Assign.targets = targets; |
| 1405 | p->v.Assign.value = value; |
| 1406 | p->lineno = lineno; |
| 1407 | p->col_offset = col_offset; |
| 1408 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1412 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 1413 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1414 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1415 | stmt_ty p; |
| 1416 | if (!target) { |
| 1417 | PyErr_SetString(PyExc_ValueError, |
| 1418 | "field target is required for AugAssign"); |
| 1419 | return NULL; |
| 1420 | } |
| 1421 | if (!op) { |
| 1422 | PyErr_SetString(PyExc_ValueError, |
| 1423 | "field op is required for AugAssign"); |
| 1424 | return NULL; |
| 1425 | } |
| 1426 | if (!value) { |
| 1427 | PyErr_SetString(PyExc_ValueError, |
| 1428 | "field value is required for AugAssign"); |
| 1429 | return NULL; |
| 1430 | } |
| 1431 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1432 | if (!p) |
| 1433 | return NULL; |
| 1434 | p->kind = AugAssign_kind; |
| 1435 | p->v.AugAssign.target = target; |
| 1436 | p->v.AugAssign.op = op; |
| 1437 | p->v.AugAssign.value = value; |
| 1438 | p->lineno = lineno; |
| 1439 | p->col_offset = col_offset; |
| 1440 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 1444 | AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int |
| 1445 | lineno, int col_offset, PyArena *arena) |
| 1446 | { |
| 1447 | stmt_ty p; |
| 1448 | if (!target) { |
| 1449 | PyErr_SetString(PyExc_ValueError, |
| 1450 | "field target is required for AnnAssign"); |
| 1451 | return NULL; |
| 1452 | } |
| 1453 | if (!annotation) { |
| 1454 | PyErr_SetString(PyExc_ValueError, |
| 1455 | "field annotation is required for AnnAssign"); |
| 1456 | return NULL; |
| 1457 | } |
| 1458 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1459 | if (!p) |
| 1460 | return NULL; |
| 1461 | p->kind = AnnAssign_kind; |
| 1462 | p->v.AnnAssign.target = target; |
| 1463 | p->v.AnnAssign.annotation = annotation; |
| 1464 | p->v.AnnAssign.value = value; |
| 1465 | p->v.AnnAssign.simple = simple; |
| 1466 | p->lineno = lineno; |
| 1467 | p->col_offset = col_offset; |
| 1468 | return p; |
| 1469 | } |
| 1470 | |
| 1471 | stmt_ty |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1472 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1473 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1474 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1475 | stmt_ty p; |
| 1476 | if (!target) { |
| 1477 | PyErr_SetString(PyExc_ValueError, |
| 1478 | "field target is required for For"); |
| 1479 | return NULL; |
| 1480 | } |
| 1481 | if (!iter) { |
| 1482 | PyErr_SetString(PyExc_ValueError, |
| 1483 | "field iter is required for For"); |
| 1484 | return NULL; |
| 1485 | } |
| 1486 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1487 | if (!p) |
| 1488 | return NULL; |
| 1489 | p->kind = For_kind; |
| 1490 | p->v.For.target = target; |
| 1491 | p->v.For.iter = iter; |
| 1492 | p->v.For.body = body; |
| 1493 | p->v.For.orelse = orelse; |
| 1494 | p->lineno = lineno; |
| 1495 | p->col_offset = col_offset; |
| 1496 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1500 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int |
| 1501 | lineno, int col_offset, PyArena *arena) |
| 1502 | { |
| 1503 | stmt_ty p; |
| 1504 | if (!target) { |
| 1505 | PyErr_SetString(PyExc_ValueError, |
| 1506 | "field target is required for AsyncFor"); |
| 1507 | return NULL; |
| 1508 | } |
| 1509 | if (!iter) { |
| 1510 | PyErr_SetString(PyExc_ValueError, |
| 1511 | "field iter is required for AsyncFor"); |
| 1512 | return NULL; |
| 1513 | } |
| 1514 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1515 | if (!p) |
| 1516 | return NULL; |
| 1517 | p->kind = AsyncFor_kind; |
| 1518 | p->v.AsyncFor.target = target; |
| 1519 | p->v.AsyncFor.iter = iter; |
| 1520 | p->v.AsyncFor.body = body; |
| 1521 | p->v.AsyncFor.orelse = orelse; |
| 1522 | p->lineno = lineno; |
| 1523 | p->col_offset = col_offset; |
| 1524 | return p; |
| 1525 | } |
| 1526 | |
| 1527 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1528 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1529 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1530 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1531 | stmt_ty p; |
| 1532 | if (!test) { |
| 1533 | PyErr_SetString(PyExc_ValueError, |
| 1534 | "field test is required for While"); |
| 1535 | return NULL; |
| 1536 | } |
| 1537 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1538 | if (!p) |
| 1539 | return NULL; |
| 1540 | p->kind = While_kind; |
| 1541 | p->v.While.test = test; |
| 1542 | p->v.While.body = body; |
| 1543 | p->v.While.orelse = orelse; |
| 1544 | p->lineno = lineno; |
| 1545 | p->col_offset = col_offset; |
| 1546 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1550 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1551 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1552 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1553 | stmt_ty p; |
| 1554 | if (!test) { |
| 1555 | PyErr_SetString(PyExc_ValueError, |
| 1556 | "field test is required for If"); |
| 1557 | return NULL; |
| 1558 | } |
| 1559 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1560 | if (!p) |
| 1561 | return NULL; |
| 1562 | p->kind = If_kind; |
| 1563 | p->v.If.test = test; |
| 1564 | p->v.If.body = body; |
| 1565 | p->v.If.orelse = orelse; |
| 1566 | p->lineno = lineno; |
| 1567 | p->col_offset = col_offset; |
| 1568 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | stmt_ty |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1572 | With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena |
| 1573 | *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1574 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1575 | stmt_ty p; |
| 1576 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1577 | if (!p) |
| 1578 | return NULL; |
| 1579 | p->kind = With_kind; |
| 1580 | p->v.With.items = items; |
| 1581 | p->v.With.body = body; |
| 1582 | p->lineno = lineno; |
| 1583 | p->col_offset = col_offset; |
| 1584 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1588 | AsyncWith(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, |
| 1589 | PyArena *arena) |
| 1590 | { |
| 1591 | stmt_ty p; |
| 1592 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1593 | if (!p) |
| 1594 | return NULL; |
| 1595 | p->kind = AsyncWith_kind; |
| 1596 | p->v.AsyncWith.items = items; |
| 1597 | p->v.AsyncWith.body = body; |
| 1598 | p->lineno = lineno; |
| 1599 | p->col_offset = col_offset; |
| 1600 | return p; |
| 1601 | } |
| 1602 | |
| 1603 | stmt_ty |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1604 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1605 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1606 | stmt_ty p; |
| 1607 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1608 | if (!p) |
| 1609 | return NULL; |
| 1610 | p->kind = Raise_kind; |
| 1611 | p->v.Raise.exc = exc; |
| 1612 | p->v.Raise.cause = cause; |
| 1613 | p->lineno = lineno; |
| 1614 | p->col_offset = col_offset; |
| 1615 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1619 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
| 1620 | finalbody, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1621 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1622 | stmt_ty p; |
| 1623 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1624 | if (!p) |
| 1625 | return NULL; |
| 1626 | p->kind = Try_kind; |
| 1627 | p->v.Try.body = body; |
| 1628 | p->v.Try.handlers = handlers; |
| 1629 | p->v.Try.orelse = orelse; |
| 1630 | p->v.Try.finalbody = finalbody; |
| 1631 | p->lineno = lineno; |
| 1632 | p->col_offset = col_offset; |
| 1633 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1637 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1638 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1639 | stmt_ty p; |
| 1640 | if (!test) { |
| 1641 | PyErr_SetString(PyExc_ValueError, |
| 1642 | "field test is required for Assert"); |
| 1643 | return NULL; |
| 1644 | } |
| 1645 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1646 | if (!p) |
| 1647 | return NULL; |
| 1648 | p->kind = Assert_kind; |
| 1649 | p->v.Assert.test = test; |
| 1650 | p->v.Assert.msg = msg; |
| 1651 | p->lineno = lineno; |
| 1652 | p->col_offset = col_offset; |
| 1653 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1657 | Import(asdl_seq * names, int lineno, int col_offset, 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 = Import_kind; |
| 1664 | p->v.Import.names = names; |
| 1665 | p->lineno = lineno; |
| 1666 | p->col_offset = col_offset; |
| 1667 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1671 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1672 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1673 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1674 | stmt_ty p; |
| 1675 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1676 | if (!p) |
| 1677 | return NULL; |
| 1678 | p->kind = ImportFrom_kind; |
| 1679 | p->v.ImportFrom.module = module; |
| 1680 | p->v.ImportFrom.names = names; |
| 1681 | p->v.ImportFrom.level = level; |
| 1682 | p->lineno = lineno; |
| 1683 | p->col_offset = col_offset; |
| 1684 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1688 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1689 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1690 | stmt_ty p; |
| 1691 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1692 | if (!p) |
| 1693 | return NULL; |
| 1694 | p->kind = Global_kind; |
| 1695 | p->v.Global.names = names; |
| 1696 | p->lineno = lineno; |
| 1697 | p->col_offset = col_offset; |
| 1698 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | stmt_ty |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1702 | Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 1703 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1704 | stmt_ty p; |
| 1705 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1706 | if (!p) |
| 1707 | return NULL; |
| 1708 | p->kind = Nonlocal_kind; |
| 1709 | p->v.Nonlocal.names = names; |
| 1710 | p->lineno = lineno; |
| 1711 | p->col_offset = col_offset; |
| 1712 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1716 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1717 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1718 | stmt_ty p; |
| 1719 | if (!value) { |
| 1720 | PyErr_SetString(PyExc_ValueError, |
| 1721 | "field value is required for Expr"); |
| 1722 | return NULL; |
| 1723 | } |
| 1724 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1725 | if (!p) |
| 1726 | return NULL; |
| 1727 | p->kind = Expr_kind; |
| 1728 | p->v.Expr.value = value; |
| 1729 | p->lineno = lineno; |
| 1730 | p->col_offset = col_offset; |
| 1731 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1735 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1736 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1737 | stmt_ty p; |
| 1738 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1739 | if (!p) |
| 1740 | return NULL; |
| 1741 | p->kind = Pass_kind; |
| 1742 | p->lineno = lineno; |
| 1743 | p->col_offset = col_offset; |
| 1744 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1748 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1749 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1750 | stmt_ty p; |
| 1751 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1752 | if (!p) |
| 1753 | return NULL; |
| 1754 | p->kind = Break_kind; |
| 1755 | p->lineno = lineno; |
| 1756 | p->col_offset = col_offset; |
| 1757 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1761 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1762 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1763 | stmt_ty p; |
| 1764 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1765 | if (!p) |
| 1766 | return NULL; |
| 1767 | p->kind = Continue_kind; |
| 1768 | p->lineno = lineno; |
| 1769 | p->col_offset = col_offset; |
| 1770 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1774 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1775 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1776 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1777 | expr_ty p; |
| 1778 | if (!op) { |
| 1779 | PyErr_SetString(PyExc_ValueError, |
| 1780 | "field op is required for BoolOp"); |
| 1781 | return NULL; |
| 1782 | } |
| 1783 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1784 | if (!p) |
| 1785 | return NULL; |
| 1786 | p->kind = BoolOp_kind; |
| 1787 | p->v.BoolOp.op = op; |
| 1788 | p->v.BoolOp.values = values; |
| 1789 | p->lineno = lineno; |
| 1790 | p->col_offset = col_offset; |
| 1791 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1795 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1796 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1797 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1798 | expr_ty p; |
| 1799 | if (!left) { |
| 1800 | PyErr_SetString(PyExc_ValueError, |
| 1801 | "field left is required for BinOp"); |
| 1802 | return NULL; |
| 1803 | } |
| 1804 | if (!op) { |
| 1805 | PyErr_SetString(PyExc_ValueError, |
| 1806 | "field op is required for BinOp"); |
| 1807 | return NULL; |
| 1808 | } |
| 1809 | if (!right) { |
| 1810 | PyErr_SetString(PyExc_ValueError, |
| 1811 | "field right is required for BinOp"); |
| 1812 | return NULL; |
| 1813 | } |
| 1814 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1815 | if (!p) |
| 1816 | return NULL; |
| 1817 | p->kind = BinOp_kind; |
| 1818 | p->v.BinOp.left = left; |
| 1819 | p->v.BinOp.op = op; |
| 1820 | p->v.BinOp.right = right; |
| 1821 | p->lineno = lineno; |
| 1822 | p->col_offset = col_offset; |
| 1823 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1827 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1828 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1829 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1830 | expr_ty p; |
| 1831 | if (!op) { |
| 1832 | PyErr_SetString(PyExc_ValueError, |
| 1833 | "field op is required for UnaryOp"); |
| 1834 | return NULL; |
| 1835 | } |
| 1836 | if (!operand) { |
| 1837 | PyErr_SetString(PyExc_ValueError, |
| 1838 | "field operand is required for UnaryOp"); |
| 1839 | return NULL; |
| 1840 | } |
| 1841 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1842 | if (!p) |
| 1843 | return NULL; |
| 1844 | p->kind = UnaryOp_kind; |
| 1845 | p->v.UnaryOp.op = op; |
| 1846 | p->v.UnaryOp.operand = operand; |
| 1847 | p->lineno = lineno; |
| 1848 | p->col_offset = col_offset; |
| 1849 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1853 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1854 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1855 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1856 | expr_ty p; |
| 1857 | if (!args) { |
| 1858 | PyErr_SetString(PyExc_ValueError, |
| 1859 | "field args is required for Lambda"); |
| 1860 | return NULL; |
| 1861 | } |
| 1862 | if (!body) { |
| 1863 | PyErr_SetString(PyExc_ValueError, |
| 1864 | "field body is required for Lambda"); |
| 1865 | return NULL; |
| 1866 | } |
| 1867 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1868 | if (!p) |
| 1869 | return NULL; |
| 1870 | p->kind = Lambda_kind; |
| 1871 | p->v.Lambda.args = args; |
| 1872 | p->v.Lambda.body = body; |
| 1873 | p->lineno = lineno; |
| 1874 | p->col_offset = col_offset; |
| 1875 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1879 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1880 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1881 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1882 | expr_ty p; |
| 1883 | if (!test) { |
| 1884 | PyErr_SetString(PyExc_ValueError, |
| 1885 | "field test is required for IfExp"); |
| 1886 | return NULL; |
| 1887 | } |
| 1888 | if (!body) { |
| 1889 | PyErr_SetString(PyExc_ValueError, |
| 1890 | "field body is required for IfExp"); |
| 1891 | return NULL; |
| 1892 | } |
| 1893 | if (!orelse) { |
| 1894 | PyErr_SetString(PyExc_ValueError, |
| 1895 | "field orelse is required for IfExp"); |
| 1896 | return NULL; |
| 1897 | } |
| 1898 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1899 | if (!p) |
| 1900 | return NULL; |
| 1901 | p->kind = IfExp_kind; |
| 1902 | p->v.IfExp.test = test; |
| 1903 | p->v.IfExp.body = body; |
| 1904 | p->v.IfExp.orelse = orelse; |
| 1905 | p->lineno = lineno; |
| 1906 | p->col_offset = col_offset; |
| 1907 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1911 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1912 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1913 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1914 | expr_ty p; |
| 1915 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1916 | if (!p) |
| 1917 | return NULL; |
| 1918 | p->kind = Dict_kind; |
| 1919 | p->v.Dict.keys = keys; |
| 1920 | p->v.Dict.values = values; |
| 1921 | p->lineno = lineno; |
| 1922 | p->col_offset = col_offset; |
| 1923 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | expr_ty |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1927 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
| 1928 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1929 | expr_ty p; |
| 1930 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1931 | if (!p) |
| 1932 | return NULL; |
| 1933 | p->kind = Set_kind; |
| 1934 | p->v.Set.elts = elts; |
| 1935 | p->lineno = lineno; |
| 1936 | p->col_offset = col_offset; |
| 1937 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1941 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1942 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1943 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1944 | expr_ty p; |
| 1945 | if (!elt) { |
| 1946 | PyErr_SetString(PyExc_ValueError, |
| 1947 | "field elt is required for ListComp"); |
| 1948 | return NULL; |
| 1949 | } |
| 1950 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1951 | if (!p) |
| 1952 | return NULL; |
| 1953 | p->kind = ListComp_kind; |
| 1954 | p->v.ListComp.elt = elt; |
| 1955 | p->v.ListComp.generators = generators; |
| 1956 | p->lineno = lineno; |
| 1957 | p->col_offset = col_offset; |
| 1958 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | expr_ty |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1962 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
| 1963 | *arena) |
| 1964 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1965 | expr_ty p; |
| 1966 | if (!elt) { |
| 1967 | PyErr_SetString(PyExc_ValueError, |
| 1968 | "field elt is required for SetComp"); |
| 1969 | return NULL; |
| 1970 | } |
| 1971 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1972 | if (!p) |
| 1973 | return NULL; |
| 1974 | p->kind = SetComp_kind; |
| 1975 | p->v.SetComp.elt = elt; |
| 1976 | p->v.SetComp.generators = generators; |
| 1977 | p->lineno = lineno; |
| 1978 | p->col_offset = col_offset; |
| 1979 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1983 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
| 1984 | col_offset, PyArena *arena) |
| 1985 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1986 | expr_ty p; |
| 1987 | if (!key) { |
| 1988 | PyErr_SetString(PyExc_ValueError, |
| 1989 | "field key is required for DictComp"); |
| 1990 | return NULL; |
| 1991 | } |
| 1992 | if (!value) { |
| 1993 | PyErr_SetString(PyExc_ValueError, |
| 1994 | "field value is required for DictComp"); |
| 1995 | return NULL; |
| 1996 | } |
| 1997 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1998 | if (!p) |
| 1999 | return NULL; |
| 2000 | p->kind = DictComp_kind; |
| 2001 | p->v.DictComp.key = key; |
| 2002 | p->v.DictComp.value = value; |
| 2003 | p->v.DictComp.generators = generators; |
| 2004 | p->lineno = lineno; |
| 2005 | p->col_offset = col_offset; |
| 2006 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2010 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 2011 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2012 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2013 | expr_ty p; |
| 2014 | if (!elt) { |
| 2015 | PyErr_SetString(PyExc_ValueError, |
| 2016 | "field elt is required for GeneratorExp"); |
| 2017 | return NULL; |
| 2018 | } |
| 2019 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2020 | if (!p) |
| 2021 | return NULL; |
| 2022 | p->kind = GeneratorExp_kind; |
| 2023 | p->v.GeneratorExp.elt = elt; |
| 2024 | p->v.GeneratorExp.generators = generators; |
| 2025 | p->lineno = lineno; |
| 2026 | p->col_offset = col_offset; |
| 2027 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2028 | } |
| 2029 | |
| 2030 | expr_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2031 | Await(expr_ty value, int lineno, int col_offset, PyArena *arena) |
| 2032 | { |
| 2033 | expr_ty p; |
| 2034 | if (!value) { |
| 2035 | PyErr_SetString(PyExc_ValueError, |
| 2036 | "field value is required for Await"); |
| 2037 | return NULL; |
| 2038 | } |
| 2039 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2040 | if (!p) |
| 2041 | return NULL; |
| 2042 | p->kind = Await_kind; |
| 2043 | p->v.Await.value = value; |
| 2044 | p->lineno = lineno; |
| 2045 | p->col_offset = col_offset; |
| 2046 | return p; |
| 2047 | } |
| 2048 | |
| 2049 | expr_ty |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2050 | Yield(expr_ty value, int lineno, int 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 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2054 | if (!p) |
| 2055 | return NULL; |
| 2056 | p->kind = Yield_kind; |
| 2057 | p->v.Yield.value = value; |
| 2058 | p->lineno = lineno; |
| 2059 | p->col_offset = col_offset; |
| 2060 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | expr_ty |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2064 | YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena) |
| 2065 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2066 | expr_ty p; |
| 2067 | if (!value) { |
| 2068 | PyErr_SetString(PyExc_ValueError, |
| 2069 | "field value is required for YieldFrom"); |
| 2070 | return NULL; |
| 2071 | } |
| 2072 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2073 | if (!p) |
| 2074 | return NULL; |
| 2075 | p->kind = YieldFrom_kind; |
| 2076 | p->v.YieldFrom.value = value; |
| 2077 | p->lineno = lineno; |
| 2078 | p->col_offset = col_offset; |
| 2079 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2083 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 2084 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2085 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2086 | expr_ty p; |
| 2087 | if (!left) { |
| 2088 | PyErr_SetString(PyExc_ValueError, |
| 2089 | "field left is required for Compare"); |
| 2090 | return NULL; |
| 2091 | } |
| 2092 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2093 | if (!p) |
| 2094 | return NULL; |
| 2095 | p->kind = Compare_kind; |
| 2096 | p->v.Compare.left = left; |
| 2097 | p->v.Compare.ops = ops; |
| 2098 | p->v.Compare.comparators = comparators; |
| 2099 | p->lineno = lineno; |
| 2100 | p->col_offset = col_offset; |
| 2101 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2105 | Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int |
| 2106 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2107 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2108 | expr_ty p; |
| 2109 | if (!func) { |
| 2110 | PyErr_SetString(PyExc_ValueError, |
| 2111 | "field func is required for Call"); |
| 2112 | return NULL; |
| 2113 | } |
| 2114 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2115 | if (!p) |
| 2116 | return NULL; |
| 2117 | p->kind = Call_kind; |
| 2118 | p->v.Call.func = func; |
| 2119 | p->v.Call.args = args; |
| 2120 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2121 | p->lineno = lineno; |
| 2122 | p->col_offset = col_offset; |
| 2123 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2127 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2128 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2129 | expr_ty p; |
| 2130 | if (!n) { |
| 2131 | PyErr_SetString(PyExc_ValueError, |
| 2132 | "field n is required for Num"); |
| 2133 | return NULL; |
| 2134 | } |
| 2135 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2136 | if (!p) |
| 2137 | return NULL; |
| 2138 | p->kind = Num_kind; |
| 2139 | p->v.Num.n = n; |
| 2140 | p->lineno = lineno; |
| 2141 | p->col_offset = col_offset; |
| 2142 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2146 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2147 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2148 | expr_ty p; |
| 2149 | if (!s) { |
| 2150 | PyErr_SetString(PyExc_ValueError, |
| 2151 | "field s is required for Str"); |
| 2152 | return NULL; |
| 2153 | } |
| 2154 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2155 | if (!p) |
| 2156 | return NULL; |
| 2157 | p->kind = Str_kind; |
| 2158 | p->v.Str.s = s; |
| 2159 | p->lineno = lineno; |
| 2160 | p->col_offset = col_offset; |
| 2161 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | expr_ty |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2165 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
| 2166 | int col_offset, PyArena *arena) |
| 2167 | { |
| 2168 | expr_ty p; |
| 2169 | if (!value) { |
| 2170 | PyErr_SetString(PyExc_ValueError, |
| 2171 | "field value is required for FormattedValue"); |
| 2172 | return NULL; |
| 2173 | } |
| 2174 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2175 | if (!p) |
| 2176 | return NULL; |
| 2177 | p->kind = FormattedValue_kind; |
| 2178 | p->v.FormattedValue.value = value; |
| 2179 | p->v.FormattedValue.conversion = conversion; |
| 2180 | p->v.FormattedValue.format_spec = format_spec; |
| 2181 | p->lineno = lineno; |
| 2182 | p->col_offset = col_offset; |
| 2183 | return p; |
| 2184 | } |
| 2185 | |
| 2186 | expr_ty |
| 2187 | JoinedStr(asdl_seq * values, int lineno, int col_offset, PyArena *arena) |
| 2188 | { |
| 2189 | expr_ty p; |
| 2190 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2191 | if (!p) |
| 2192 | return NULL; |
| 2193 | p->kind = JoinedStr_kind; |
| 2194 | p->v.JoinedStr.values = values; |
| 2195 | p->lineno = lineno; |
| 2196 | p->col_offset = col_offset; |
| 2197 | return p; |
| 2198 | } |
| 2199 | |
| 2200 | expr_ty |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 2201 | Bytes(bytes s, int lineno, int col_offset, PyArena *arena) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2202 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2203 | expr_ty p; |
| 2204 | if (!s) { |
| 2205 | PyErr_SetString(PyExc_ValueError, |
| 2206 | "field s is required for Bytes"); |
| 2207 | return NULL; |
| 2208 | } |
| 2209 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2210 | if (!p) |
| 2211 | return NULL; |
| 2212 | p->kind = Bytes_kind; |
| 2213 | p->v.Bytes.s = s; |
| 2214 | p->lineno = lineno; |
| 2215 | p->col_offset = col_offset; |
| 2216 | return p; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2217 | } |
| 2218 | |
| 2219 | expr_ty |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 2220 | NameConstant(singleton value, int lineno, int col_offset, PyArena *arena) |
| 2221 | { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 2222 | expr_ty p; |
| 2223 | if (!value) { |
| 2224 | PyErr_SetString(PyExc_ValueError, |
| 2225 | "field value is required for NameConstant"); |
| 2226 | return NULL; |
| 2227 | } |
| 2228 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2229 | if (!p) |
| 2230 | return NULL; |
| 2231 | p->kind = NameConstant_kind; |
| 2232 | p->v.NameConstant.value = value; |
| 2233 | p->lineno = lineno; |
| 2234 | p->col_offset = col_offset; |
| 2235 | return p; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | expr_ty |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 2239 | Ellipsis(int lineno, int col_offset, PyArena *arena) |
| 2240 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2241 | expr_ty p; |
| 2242 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2243 | if (!p) |
| 2244 | return NULL; |
| 2245 | p->kind = Ellipsis_kind; |
| 2246 | p->lineno = lineno; |
| 2247 | p->col_offset = col_offset; |
| 2248 | return p; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | expr_ty |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2252 | Constant(constant value, int lineno, int col_offset, PyArena *arena) |
| 2253 | { |
| 2254 | expr_ty p; |
| 2255 | if (!value) { |
| 2256 | PyErr_SetString(PyExc_ValueError, |
| 2257 | "field value is required for Constant"); |
| 2258 | return NULL; |
| 2259 | } |
| 2260 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2261 | if (!p) |
| 2262 | return NULL; |
| 2263 | p->kind = Constant_kind; |
| 2264 | p->v.Constant.value = value; |
| 2265 | p->lineno = lineno; |
| 2266 | p->col_offset = col_offset; |
| 2267 | return p; |
| 2268 | } |
| 2269 | |
| 2270 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2271 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 2272 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2273 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2274 | expr_ty p; |
| 2275 | if (!value) { |
| 2276 | PyErr_SetString(PyExc_ValueError, |
| 2277 | "field value is required for Attribute"); |
| 2278 | return NULL; |
| 2279 | } |
| 2280 | if (!attr) { |
| 2281 | PyErr_SetString(PyExc_ValueError, |
| 2282 | "field attr is required for Attribute"); |
| 2283 | return NULL; |
| 2284 | } |
| 2285 | if (!ctx) { |
| 2286 | PyErr_SetString(PyExc_ValueError, |
| 2287 | "field ctx is required for Attribute"); |
| 2288 | return NULL; |
| 2289 | } |
| 2290 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2291 | if (!p) |
| 2292 | return NULL; |
| 2293 | p->kind = Attribute_kind; |
| 2294 | p->v.Attribute.value = value; |
| 2295 | p->v.Attribute.attr = attr; |
| 2296 | p->v.Attribute.ctx = ctx; |
| 2297 | p->lineno = lineno; |
| 2298 | p->col_offset = col_offset; |
| 2299 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2303 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 2304 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2305 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2306 | expr_ty p; |
| 2307 | if (!value) { |
| 2308 | PyErr_SetString(PyExc_ValueError, |
| 2309 | "field value is required for Subscript"); |
| 2310 | return NULL; |
| 2311 | } |
| 2312 | if (!slice) { |
| 2313 | PyErr_SetString(PyExc_ValueError, |
| 2314 | "field slice is required for Subscript"); |
| 2315 | return NULL; |
| 2316 | } |
| 2317 | if (!ctx) { |
| 2318 | PyErr_SetString(PyExc_ValueError, |
| 2319 | "field ctx is required for Subscript"); |
| 2320 | return NULL; |
| 2321 | } |
| 2322 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2323 | if (!p) |
| 2324 | return NULL; |
| 2325 | p->kind = Subscript_kind; |
| 2326 | p->v.Subscript.value = value; |
| 2327 | p->v.Subscript.slice = slice; |
| 2328 | p->v.Subscript.ctx = ctx; |
| 2329 | p->lineno = lineno; |
| 2330 | p->col_offset = col_offset; |
| 2331 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | expr_ty |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2335 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2336 | *arena) |
| 2337 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2338 | expr_ty p; |
| 2339 | if (!value) { |
| 2340 | PyErr_SetString(PyExc_ValueError, |
| 2341 | "field value is required for Starred"); |
| 2342 | return NULL; |
| 2343 | } |
| 2344 | if (!ctx) { |
| 2345 | PyErr_SetString(PyExc_ValueError, |
| 2346 | "field ctx is required for Starred"); |
| 2347 | return NULL; |
| 2348 | } |
| 2349 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2350 | if (!p) |
| 2351 | return NULL; |
| 2352 | p->kind = Starred_kind; |
| 2353 | p->v.Starred.value = value; |
| 2354 | p->v.Starred.ctx = ctx; |
| 2355 | p->lineno = lineno; |
| 2356 | p->col_offset = col_offset; |
| 2357 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2361 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2362 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2363 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2364 | expr_ty p; |
| 2365 | if (!id) { |
| 2366 | PyErr_SetString(PyExc_ValueError, |
| 2367 | "field id is required for Name"); |
| 2368 | return NULL; |
| 2369 | } |
| 2370 | if (!ctx) { |
| 2371 | PyErr_SetString(PyExc_ValueError, |
| 2372 | "field ctx is required for Name"); |
| 2373 | return NULL; |
| 2374 | } |
| 2375 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2376 | if (!p) |
| 2377 | return NULL; |
| 2378 | p->kind = Name_kind; |
| 2379 | p->v.Name.id = id; |
| 2380 | p->v.Name.ctx = ctx; |
| 2381 | p->lineno = lineno; |
| 2382 | p->col_offset = col_offset; |
| 2383 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2387 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2388 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2389 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2390 | expr_ty p; |
| 2391 | if (!ctx) { |
| 2392 | PyErr_SetString(PyExc_ValueError, |
| 2393 | "field ctx is required for List"); |
| 2394 | return NULL; |
| 2395 | } |
| 2396 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2397 | if (!p) |
| 2398 | return NULL; |
| 2399 | p->kind = List_kind; |
| 2400 | p->v.List.elts = elts; |
| 2401 | p->v.List.ctx = ctx; |
| 2402 | p->lineno = lineno; |
| 2403 | p->col_offset = col_offset; |
| 2404 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2408 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2409 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2410 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2411 | expr_ty p; |
| 2412 | if (!ctx) { |
| 2413 | PyErr_SetString(PyExc_ValueError, |
| 2414 | "field ctx is required for Tuple"); |
| 2415 | return NULL; |
| 2416 | } |
| 2417 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2418 | if (!p) |
| 2419 | return NULL; |
| 2420 | p->kind = Tuple_kind; |
| 2421 | p->v.Tuple.elts = elts; |
| 2422 | p->v.Tuple.ctx = ctx; |
| 2423 | p->lineno = lineno; |
| 2424 | p->col_offset = col_offset; |
| 2425 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2426 | } |
| 2427 | |
| 2428 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2429 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2430 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2431 | slice_ty p; |
| 2432 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2433 | if (!p) |
| 2434 | return NULL; |
| 2435 | p->kind = Slice_kind; |
| 2436 | p->v.Slice.lower = lower; |
| 2437 | p->v.Slice.upper = upper; |
| 2438 | p->v.Slice.step = step; |
| 2439 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2443 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2444 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2445 | slice_ty p; |
| 2446 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2447 | if (!p) |
| 2448 | return NULL; |
| 2449 | p->kind = ExtSlice_kind; |
| 2450 | p->v.ExtSlice.dims = dims; |
| 2451 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2452 | } |
| 2453 | |
| 2454 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2455 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2456 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2457 | slice_ty p; |
| 2458 | if (!value) { |
| 2459 | PyErr_SetString(PyExc_ValueError, |
| 2460 | "field value is required for Index"); |
| 2461 | return NULL; |
| 2462 | } |
| 2463 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2464 | if (!p) |
| 2465 | return NULL; |
| 2466 | p->kind = Index_kind; |
| 2467 | p->v.Index.value = value; |
| 2468 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2469 | } |
| 2470 | |
| 2471 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 2472 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 2473 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2474 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2475 | comprehension_ty p; |
| 2476 | if (!target) { |
| 2477 | PyErr_SetString(PyExc_ValueError, |
| 2478 | "field target is required for comprehension"); |
| 2479 | return NULL; |
| 2480 | } |
| 2481 | if (!iter) { |
| 2482 | PyErr_SetString(PyExc_ValueError, |
| 2483 | "field iter is required for comprehension"); |
| 2484 | return NULL; |
| 2485 | } |
| 2486 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2487 | if (!p) |
| 2488 | return NULL; |
| 2489 | p->target = target; |
| 2490 | p->iter = iter; |
| 2491 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 2492 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2493 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2497 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2498 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2499 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2500 | excepthandler_ty p; |
| 2501 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2502 | if (!p) |
| 2503 | return NULL; |
| 2504 | p->kind = ExceptHandler_kind; |
| 2505 | p->v.ExceptHandler.type = type; |
| 2506 | p->v.ExceptHandler.name = name; |
| 2507 | p->v.ExceptHandler.body = body; |
| 2508 | p->lineno = lineno; |
| 2509 | p->col_offset = col_offset; |
| 2510 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | arguments_ty |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 2514 | arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq * |
| 2515 | kw_defaults, arg_ty kwarg, asdl_seq * defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2516 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2517 | arguments_ty p; |
| 2518 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2519 | if (!p) |
| 2520 | return NULL; |
| 2521 | p->args = args; |
| 2522 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2523 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2524 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 2525 | p->kwarg = kwarg; |
| 2526 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2527 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2528 | } |
| 2529 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2530 | arg_ty |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 2531 | arg(identifier arg, expr_ty annotation, int lineno, int col_offset, PyArena |
| 2532 | *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2533 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2534 | arg_ty p; |
| 2535 | if (!arg) { |
| 2536 | PyErr_SetString(PyExc_ValueError, |
| 2537 | "field arg is required for arg"); |
| 2538 | return NULL; |
| 2539 | } |
| 2540 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2541 | if (!p) |
| 2542 | return NULL; |
| 2543 | p->arg = arg; |
| 2544 | p->annotation = annotation; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 2545 | p->lineno = lineno; |
| 2546 | p->col_offset = col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2547 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2548 | } |
| 2549 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2550 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2551 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2552 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2553 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2554 | if (!value) { |
| 2555 | PyErr_SetString(PyExc_ValueError, |
| 2556 | "field value is required for keyword"); |
| 2557 | return NULL; |
| 2558 | } |
| 2559 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2560 | if (!p) |
| 2561 | return NULL; |
| 2562 | p->arg = arg; |
| 2563 | p->value = value; |
| 2564 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2565 | } |
| 2566 | |
| 2567 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2568 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2569 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2570 | alias_ty p; |
| 2571 | if (!name) { |
| 2572 | PyErr_SetString(PyExc_ValueError, |
| 2573 | "field name is required for alias"); |
| 2574 | return NULL; |
| 2575 | } |
| 2576 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2577 | if (!p) |
| 2578 | return NULL; |
| 2579 | p->name = name; |
| 2580 | p->asname = asname; |
| 2581 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2582 | } |
| 2583 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2584 | withitem_ty |
| 2585 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2586 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2587 | withitem_ty p; |
| 2588 | if (!context_expr) { |
| 2589 | PyErr_SetString(PyExc_ValueError, |
| 2590 | "field context_expr is required for withitem"); |
| 2591 | return NULL; |
| 2592 | } |
| 2593 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2594 | if (!p) |
| 2595 | return NULL; |
| 2596 | p->context_expr = context_expr; |
| 2597 | p->optional_vars = optional_vars; |
| 2598 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2599 | } |
| 2600 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2601 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2602 | PyObject* |
| 2603 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2604 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2605 | mod_ty o = (mod_ty)_o; |
| 2606 | PyObject *result = NULL, *value = NULL; |
| 2607 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 2608 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2609 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2610 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2611 | switch (o->kind) { |
| 2612 | case Module_kind: |
| 2613 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2614 | if (!result) goto failed; |
| 2615 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2616 | if (!value) goto failed; |
| 2617 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2618 | goto failed; |
| 2619 | Py_DECREF(value); |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 2620 | value = ast2obj_string(o->v.Module.docstring); |
| 2621 | if (!value) goto failed; |
| 2622 | if (_PyObject_SetAttrId(result, &PyId_docstring, value) == -1) |
| 2623 | goto failed; |
| 2624 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2625 | break; |
| 2626 | case Interactive_kind: |
| 2627 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2628 | if (!result) goto failed; |
| 2629 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2630 | if (!value) goto failed; |
| 2631 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2632 | goto failed; |
| 2633 | Py_DECREF(value); |
| 2634 | break; |
| 2635 | case Expression_kind: |
| 2636 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2637 | if (!result) goto failed; |
| 2638 | value = ast2obj_expr(o->v.Expression.body); |
| 2639 | if (!value) goto failed; |
| 2640 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2641 | goto failed; |
| 2642 | Py_DECREF(value); |
| 2643 | break; |
| 2644 | case Suite_kind: |
| 2645 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2646 | if (!result) goto failed; |
| 2647 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2648 | if (!value) goto failed; |
| 2649 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2650 | goto failed; |
| 2651 | Py_DECREF(value); |
| 2652 | break; |
| 2653 | } |
| 2654 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2655 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2656 | Py_XDECREF(value); |
| 2657 | Py_XDECREF(result); |
| 2658 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2659 | } |
| 2660 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2661 | PyObject* |
| 2662 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2663 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2664 | stmt_ty o = (stmt_ty)_o; |
| 2665 | PyObject *result = NULL, *value = NULL; |
| 2666 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 2667 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2668 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2669 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2670 | switch (o->kind) { |
| 2671 | case FunctionDef_kind: |
| 2672 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2673 | if (!result) goto failed; |
| 2674 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2675 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2676 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2677 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2678 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2679 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2680 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2681 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2682 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2683 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2684 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2685 | if (!value) goto failed; |
| 2686 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2687 | goto failed; |
| 2688 | Py_DECREF(value); |
| 2689 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 2690 | if (!value) goto failed; |
| 2691 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2692 | goto failed; |
| 2693 | Py_DECREF(value); |
| 2694 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2695 | if (!value) goto failed; |
| 2696 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2697 | goto failed; |
| 2698 | Py_DECREF(value); |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 2699 | value = ast2obj_string(o->v.FunctionDef.docstring); |
| 2700 | if (!value) goto failed; |
| 2701 | if (_PyObject_SetAttrId(result, &PyId_docstring, value) == -1) |
| 2702 | goto failed; |
| 2703 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2704 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2705 | case AsyncFunctionDef_kind: |
| 2706 | result = PyType_GenericNew(AsyncFunctionDef_type, NULL, NULL); |
| 2707 | if (!result) goto failed; |
| 2708 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 2709 | if (!value) goto failed; |
| 2710 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2711 | goto failed; |
| 2712 | Py_DECREF(value); |
| 2713 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 2714 | if (!value) goto failed; |
| 2715 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2716 | goto failed; |
| 2717 | Py_DECREF(value); |
| 2718 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 2719 | if (!value) goto failed; |
| 2720 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2721 | goto failed; |
| 2722 | Py_DECREF(value); |
| 2723 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 2724 | ast2obj_expr); |
| 2725 | if (!value) goto failed; |
| 2726 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2727 | goto failed; |
| 2728 | Py_DECREF(value); |
| 2729 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 2730 | if (!value) goto failed; |
| 2731 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2732 | goto failed; |
| 2733 | Py_DECREF(value); |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 2734 | value = ast2obj_string(o->v.AsyncFunctionDef.docstring); |
| 2735 | if (!value) goto failed; |
| 2736 | if (_PyObject_SetAttrId(result, &PyId_docstring, value) == -1) |
| 2737 | goto failed; |
| 2738 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2739 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2740 | case ClassDef_kind: |
| 2741 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2742 | if (!result) goto failed; |
| 2743 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2744 | if (!value) goto failed; |
| 2745 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2746 | goto failed; |
| 2747 | Py_DECREF(value); |
| 2748 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2749 | if (!value) goto failed; |
| 2750 | if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) |
| 2751 | goto failed; |
| 2752 | Py_DECREF(value); |
| 2753 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2754 | if (!value) goto failed; |
| 2755 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 2756 | goto failed; |
| 2757 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2758 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2759 | if (!value) goto failed; |
| 2760 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2761 | goto failed; |
| 2762 | Py_DECREF(value); |
| 2763 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 2764 | if (!value) goto failed; |
| 2765 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2766 | goto failed; |
| 2767 | Py_DECREF(value); |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 2768 | value = ast2obj_string(o->v.ClassDef.docstring); |
| 2769 | if (!value) goto failed; |
| 2770 | if (_PyObject_SetAttrId(result, &PyId_docstring, value) == -1) |
| 2771 | goto failed; |
| 2772 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2773 | break; |
| 2774 | case Return_kind: |
| 2775 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2776 | if (!result) goto failed; |
| 2777 | value = ast2obj_expr(o->v.Return.value); |
| 2778 | if (!value) goto failed; |
| 2779 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2780 | goto failed; |
| 2781 | Py_DECREF(value); |
| 2782 | break; |
| 2783 | case Delete_kind: |
| 2784 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2785 | if (!result) goto failed; |
| 2786 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2787 | if (!value) goto failed; |
| 2788 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2789 | goto failed; |
| 2790 | Py_DECREF(value); |
| 2791 | break; |
| 2792 | case Assign_kind: |
| 2793 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2794 | if (!result) goto failed; |
| 2795 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2796 | if (!value) goto failed; |
| 2797 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2798 | goto failed; |
| 2799 | Py_DECREF(value); |
| 2800 | value = ast2obj_expr(o->v.Assign.value); |
| 2801 | if (!value) goto failed; |
| 2802 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2803 | goto failed; |
| 2804 | Py_DECREF(value); |
| 2805 | break; |
| 2806 | case AugAssign_kind: |
| 2807 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2808 | if (!result) goto failed; |
| 2809 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2810 | if (!value) goto failed; |
| 2811 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2812 | goto failed; |
| 2813 | Py_DECREF(value); |
| 2814 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2815 | if (!value) goto failed; |
| 2816 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2817 | goto failed; |
| 2818 | Py_DECREF(value); |
| 2819 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2820 | if (!value) goto failed; |
| 2821 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2822 | goto failed; |
| 2823 | Py_DECREF(value); |
| 2824 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2825 | case AnnAssign_kind: |
| 2826 | result = PyType_GenericNew(AnnAssign_type, NULL, NULL); |
| 2827 | if (!result) goto failed; |
| 2828 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 2829 | if (!value) goto failed; |
| 2830 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2831 | goto failed; |
| 2832 | Py_DECREF(value); |
| 2833 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 2834 | if (!value) goto failed; |
| 2835 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 2836 | goto failed; |
| 2837 | Py_DECREF(value); |
| 2838 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 2839 | if (!value) goto failed; |
| 2840 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2841 | goto failed; |
| 2842 | Py_DECREF(value); |
| 2843 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 2844 | if (!value) goto failed; |
| 2845 | if (_PyObject_SetAttrId(result, &PyId_simple, value) == -1) |
| 2846 | goto failed; |
| 2847 | Py_DECREF(value); |
| 2848 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2849 | case For_kind: |
| 2850 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2851 | if (!result) goto failed; |
| 2852 | value = ast2obj_expr(o->v.For.target); |
| 2853 | if (!value) goto failed; |
| 2854 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2855 | goto failed; |
| 2856 | Py_DECREF(value); |
| 2857 | value = ast2obj_expr(o->v.For.iter); |
| 2858 | if (!value) goto failed; |
| 2859 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2860 | goto failed; |
| 2861 | Py_DECREF(value); |
| 2862 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2863 | if (!value) goto failed; |
| 2864 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2865 | goto failed; |
| 2866 | Py_DECREF(value); |
| 2867 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2868 | if (!value) goto failed; |
| 2869 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2870 | goto failed; |
| 2871 | Py_DECREF(value); |
| 2872 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2873 | case AsyncFor_kind: |
| 2874 | result = PyType_GenericNew(AsyncFor_type, NULL, NULL); |
| 2875 | if (!result) goto failed; |
| 2876 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 2877 | if (!value) goto failed; |
| 2878 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2879 | goto failed; |
| 2880 | Py_DECREF(value); |
| 2881 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 2882 | if (!value) goto failed; |
| 2883 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2884 | goto failed; |
| 2885 | Py_DECREF(value); |
| 2886 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 2887 | if (!value) goto failed; |
| 2888 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2889 | goto failed; |
| 2890 | Py_DECREF(value); |
| 2891 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 2892 | if (!value) goto failed; |
| 2893 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2894 | goto failed; |
| 2895 | Py_DECREF(value); |
| 2896 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2897 | case While_kind: |
| 2898 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2899 | if (!result) goto failed; |
| 2900 | value = ast2obj_expr(o->v.While.test); |
| 2901 | if (!value) goto failed; |
| 2902 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2903 | goto failed; |
| 2904 | Py_DECREF(value); |
| 2905 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2906 | if (!value) goto failed; |
| 2907 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2908 | goto failed; |
| 2909 | Py_DECREF(value); |
| 2910 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2911 | if (!value) goto failed; |
| 2912 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2913 | goto failed; |
| 2914 | Py_DECREF(value); |
| 2915 | break; |
| 2916 | case If_kind: |
| 2917 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2918 | if (!result) goto failed; |
| 2919 | value = ast2obj_expr(o->v.If.test); |
| 2920 | if (!value) goto failed; |
| 2921 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2922 | goto failed; |
| 2923 | Py_DECREF(value); |
| 2924 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2925 | if (!value) goto failed; |
| 2926 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2927 | goto failed; |
| 2928 | Py_DECREF(value); |
| 2929 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2930 | if (!value) goto failed; |
| 2931 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2932 | goto failed; |
| 2933 | Py_DECREF(value); |
| 2934 | break; |
| 2935 | case With_kind: |
| 2936 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2937 | if (!result) goto failed; |
| 2938 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 2939 | if (!value) goto failed; |
| 2940 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 2941 | goto failed; |
| 2942 | Py_DECREF(value); |
| 2943 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2944 | if (!value) goto failed; |
| 2945 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2946 | goto failed; |
| 2947 | Py_DECREF(value); |
| 2948 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2949 | case AsyncWith_kind: |
| 2950 | result = PyType_GenericNew(AsyncWith_type, NULL, NULL); |
| 2951 | if (!result) goto failed; |
| 2952 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 2953 | if (!value) goto failed; |
| 2954 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 2955 | goto failed; |
| 2956 | Py_DECREF(value); |
| 2957 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 2958 | if (!value) goto failed; |
| 2959 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2960 | goto failed; |
| 2961 | Py_DECREF(value); |
| 2962 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2963 | case Raise_kind: |
| 2964 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2965 | if (!result) goto failed; |
| 2966 | value = ast2obj_expr(o->v.Raise.exc); |
| 2967 | if (!value) goto failed; |
| 2968 | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
| 2969 | goto failed; |
| 2970 | Py_DECREF(value); |
| 2971 | value = ast2obj_expr(o->v.Raise.cause); |
| 2972 | if (!value) goto failed; |
| 2973 | if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) |
| 2974 | goto failed; |
| 2975 | Py_DECREF(value); |
| 2976 | break; |
| 2977 | case Try_kind: |
| 2978 | result = PyType_GenericNew(Try_type, NULL, NULL); |
| 2979 | if (!result) goto failed; |
| 2980 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 2981 | if (!value) goto failed; |
| 2982 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2983 | goto failed; |
| 2984 | Py_DECREF(value); |
| 2985 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 2986 | if (!value) goto failed; |
| 2987 | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
| 2988 | goto failed; |
| 2989 | Py_DECREF(value); |
| 2990 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 2991 | if (!value) goto failed; |
| 2992 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2993 | goto failed; |
| 2994 | Py_DECREF(value); |
| 2995 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 2996 | if (!value) goto failed; |
| 2997 | if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) |
| 2998 | goto failed; |
| 2999 | Py_DECREF(value); |
| 3000 | break; |
| 3001 | case Assert_kind: |
| 3002 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 3003 | if (!result) goto failed; |
| 3004 | value = ast2obj_expr(o->v.Assert.test); |
| 3005 | if (!value) goto failed; |
| 3006 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3007 | goto failed; |
| 3008 | Py_DECREF(value); |
| 3009 | value = ast2obj_expr(o->v.Assert.msg); |
| 3010 | if (!value) goto failed; |
| 3011 | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
| 3012 | goto failed; |
| 3013 | Py_DECREF(value); |
| 3014 | break; |
| 3015 | case Import_kind: |
| 3016 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 3017 | if (!result) goto failed; |
| 3018 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 3019 | if (!value) goto failed; |
| 3020 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3021 | goto failed; |
| 3022 | Py_DECREF(value); |
| 3023 | break; |
| 3024 | case ImportFrom_kind: |
| 3025 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 3026 | if (!result) goto failed; |
| 3027 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 3028 | if (!value) goto failed; |
| 3029 | if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) |
| 3030 | goto failed; |
| 3031 | Py_DECREF(value); |
| 3032 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 3033 | if (!value) goto failed; |
| 3034 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3035 | goto failed; |
| 3036 | Py_DECREF(value); |
| 3037 | value = ast2obj_int(o->v.ImportFrom.level); |
| 3038 | if (!value) goto failed; |
| 3039 | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
| 3040 | goto failed; |
| 3041 | Py_DECREF(value); |
| 3042 | break; |
| 3043 | case Global_kind: |
| 3044 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 3045 | if (!result) goto failed; |
| 3046 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 3047 | if (!value) goto failed; |
| 3048 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3049 | goto failed; |
| 3050 | Py_DECREF(value); |
| 3051 | break; |
| 3052 | case Nonlocal_kind: |
| 3053 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 3054 | if (!result) goto failed; |
| 3055 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 3056 | if (!value) goto failed; |
| 3057 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 3058 | goto failed; |
| 3059 | Py_DECREF(value); |
| 3060 | break; |
| 3061 | case Expr_kind: |
| 3062 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 3063 | if (!result) goto failed; |
| 3064 | value = ast2obj_expr(o->v.Expr.value); |
| 3065 | if (!value) goto failed; |
| 3066 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3067 | goto failed; |
| 3068 | Py_DECREF(value); |
| 3069 | break; |
| 3070 | case Pass_kind: |
| 3071 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 3072 | if (!result) goto failed; |
| 3073 | break; |
| 3074 | case Break_kind: |
| 3075 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 3076 | if (!result) goto failed; |
| 3077 | break; |
| 3078 | case Continue_kind: |
| 3079 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 3080 | if (!result) goto failed; |
| 3081 | break; |
| 3082 | } |
| 3083 | value = ast2obj_int(o->lineno); |
| 3084 | if (!value) goto failed; |
| 3085 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3086 | goto failed; |
| 3087 | Py_DECREF(value); |
| 3088 | value = ast2obj_int(o->col_offset); |
| 3089 | if (!value) goto failed; |
| 3090 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3091 | goto failed; |
| 3092 | Py_DECREF(value); |
| 3093 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3094 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3095 | Py_XDECREF(value); |
| 3096 | Py_XDECREF(result); |
| 3097 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3098 | } |
| 3099 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3100 | PyObject* |
| 3101 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3102 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3103 | expr_ty o = (expr_ty)_o; |
| 3104 | PyObject *result = NULL, *value = NULL; |
| 3105 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3106 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3107 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3108 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3109 | switch (o->kind) { |
| 3110 | case BoolOp_kind: |
| 3111 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 3112 | if (!result) goto failed; |
| 3113 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 3114 | if (!value) goto failed; |
| 3115 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3116 | goto failed; |
| 3117 | Py_DECREF(value); |
| 3118 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 3119 | if (!value) goto failed; |
| 3120 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3121 | goto failed; |
| 3122 | Py_DECREF(value); |
| 3123 | break; |
| 3124 | case BinOp_kind: |
| 3125 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 3126 | if (!result) goto failed; |
| 3127 | value = ast2obj_expr(o->v.BinOp.left); |
| 3128 | if (!value) goto failed; |
| 3129 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3130 | goto failed; |
| 3131 | Py_DECREF(value); |
| 3132 | value = ast2obj_operator(o->v.BinOp.op); |
| 3133 | if (!value) goto failed; |
| 3134 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3135 | goto failed; |
| 3136 | Py_DECREF(value); |
| 3137 | value = ast2obj_expr(o->v.BinOp.right); |
| 3138 | if (!value) goto failed; |
| 3139 | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
| 3140 | goto failed; |
| 3141 | Py_DECREF(value); |
| 3142 | break; |
| 3143 | case UnaryOp_kind: |
| 3144 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 3145 | if (!result) goto failed; |
| 3146 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 3147 | if (!value) goto failed; |
| 3148 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3149 | goto failed; |
| 3150 | Py_DECREF(value); |
| 3151 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 3152 | if (!value) goto failed; |
| 3153 | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
| 3154 | goto failed; |
| 3155 | Py_DECREF(value); |
| 3156 | break; |
| 3157 | case Lambda_kind: |
| 3158 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 3159 | if (!result) goto failed; |
| 3160 | value = ast2obj_arguments(o->v.Lambda.args); |
| 3161 | if (!value) goto failed; |
| 3162 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3163 | goto failed; |
| 3164 | Py_DECREF(value); |
| 3165 | value = ast2obj_expr(o->v.Lambda.body); |
| 3166 | if (!value) goto failed; |
| 3167 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3168 | goto failed; |
| 3169 | Py_DECREF(value); |
| 3170 | break; |
| 3171 | case IfExp_kind: |
| 3172 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 3173 | if (!result) goto failed; |
| 3174 | value = ast2obj_expr(o->v.IfExp.test); |
| 3175 | if (!value) goto failed; |
| 3176 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3177 | goto failed; |
| 3178 | Py_DECREF(value); |
| 3179 | value = ast2obj_expr(o->v.IfExp.body); |
| 3180 | if (!value) goto failed; |
| 3181 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3182 | goto failed; |
| 3183 | Py_DECREF(value); |
| 3184 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 3185 | if (!value) goto failed; |
| 3186 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3187 | goto failed; |
| 3188 | Py_DECREF(value); |
| 3189 | break; |
| 3190 | case Dict_kind: |
| 3191 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 3192 | if (!result) goto failed; |
| 3193 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 3194 | if (!value) goto failed; |
| 3195 | if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) |
| 3196 | goto failed; |
| 3197 | Py_DECREF(value); |
| 3198 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 3199 | if (!value) goto failed; |
| 3200 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3201 | goto failed; |
| 3202 | Py_DECREF(value); |
| 3203 | break; |
| 3204 | case Set_kind: |
| 3205 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 3206 | if (!result) goto failed; |
| 3207 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 3208 | if (!value) goto failed; |
| 3209 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3210 | goto failed; |
| 3211 | Py_DECREF(value); |
| 3212 | break; |
| 3213 | case ListComp_kind: |
| 3214 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 3215 | if (!result) goto failed; |
| 3216 | value = ast2obj_expr(o->v.ListComp.elt); |
| 3217 | if (!value) goto failed; |
| 3218 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3219 | goto failed; |
| 3220 | Py_DECREF(value); |
| 3221 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 3222 | if (!value) goto failed; |
| 3223 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3224 | goto failed; |
| 3225 | Py_DECREF(value); |
| 3226 | break; |
| 3227 | case SetComp_kind: |
| 3228 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 3229 | if (!result) goto failed; |
| 3230 | value = ast2obj_expr(o->v.SetComp.elt); |
| 3231 | if (!value) goto failed; |
| 3232 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3233 | goto failed; |
| 3234 | Py_DECREF(value); |
| 3235 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 3236 | if (!value) goto failed; |
| 3237 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3238 | goto failed; |
| 3239 | Py_DECREF(value); |
| 3240 | break; |
| 3241 | case DictComp_kind: |
| 3242 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 3243 | if (!result) goto failed; |
| 3244 | value = ast2obj_expr(o->v.DictComp.key); |
| 3245 | if (!value) goto failed; |
| 3246 | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
| 3247 | goto failed; |
| 3248 | Py_DECREF(value); |
| 3249 | value = ast2obj_expr(o->v.DictComp.value); |
| 3250 | if (!value) goto failed; |
| 3251 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3252 | goto failed; |
| 3253 | Py_DECREF(value); |
| 3254 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 3255 | if (!value) goto failed; |
| 3256 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3257 | goto failed; |
| 3258 | Py_DECREF(value); |
| 3259 | break; |
| 3260 | case GeneratorExp_kind: |
| 3261 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 3262 | if (!result) goto failed; |
| 3263 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 3264 | if (!value) goto failed; |
| 3265 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3266 | goto failed; |
| 3267 | Py_DECREF(value); |
| 3268 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 3269 | ast2obj_comprehension); |
| 3270 | if (!value) goto failed; |
| 3271 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3272 | goto failed; |
| 3273 | Py_DECREF(value); |
| 3274 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3275 | case Await_kind: |
| 3276 | result = PyType_GenericNew(Await_type, NULL, NULL); |
| 3277 | if (!result) goto failed; |
| 3278 | value = ast2obj_expr(o->v.Await.value); |
| 3279 | if (!value) goto failed; |
| 3280 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3281 | goto failed; |
| 3282 | Py_DECREF(value); |
| 3283 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3284 | case Yield_kind: |
| 3285 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 3286 | if (!result) goto failed; |
| 3287 | value = ast2obj_expr(o->v.Yield.value); |
| 3288 | if (!value) goto failed; |
| 3289 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3290 | goto failed; |
| 3291 | Py_DECREF(value); |
| 3292 | break; |
| 3293 | case YieldFrom_kind: |
| 3294 | result = PyType_GenericNew(YieldFrom_type, NULL, NULL); |
| 3295 | if (!result) goto failed; |
| 3296 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 3297 | if (!value) goto failed; |
| 3298 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3299 | goto failed; |
| 3300 | Py_DECREF(value); |
| 3301 | break; |
| 3302 | case Compare_kind: |
| 3303 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 3304 | if (!result) goto failed; |
| 3305 | value = ast2obj_expr(o->v.Compare.left); |
| 3306 | if (!value) goto failed; |
| 3307 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3308 | goto failed; |
| 3309 | Py_DECREF(value); |
| 3310 | { |
| 3311 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 3312 | value = PyList_New(n); |
| 3313 | if (!value) goto failed; |
| 3314 | for(i = 0; i < n; i++) |
| 3315 | 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] | 3316 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3317 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3318 | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
| 3319 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3320 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3321 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3322 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3323 | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
| 3324 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3325 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3326 | break; |
| 3327 | case Call_kind: |
| 3328 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 3329 | if (!result) goto failed; |
| 3330 | value = ast2obj_expr(o->v.Call.func); |
| 3331 | if (!value) goto failed; |
| 3332 | if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) |
| 3333 | goto failed; |
| 3334 | Py_DECREF(value); |
| 3335 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 3336 | if (!value) goto failed; |
| 3337 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3338 | goto failed; |
| 3339 | Py_DECREF(value); |
| 3340 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 3341 | if (!value) goto failed; |
| 3342 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 3343 | goto failed; |
| 3344 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3345 | break; |
| 3346 | case Num_kind: |
| 3347 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 3348 | if (!result) goto failed; |
| 3349 | value = ast2obj_object(o->v.Num.n); |
| 3350 | if (!value) goto failed; |
| 3351 | if (_PyObject_SetAttrId(result, &PyId_n, value) == -1) |
| 3352 | goto failed; |
| 3353 | Py_DECREF(value); |
| 3354 | break; |
| 3355 | case Str_kind: |
| 3356 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 3357 | if (!result) goto failed; |
| 3358 | value = ast2obj_string(o->v.Str.s); |
| 3359 | if (!value) goto failed; |
| 3360 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
| 3361 | goto failed; |
| 3362 | Py_DECREF(value); |
| 3363 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3364 | case FormattedValue_kind: |
| 3365 | result = PyType_GenericNew(FormattedValue_type, NULL, NULL); |
| 3366 | if (!result) goto failed; |
| 3367 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 3368 | if (!value) goto failed; |
| 3369 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3370 | goto failed; |
| 3371 | Py_DECREF(value); |
| 3372 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 3373 | if (!value) goto failed; |
| 3374 | if (_PyObject_SetAttrId(result, &PyId_conversion, value) == -1) |
| 3375 | goto failed; |
| 3376 | Py_DECREF(value); |
| 3377 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 3378 | if (!value) goto failed; |
| 3379 | if (_PyObject_SetAttrId(result, &PyId_format_spec, value) == -1) |
| 3380 | goto failed; |
| 3381 | Py_DECREF(value); |
| 3382 | break; |
| 3383 | case JoinedStr_kind: |
| 3384 | result = PyType_GenericNew(JoinedStr_type, NULL, NULL); |
| 3385 | if (!result) goto failed; |
| 3386 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 3387 | if (!value) goto failed; |
| 3388 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3389 | goto failed; |
| 3390 | Py_DECREF(value); |
| 3391 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3392 | case Bytes_kind: |
| 3393 | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
| 3394 | if (!result) goto failed; |
| 3395 | value = ast2obj_bytes(o->v.Bytes.s); |
| 3396 | if (!value) goto failed; |
| 3397 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
| 3398 | goto failed; |
| 3399 | Py_DECREF(value); |
| 3400 | break; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3401 | case NameConstant_kind: |
| 3402 | result = PyType_GenericNew(NameConstant_type, NULL, NULL); |
| 3403 | if (!result) goto failed; |
| 3404 | value = ast2obj_singleton(o->v.NameConstant.value); |
| 3405 | if (!value) goto failed; |
| 3406 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3407 | goto failed; |
| 3408 | Py_DECREF(value); |
| 3409 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3410 | case Ellipsis_kind: |
| 3411 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 3412 | if (!result) goto failed; |
| 3413 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3414 | case Constant_kind: |
| 3415 | result = PyType_GenericNew(Constant_type, NULL, NULL); |
| 3416 | if (!result) goto failed; |
| 3417 | value = ast2obj_constant(o->v.Constant.value); |
| 3418 | if (!value) goto failed; |
| 3419 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3420 | goto failed; |
| 3421 | Py_DECREF(value); |
| 3422 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3423 | case Attribute_kind: |
| 3424 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 3425 | if (!result) goto failed; |
| 3426 | value = ast2obj_expr(o->v.Attribute.value); |
| 3427 | if (!value) goto failed; |
| 3428 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3429 | goto failed; |
| 3430 | Py_DECREF(value); |
| 3431 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 3432 | if (!value) goto failed; |
| 3433 | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
| 3434 | goto failed; |
| 3435 | Py_DECREF(value); |
| 3436 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 3437 | if (!value) goto failed; |
| 3438 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3439 | goto failed; |
| 3440 | Py_DECREF(value); |
| 3441 | break; |
| 3442 | case Subscript_kind: |
| 3443 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 3444 | if (!result) goto failed; |
| 3445 | value = ast2obj_expr(o->v.Subscript.value); |
| 3446 | if (!value) goto failed; |
| 3447 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3448 | goto failed; |
| 3449 | Py_DECREF(value); |
| 3450 | value = ast2obj_slice(o->v.Subscript.slice); |
| 3451 | if (!value) goto failed; |
| 3452 | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
| 3453 | goto failed; |
| 3454 | Py_DECREF(value); |
| 3455 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 3456 | if (!value) goto failed; |
| 3457 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3458 | goto failed; |
| 3459 | Py_DECREF(value); |
| 3460 | break; |
| 3461 | case Starred_kind: |
| 3462 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 3463 | if (!result) goto failed; |
| 3464 | value = ast2obj_expr(o->v.Starred.value); |
| 3465 | if (!value) goto failed; |
| 3466 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3467 | goto failed; |
| 3468 | Py_DECREF(value); |
| 3469 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 3470 | if (!value) goto failed; |
| 3471 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3472 | goto failed; |
| 3473 | Py_DECREF(value); |
| 3474 | break; |
| 3475 | case Name_kind: |
| 3476 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 3477 | if (!result) goto failed; |
| 3478 | value = ast2obj_identifier(o->v.Name.id); |
| 3479 | if (!value) goto failed; |
| 3480 | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
| 3481 | goto failed; |
| 3482 | Py_DECREF(value); |
| 3483 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 3484 | if (!value) goto failed; |
| 3485 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3486 | goto failed; |
| 3487 | Py_DECREF(value); |
| 3488 | break; |
| 3489 | case List_kind: |
| 3490 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 3491 | if (!result) goto failed; |
| 3492 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 3493 | if (!value) goto failed; |
| 3494 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3495 | goto failed; |
| 3496 | Py_DECREF(value); |
| 3497 | value = ast2obj_expr_context(o->v.List.ctx); |
| 3498 | if (!value) goto failed; |
| 3499 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3500 | goto failed; |
| 3501 | Py_DECREF(value); |
| 3502 | break; |
| 3503 | case Tuple_kind: |
| 3504 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 3505 | if (!result) goto failed; |
| 3506 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 3507 | if (!value) goto failed; |
| 3508 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3509 | goto failed; |
| 3510 | Py_DECREF(value); |
| 3511 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 3512 | if (!value) goto failed; |
| 3513 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3514 | goto failed; |
| 3515 | Py_DECREF(value); |
| 3516 | break; |
| 3517 | } |
| 3518 | value = ast2obj_int(o->lineno); |
| 3519 | if (!value) goto failed; |
| 3520 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3521 | goto failed; |
| 3522 | Py_DECREF(value); |
| 3523 | value = ast2obj_int(o->col_offset); |
| 3524 | if (!value) goto failed; |
| 3525 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3526 | goto failed; |
| 3527 | Py_DECREF(value); |
| 3528 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3529 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3530 | Py_XDECREF(value); |
| 3531 | Py_XDECREF(result); |
| 3532 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3533 | } |
| 3534 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3535 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3536 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3537 | switch(o) { |
| 3538 | case Load: |
| 3539 | Py_INCREF(Load_singleton); |
| 3540 | return Load_singleton; |
| 3541 | case Store: |
| 3542 | Py_INCREF(Store_singleton); |
| 3543 | return Store_singleton; |
| 3544 | case Del: |
| 3545 | Py_INCREF(Del_singleton); |
| 3546 | return Del_singleton; |
| 3547 | case AugLoad: |
| 3548 | Py_INCREF(AugLoad_singleton); |
| 3549 | return AugLoad_singleton; |
| 3550 | case AugStore: |
| 3551 | Py_INCREF(AugStore_singleton); |
| 3552 | return AugStore_singleton; |
| 3553 | case Param: |
| 3554 | Py_INCREF(Param_singleton); |
| 3555 | return Param_singleton; |
| 3556 | default: |
| 3557 | /* should never happen, but just in case ... */ |
| 3558 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 3559 | return NULL; |
| 3560 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3561 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3562 | PyObject* |
| 3563 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3564 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3565 | slice_ty o = (slice_ty)_o; |
| 3566 | PyObject *result = NULL, *value = NULL; |
| 3567 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3568 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3569 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3570 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3571 | switch (o->kind) { |
| 3572 | case Slice_kind: |
| 3573 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 3574 | if (!result) goto failed; |
| 3575 | value = ast2obj_expr(o->v.Slice.lower); |
| 3576 | if (!value) goto failed; |
| 3577 | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
| 3578 | goto failed; |
| 3579 | Py_DECREF(value); |
| 3580 | value = ast2obj_expr(o->v.Slice.upper); |
| 3581 | if (!value) goto failed; |
| 3582 | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
| 3583 | goto failed; |
| 3584 | Py_DECREF(value); |
| 3585 | value = ast2obj_expr(o->v.Slice.step); |
| 3586 | if (!value) goto failed; |
| 3587 | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
| 3588 | goto failed; |
| 3589 | Py_DECREF(value); |
| 3590 | break; |
| 3591 | case ExtSlice_kind: |
| 3592 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3593 | if (!result) goto failed; |
| 3594 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3595 | if (!value) goto failed; |
| 3596 | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
| 3597 | goto failed; |
| 3598 | Py_DECREF(value); |
| 3599 | break; |
| 3600 | case Index_kind: |
| 3601 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3602 | if (!result) goto failed; |
| 3603 | value = ast2obj_expr(o->v.Index.value); |
| 3604 | if (!value) goto failed; |
| 3605 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3606 | goto failed; |
| 3607 | Py_DECREF(value); |
| 3608 | break; |
| 3609 | } |
| 3610 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3611 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3612 | Py_XDECREF(value); |
| 3613 | Py_XDECREF(result); |
| 3614 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3615 | } |
| 3616 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3617 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3618 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3619 | switch(o) { |
| 3620 | case And: |
| 3621 | Py_INCREF(And_singleton); |
| 3622 | return And_singleton; |
| 3623 | case Or: |
| 3624 | Py_INCREF(Or_singleton); |
| 3625 | return Or_singleton; |
| 3626 | default: |
| 3627 | /* should never happen, but just in case ... */ |
| 3628 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3629 | return NULL; |
| 3630 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3631 | } |
| 3632 | PyObject* ast2obj_operator(operator_ty o) |
| 3633 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3634 | switch(o) { |
| 3635 | case Add: |
| 3636 | Py_INCREF(Add_singleton); |
| 3637 | return Add_singleton; |
| 3638 | case Sub: |
| 3639 | Py_INCREF(Sub_singleton); |
| 3640 | return Sub_singleton; |
| 3641 | case Mult: |
| 3642 | Py_INCREF(Mult_singleton); |
| 3643 | return Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 3644 | case MatMult: |
| 3645 | Py_INCREF(MatMult_singleton); |
| 3646 | return MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3647 | case Div: |
| 3648 | Py_INCREF(Div_singleton); |
| 3649 | return Div_singleton; |
| 3650 | case Mod: |
| 3651 | Py_INCREF(Mod_singleton); |
| 3652 | return Mod_singleton; |
| 3653 | case Pow: |
| 3654 | Py_INCREF(Pow_singleton); |
| 3655 | return Pow_singleton; |
| 3656 | case LShift: |
| 3657 | Py_INCREF(LShift_singleton); |
| 3658 | return LShift_singleton; |
| 3659 | case RShift: |
| 3660 | Py_INCREF(RShift_singleton); |
| 3661 | return RShift_singleton; |
| 3662 | case BitOr: |
| 3663 | Py_INCREF(BitOr_singleton); |
| 3664 | return BitOr_singleton; |
| 3665 | case BitXor: |
| 3666 | Py_INCREF(BitXor_singleton); |
| 3667 | return BitXor_singleton; |
| 3668 | case BitAnd: |
| 3669 | Py_INCREF(BitAnd_singleton); |
| 3670 | return BitAnd_singleton; |
| 3671 | case FloorDiv: |
| 3672 | Py_INCREF(FloorDiv_singleton); |
| 3673 | return FloorDiv_singleton; |
| 3674 | default: |
| 3675 | /* should never happen, but just in case ... */ |
| 3676 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3677 | return NULL; |
| 3678 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3679 | } |
| 3680 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3681 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3682 | switch(o) { |
| 3683 | case Invert: |
| 3684 | Py_INCREF(Invert_singleton); |
| 3685 | return Invert_singleton; |
| 3686 | case Not: |
| 3687 | Py_INCREF(Not_singleton); |
| 3688 | return Not_singleton; |
| 3689 | case UAdd: |
| 3690 | Py_INCREF(UAdd_singleton); |
| 3691 | return UAdd_singleton; |
| 3692 | case USub: |
| 3693 | Py_INCREF(USub_singleton); |
| 3694 | return USub_singleton; |
| 3695 | default: |
| 3696 | /* should never happen, but just in case ... */ |
| 3697 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3698 | return NULL; |
| 3699 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3700 | } |
| 3701 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3702 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3703 | switch(o) { |
| 3704 | case Eq: |
| 3705 | Py_INCREF(Eq_singleton); |
| 3706 | return Eq_singleton; |
| 3707 | case NotEq: |
| 3708 | Py_INCREF(NotEq_singleton); |
| 3709 | return NotEq_singleton; |
| 3710 | case Lt: |
| 3711 | Py_INCREF(Lt_singleton); |
| 3712 | return Lt_singleton; |
| 3713 | case LtE: |
| 3714 | Py_INCREF(LtE_singleton); |
| 3715 | return LtE_singleton; |
| 3716 | case Gt: |
| 3717 | Py_INCREF(Gt_singleton); |
| 3718 | return Gt_singleton; |
| 3719 | case GtE: |
| 3720 | Py_INCREF(GtE_singleton); |
| 3721 | return GtE_singleton; |
| 3722 | case Is: |
| 3723 | Py_INCREF(Is_singleton); |
| 3724 | return Is_singleton; |
| 3725 | case IsNot: |
| 3726 | Py_INCREF(IsNot_singleton); |
| 3727 | return IsNot_singleton; |
| 3728 | case In: |
| 3729 | Py_INCREF(In_singleton); |
| 3730 | return In_singleton; |
| 3731 | case NotIn: |
| 3732 | Py_INCREF(NotIn_singleton); |
| 3733 | return NotIn_singleton; |
| 3734 | default: |
| 3735 | /* should never happen, but just in case ... */ |
| 3736 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3737 | return NULL; |
| 3738 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3739 | } |
| 3740 | PyObject* |
| 3741 | ast2obj_comprehension(void* _o) |
| 3742 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3743 | comprehension_ty o = (comprehension_ty)_o; |
| 3744 | PyObject *result = NULL, *value = NULL; |
| 3745 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3746 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3747 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3748 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3749 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3750 | if (!result) return NULL; |
| 3751 | value = ast2obj_expr(o->target); |
| 3752 | if (!value) goto failed; |
| 3753 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 3754 | goto failed; |
| 3755 | Py_DECREF(value); |
| 3756 | value = ast2obj_expr(o->iter); |
| 3757 | if (!value) goto failed; |
| 3758 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 3759 | goto failed; |
| 3760 | Py_DECREF(value); |
| 3761 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3762 | if (!value) goto failed; |
| 3763 | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
| 3764 | goto failed; |
| 3765 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3766 | value = ast2obj_int(o->is_async); |
| 3767 | if (!value) goto failed; |
| 3768 | if (_PyObject_SetAttrId(result, &PyId_is_async, value) == -1) |
| 3769 | goto failed; |
| 3770 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3771 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3772 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3773 | Py_XDECREF(value); |
| 3774 | Py_XDECREF(result); |
| 3775 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3776 | } |
| 3777 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3778 | PyObject* |
| 3779 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3780 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3781 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3782 | PyObject *result = NULL, *value = NULL; |
| 3783 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3784 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3785 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3786 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3787 | switch (o->kind) { |
| 3788 | case ExceptHandler_kind: |
| 3789 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3790 | if (!result) goto failed; |
| 3791 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3792 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3793 | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
| 3794 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3795 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3796 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3797 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3798 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3799 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3800 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3801 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3802 | if (!value) goto failed; |
| 3803 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3804 | goto failed; |
| 3805 | Py_DECREF(value); |
| 3806 | break; |
| 3807 | } |
| 3808 | value = ast2obj_int(o->lineno); |
| 3809 | if (!value) goto failed; |
| 3810 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3811 | goto failed; |
| 3812 | Py_DECREF(value); |
| 3813 | value = ast2obj_int(o->col_offset); |
| 3814 | if (!value) goto failed; |
| 3815 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3816 | goto failed; |
| 3817 | Py_DECREF(value); |
| 3818 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3819 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3820 | Py_XDECREF(value); |
| 3821 | Py_XDECREF(result); |
| 3822 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3823 | } |
| 3824 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3825 | PyObject* |
| 3826 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3827 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3828 | arguments_ty o = (arguments_ty)_o; |
| 3829 | PyObject *result = NULL, *value = NULL; |
| 3830 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3831 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3832 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3833 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3834 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3835 | if (!result) return NULL; |
| 3836 | value = ast2obj_list(o->args, ast2obj_arg); |
| 3837 | if (!value) goto failed; |
| 3838 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3839 | goto failed; |
| 3840 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3841 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3842 | if (!value) goto failed; |
| 3843 | if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) |
| 3844 | goto failed; |
| 3845 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3846 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 3847 | if (!value) goto failed; |
| 3848 | if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) |
| 3849 | goto failed; |
| 3850 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3851 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3852 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3853 | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3854 | goto failed; |
| 3855 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3856 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3857 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3858 | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3859 | goto failed; |
| 3860 | Py_DECREF(value); |
| 3861 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3862 | if (!value) goto failed; |
| 3863 | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
| 3864 | goto failed; |
| 3865 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3866 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3867 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3868 | Py_XDECREF(value); |
| 3869 | Py_XDECREF(result); |
| 3870 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3871 | } |
| 3872 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3873 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3874 | ast2obj_arg(void* _o) |
| 3875 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3876 | arg_ty o = (arg_ty)_o; |
| 3877 | PyObject *result = NULL, *value = NULL; |
| 3878 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3879 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3880 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3881 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3882 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3883 | if (!result) return NULL; |
| 3884 | value = ast2obj_identifier(o->arg); |
| 3885 | if (!value) goto failed; |
| 3886 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 3887 | goto failed; |
| 3888 | Py_DECREF(value); |
| 3889 | value = ast2obj_expr(o->annotation); |
| 3890 | if (!value) goto failed; |
| 3891 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 3892 | goto failed; |
| 3893 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3894 | value = ast2obj_int(o->lineno); |
| 3895 | if (!value) goto failed; |
| 3896 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3897 | goto failed; |
| 3898 | Py_DECREF(value); |
| 3899 | value = ast2obj_int(o->col_offset); |
| 3900 | if (!value) goto failed; |
| 3901 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3902 | goto failed; |
| 3903 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3904 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3905 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3906 | Py_XDECREF(value); |
| 3907 | Py_XDECREF(result); |
| 3908 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3909 | } |
| 3910 | |
| 3911 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3912 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3913 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3914 | keyword_ty o = (keyword_ty)_o; |
| 3915 | PyObject *result = NULL, *value = NULL; |
| 3916 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3917 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3918 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3919 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3920 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3921 | if (!result) return NULL; |
| 3922 | value = ast2obj_identifier(o->arg); |
| 3923 | if (!value) goto failed; |
| 3924 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 3925 | goto failed; |
| 3926 | Py_DECREF(value); |
| 3927 | value = ast2obj_expr(o->value); |
| 3928 | if (!value) goto failed; |
| 3929 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3930 | goto failed; |
| 3931 | Py_DECREF(value); |
| 3932 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3933 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3934 | Py_XDECREF(value); |
| 3935 | Py_XDECREF(result); |
| 3936 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3937 | } |
| 3938 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3939 | PyObject* |
| 3940 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3941 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3942 | alias_ty o = (alias_ty)_o; |
| 3943 | PyObject *result = NULL, *value = NULL; |
| 3944 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3945 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3946 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3947 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3948 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3949 | if (!result) return NULL; |
| 3950 | value = ast2obj_identifier(o->name); |
| 3951 | if (!value) goto failed; |
| 3952 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3953 | goto failed; |
| 3954 | Py_DECREF(value); |
| 3955 | value = ast2obj_identifier(o->asname); |
| 3956 | if (!value) goto failed; |
| 3957 | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
| 3958 | goto failed; |
| 3959 | Py_DECREF(value); |
| 3960 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3961 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3962 | Py_XDECREF(value); |
| 3963 | Py_XDECREF(result); |
| 3964 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3965 | } |
| 3966 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3967 | PyObject* |
| 3968 | ast2obj_withitem(void* _o) |
| 3969 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3970 | withitem_ty o = (withitem_ty)_o; |
| 3971 | PyObject *result = NULL, *value = NULL; |
| 3972 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3973 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3974 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3975 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3976 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 3977 | if (!result) return NULL; |
| 3978 | value = ast2obj_expr(o->context_expr); |
| 3979 | if (!value) goto failed; |
| 3980 | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
| 3981 | goto failed; |
| 3982 | Py_DECREF(value); |
| 3983 | value = ast2obj_expr(o->optional_vars); |
| 3984 | if (!value) goto failed; |
| 3985 | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
| 3986 | goto failed; |
| 3987 | Py_DECREF(value); |
| 3988 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3989 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3990 | Py_XDECREF(value); |
| 3991 | Py_XDECREF(result); |
| 3992 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3993 | } |
| 3994 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3995 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3996 | int |
| 3997 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3998 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3999 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4000 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4001 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4002 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4003 | if (obj == Py_None) { |
| 4004 | *out = NULL; |
| 4005 | return 0; |
| 4006 | } |
| 4007 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 4008 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4009 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4010 | } |
| 4011 | if (isinstance) { |
| 4012 | asdl_seq* body; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4013 | string docstring; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4014 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4015 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4016 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4017 | int res; |
| 4018 | Py_ssize_t len; |
| 4019 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4020 | if (!PyList_Check(tmp)) { |
| 4021 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4022 | goto failed; |
| 4023 | } |
| 4024 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4025 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4026 | if (body == NULL) goto failed; |
| 4027 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4028 | stmt_ty val; |
| 4029 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4030 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4031 | if (len != PyList_GET_SIZE(tmp)) { |
| 4032 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 4033 | goto failed; |
| 4034 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4035 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4036 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4037 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4038 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4039 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4040 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 4041 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4042 | return 1; |
| 4043 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4044 | tmp = get_not_none(obj, &PyId_docstring); |
| 4045 | if (tmp != NULL) { |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4046 | int res; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4047 | res = obj2ast_string(tmp, &docstring, arena); |
| 4048 | if (res != 0) goto failed; |
| 4049 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4050 | } else if (PyErr_Occurred()) { |
| 4051 | return 1; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4052 | } else { |
| 4053 | docstring = NULL; |
| 4054 | } |
| 4055 | *out = Module(body, docstring, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4056 | if (*out == NULL) goto failed; |
| 4057 | return 0; |
| 4058 | } |
| 4059 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 4060 | if (isinstance == -1) { |
| 4061 | return 1; |
| 4062 | } |
| 4063 | if (isinstance) { |
| 4064 | asdl_seq* body; |
| 4065 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4066 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4067 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4068 | int res; |
| 4069 | Py_ssize_t len; |
| 4070 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4071 | if (!PyList_Check(tmp)) { |
| 4072 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4073 | goto failed; |
| 4074 | } |
| 4075 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4076 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4077 | if (body == NULL) goto failed; |
| 4078 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4079 | stmt_ty val; |
| 4080 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4081 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4082 | if (len != PyList_GET_SIZE(tmp)) { |
| 4083 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 4084 | goto failed; |
| 4085 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4086 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4087 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4088 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4089 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4090 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4091 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 4092 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4093 | return 1; |
| 4094 | } |
| 4095 | *out = Interactive(body, arena); |
| 4096 | if (*out == NULL) goto failed; |
| 4097 | return 0; |
| 4098 | } |
| 4099 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 4100 | if (isinstance == -1) { |
| 4101 | return 1; |
| 4102 | } |
| 4103 | if (isinstance) { |
| 4104 | expr_ty body; |
| 4105 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4106 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4107 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4108 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4109 | res = obj2ast_expr(tmp, &body, arena); |
| 4110 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4111 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4112 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4113 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4114 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 4115 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4116 | return 1; |
| 4117 | } |
| 4118 | *out = Expression(body, arena); |
| 4119 | if (*out == NULL) goto failed; |
| 4120 | return 0; |
| 4121 | } |
| 4122 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 4123 | if (isinstance == -1) { |
| 4124 | return 1; |
| 4125 | } |
| 4126 | if (isinstance) { |
| 4127 | asdl_seq* body; |
| 4128 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4129 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4130 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4131 | int res; |
| 4132 | Py_ssize_t len; |
| 4133 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4134 | if (!PyList_Check(tmp)) { |
| 4135 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4136 | goto failed; |
| 4137 | } |
| 4138 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4139 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4140 | if (body == NULL) goto failed; |
| 4141 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4142 | stmt_ty val; |
| 4143 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4144 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4145 | if (len != PyList_GET_SIZE(tmp)) { |
| 4146 | PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration"); |
| 4147 | goto failed; |
| 4148 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4149 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4150 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4151 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4152 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4153 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4154 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 4155 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4156 | return 1; |
| 4157 | } |
| 4158 | *out = Suite(body, arena); |
| 4159 | if (*out == NULL) goto failed; |
| 4160 | return 0; |
| 4161 | } |
| 4162 | |
| 4163 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 4164 | failed: |
| 4165 | Py_XDECREF(tmp); |
| 4166 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | int |
| 4170 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 4171 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4172 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4173 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4174 | PyObject *tmp = NULL; |
| 4175 | int lineno; |
| 4176 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4177 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4178 | if (obj == Py_None) { |
| 4179 | *out = NULL; |
| 4180 | return 0; |
| 4181 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4182 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 4183 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4184 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4185 | res = obj2ast_int(tmp, &lineno, arena); |
| 4186 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4187 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4188 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4189 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4190 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 4191 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4192 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4193 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4194 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 4195 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4196 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4197 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4198 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4199 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4200 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4201 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4202 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 4203 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4204 | return 1; |
| 4205 | } |
| 4206 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 4207 | if (isinstance == -1) { |
| 4208 | return 1; |
| 4209 | } |
| 4210 | if (isinstance) { |
| 4211 | identifier name; |
| 4212 | arguments_ty args; |
| 4213 | asdl_seq* body; |
| 4214 | asdl_seq* decorator_list; |
| 4215 | expr_ty returns; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4216 | string docstring; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4217 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4218 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 4219 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4220 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4221 | res = obj2ast_identifier(tmp, &name, arena); |
| 4222 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4223 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4224 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4225 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4226 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 4227 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4228 | return 1; |
| 4229 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4230 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 4231 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4232 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4233 | res = obj2ast_arguments(tmp, &args, arena); |
| 4234 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4235 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4236 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4237 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4238 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 4239 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4240 | return 1; |
| 4241 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4242 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4243 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4244 | int res; |
| 4245 | Py_ssize_t len; |
| 4246 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4247 | if (!PyList_Check(tmp)) { |
| 4248 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4249 | goto failed; |
| 4250 | } |
| 4251 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4252 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4253 | if (body == NULL) goto failed; |
| 4254 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4255 | stmt_ty val; |
| 4256 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4257 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4258 | if (len != PyList_GET_SIZE(tmp)) { |
| 4259 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 4260 | goto failed; |
| 4261 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4262 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4263 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4264 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4265 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4266 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4267 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 4268 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4269 | return 1; |
| 4270 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4271 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
| 4272 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4273 | int res; |
| 4274 | Py_ssize_t len; |
| 4275 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4276 | if (!PyList_Check(tmp)) { |
| 4277 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4278 | goto failed; |
| 4279 | } |
| 4280 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4281 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4282 | if (decorator_list == NULL) goto failed; |
| 4283 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4284 | expr_ty val; |
| 4285 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4286 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4287 | if (len != PyList_GET_SIZE(tmp)) { |
| 4288 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 4289 | goto failed; |
| 4290 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4291 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4292 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4293 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4294 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4295 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4296 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 4297 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4298 | return 1; |
| 4299 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4300 | tmp = get_not_none(obj, &PyId_returns); |
| 4301 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4302 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4303 | res = obj2ast_expr(tmp, &returns, arena); |
| 4304 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4305 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4306 | } else if (PyErr_Occurred()) { |
| 4307 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4308 | } else { |
| 4309 | returns = NULL; |
| 4310 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4311 | tmp = get_not_none(obj, &PyId_docstring); |
| 4312 | if (tmp != NULL) { |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4313 | int res; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4314 | res = obj2ast_string(tmp, &docstring, arena); |
| 4315 | if (res != 0) goto failed; |
| 4316 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4317 | } else if (PyErr_Occurred()) { |
| 4318 | return 1; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4319 | } else { |
| 4320 | docstring = NULL; |
| 4321 | } |
| 4322 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 4323 | docstring, lineno, col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4324 | if (*out == NULL) goto failed; |
| 4325 | return 0; |
| 4326 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4327 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFunctionDef_type); |
| 4328 | if (isinstance == -1) { |
| 4329 | return 1; |
| 4330 | } |
| 4331 | if (isinstance) { |
| 4332 | identifier name; |
| 4333 | arguments_ty args; |
| 4334 | asdl_seq* body; |
| 4335 | asdl_seq* decorator_list; |
| 4336 | expr_ty returns; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4337 | string docstring; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4338 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4339 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 4340 | if (tmp != NULL) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4341 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4342 | res = obj2ast_identifier(tmp, &name, arena); |
| 4343 | if (res != 0) goto failed; |
| 4344 | Py_CLEAR(tmp); |
| 4345 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4346 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4347 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 4348 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4349 | return 1; |
| 4350 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4351 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 4352 | if (tmp != NULL) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4353 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4354 | res = obj2ast_arguments(tmp, &args, arena); |
| 4355 | if (res != 0) goto failed; |
| 4356 | Py_CLEAR(tmp); |
| 4357 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4358 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4359 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 4360 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4361 | return 1; |
| 4362 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4363 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4364 | if (tmp != NULL) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4365 | int res; |
| 4366 | Py_ssize_t len; |
| 4367 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4368 | if (!PyList_Check(tmp)) { |
| 4369 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4370 | goto failed; |
| 4371 | } |
| 4372 | len = PyList_GET_SIZE(tmp); |
| 4373 | body = _Py_asdl_seq_new(len, arena); |
| 4374 | if (body == NULL) goto failed; |
| 4375 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4376 | stmt_ty val; |
| 4377 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4378 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4379 | if (len != PyList_GET_SIZE(tmp)) { |
| 4380 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 4381 | goto failed; |
| 4382 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4383 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4384 | } |
| 4385 | Py_CLEAR(tmp); |
| 4386 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4387 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4388 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 4389 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4390 | return 1; |
| 4391 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4392 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
| 4393 | if (tmp != NULL) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4394 | int res; |
| 4395 | Py_ssize_t len; |
| 4396 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4397 | if (!PyList_Check(tmp)) { |
| 4398 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4399 | goto failed; |
| 4400 | } |
| 4401 | len = PyList_GET_SIZE(tmp); |
| 4402 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 4403 | if (decorator_list == NULL) goto failed; |
| 4404 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4405 | expr_ty val; |
| 4406 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4407 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4408 | if (len != PyList_GET_SIZE(tmp)) { |
| 4409 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 4410 | goto failed; |
| 4411 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4412 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4413 | } |
| 4414 | Py_CLEAR(tmp); |
| 4415 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4416 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4417 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 4418 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4419 | return 1; |
| 4420 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4421 | tmp = get_not_none(obj, &PyId_returns); |
| 4422 | if (tmp != NULL) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4423 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4424 | res = obj2ast_expr(tmp, &returns, arena); |
| 4425 | if (res != 0) goto failed; |
| 4426 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4427 | } else if (PyErr_Occurred()) { |
| 4428 | return 1; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4429 | } else { |
| 4430 | returns = NULL; |
| 4431 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4432 | tmp = get_not_none(obj, &PyId_docstring); |
| 4433 | if (tmp != NULL) { |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4434 | int res; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4435 | res = obj2ast_string(tmp, &docstring, arena); |
| 4436 | if (res != 0) goto failed; |
| 4437 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4438 | } else if (PyErr_Occurred()) { |
| 4439 | return 1; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4440 | } else { |
| 4441 | docstring = NULL; |
| 4442 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4443 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4444 | docstring, lineno, col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4445 | if (*out == NULL) goto failed; |
| 4446 | return 0; |
| 4447 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4448 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 4449 | if (isinstance == -1) { |
| 4450 | return 1; |
| 4451 | } |
| 4452 | if (isinstance) { |
| 4453 | identifier name; |
| 4454 | asdl_seq* bases; |
| 4455 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4456 | asdl_seq* body; |
| 4457 | asdl_seq* decorator_list; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4458 | string docstring; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4459 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4460 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 4461 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4462 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4463 | res = obj2ast_identifier(tmp, &name, arena); |
| 4464 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4465 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4466 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4467 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4468 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 4469 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4470 | return 1; |
| 4471 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4472 | tmp = _PyObject_GetAttrId(obj, &PyId_bases); |
| 4473 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4474 | int res; |
| 4475 | Py_ssize_t len; |
| 4476 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4477 | if (!PyList_Check(tmp)) { |
| 4478 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4479 | goto failed; |
| 4480 | } |
| 4481 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4482 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4483 | if (bases == NULL) goto failed; |
| 4484 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4485 | expr_ty val; |
| 4486 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4487 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4488 | if (len != PyList_GET_SIZE(tmp)) { |
| 4489 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 4490 | goto failed; |
| 4491 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4492 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4493 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4494 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4495 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4496 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4497 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 4498 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4499 | return 1; |
| 4500 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4501 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
| 4502 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4503 | int res; |
| 4504 | Py_ssize_t len; |
| 4505 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4506 | if (!PyList_Check(tmp)) { |
| 4507 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4508 | goto failed; |
| 4509 | } |
| 4510 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4511 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4512 | if (keywords == NULL) goto failed; |
| 4513 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4514 | keyword_ty val; |
| 4515 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4516 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4517 | if (len != PyList_GET_SIZE(tmp)) { |
| 4518 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 4519 | goto failed; |
| 4520 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4521 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4522 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4523 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4524 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4525 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4526 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 4527 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4528 | return 1; |
| 4529 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4530 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4531 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4532 | int res; |
| 4533 | Py_ssize_t len; |
| 4534 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4535 | if (!PyList_Check(tmp)) { |
| 4536 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4537 | goto failed; |
| 4538 | } |
| 4539 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4540 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4541 | if (body == NULL) goto failed; |
| 4542 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4543 | stmt_ty val; |
| 4544 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4545 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4546 | if (len != PyList_GET_SIZE(tmp)) { |
| 4547 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 4548 | goto failed; |
| 4549 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4550 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4551 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4552 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4553 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4554 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4555 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 4556 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4557 | return 1; |
| 4558 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4559 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
| 4560 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4561 | int res; |
| 4562 | Py_ssize_t len; |
| 4563 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4564 | if (!PyList_Check(tmp)) { |
| 4565 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4566 | goto failed; |
| 4567 | } |
| 4568 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4569 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4570 | if (decorator_list == NULL) goto failed; |
| 4571 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4572 | expr_ty val; |
| 4573 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4574 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4575 | if (len != PyList_GET_SIZE(tmp)) { |
| 4576 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
| 4577 | goto failed; |
| 4578 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4579 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4580 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4581 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4582 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4583 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4584 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 4585 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4586 | return 1; |
| 4587 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4588 | tmp = get_not_none(obj, &PyId_docstring); |
| 4589 | if (tmp != NULL) { |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4590 | int res; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4591 | res = obj2ast_string(tmp, &docstring, arena); |
| 4592 | if (res != 0) goto failed; |
| 4593 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4594 | } else if (PyErr_Occurred()) { |
| 4595 | return 1; |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 4596 | } else { |
| 4597 | docstring = NULL; |
| 4598 | } |
| 4599 | *out = ClassDef(name, bases, keywords, body, decorator_list, docstring, |
| 4600 | lineno, col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4601 | if (*out == NULL) goto failed; |
| 4602 | return 0; |
| 4603 | } |
| 4604 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 4605 | if (isinstance == -1) { |
| 4606 | return 1; |
| 4607 | } |
| 4608 | if (isinstance) { |
| 4609 | expr_ty value; |
| 4610 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4611 | tmp = get_not_none(obj, &PyId_value); |
| 4612 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4613 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4614 | res = obj2ast_expr(tmp, &value, arena); |
| 4615 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4616 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4617 | } else if (PyErr_Occurred()) { |
| 4618 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4619 | } else { |
| 4620 | value = NULL; |
| 4621 | } |
| 4622 | *out = Return(value, lineno, col_offset, arena); |
| 4623 | if (*out == NULL) goto failed; |
| 4624 | return 0; |
| 4625 | } |
| 4626 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 4627 | if (isinstance == -1) { |
| 4628 | return 1; |
| 4629 | } |
| 4630 | if (isinstance) { |
| 4631 | asdl_seq* targets; |
| 4632 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4633 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
| 4634 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4635 | int res; |
| 4636 | Py_ssize_t len; |
| 4637 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4638 | if (!PyList_Check(tmp)) { |
| 4639 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4640 | goto failed; |
| 4641 | } |
| 4642 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4643 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4644 | if (targets == NULL) goto failed; |
| 4645 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4646 | expr_ty val; |
| 4647 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4648 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4649 | if (len != PyList_GET_SIZE(tmp)) { |
| 4650 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 4651 | goto failed; |
| 4652 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4653 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4654 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4655 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4656 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4657 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4658 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 4659 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4660 | return 1; |
| 4661 | } |
| 4662 | *out = Delete(targets, lineno, col_offset, arena); |
| 4663 | if (*out == NULL) goto failed; |
| 4664 | return 0; |
| 4665 | } |
| 4666 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 4667 | if (isinstance == -1) { |
| 4668 | return 1; |
| 4669 | } |
| 4670 | if (isinstance) { |
| 4671 | asdl_seq* targets; |
| 4672 | expr_ty value; |
| 4673 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4674 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
| 4675 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4676 | int res; |
| 4677 | Py_ssize_t len; |
| 4678 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4679 | if (!PyList_Check(tmp)) { |
| 4680 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4681 | goto failed; |
| 4682 | } |
| 4683 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4684 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4685 | if (targets == NULL) goto failed; |
| 4686 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4687 | expr_ty val; |
| 4688 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4689 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4690 | if (len != PyList_GET_SIZE(tmp)) { |
| 4691 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 4692 | goto failed; |
| 4693 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4694 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4695 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4696 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4697 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4698 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4699 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 4700 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4701 | return 1; |
| 4702 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4703 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 4704 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4705 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4706 | res = obj2ast_expr(tmp, &value, arena); |
| 4707 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4708 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4709 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4710 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4711 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 4712 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4713 | return 1; |
| 4714 | } |
| 4715 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 4716 | if (*out == NULL) goto failed; |
| 4717 | return 0; |
| 4718 | } |
| 4719 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 4720 | if (isinstance == -1) { |
| 4721 | return 1; |
| 4722 | } |
| 4723 | if (isinstance) { |
| 4724 | expr_ty target; |
| 4725 | operator_ty op; |
| 4726 | expr_ty value; |
| 4727 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4728 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 4729 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4730 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4731 | res = obj2ast_expr(tmp, &target, arena); |
| 4732 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4733 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4734 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4735 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4736 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 4737 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4738 | return 1; |
| 4739 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4740 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 4741 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4742 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4743 | res = obj2ast_operator(tmp, &op, arena); |
| 4744 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4745 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4746 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4747 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4748 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 4749 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4750 | return 1; |
| 4751 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4752 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 4753 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4754 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4755 | res = obj2ast_expr(tmp, &value, arena); |
| 4756 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4757 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4758 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4759 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4760 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 4761 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4762 | return 1; |
| 4763 | } |
| 4764 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 4765 | if (*out == NULL) goto failed; |
| 4766 | return 0; |
| 4767 | } |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4768 | isinstance = PyObject_IsInstance(obj, (PyObject*)AnnAssign_type); |
| 4769 | if (isinstance == -1) { |
| 4770 | return 1; |
| 4771 | } |
| 4772 | if (isinstance) { |
| 4773 | expr_ty target; |
| 4774 | expr_ty annotation; |
| 4775 | expr_ty value; |
| 4776 | int simple; |
| 4777 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4778 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 4779 | if (tmp != NULL) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4780 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4781 | res = obj2ast_expr(tmp, &target, arena); |
| 4782 | if (res != 0) goto failed; |
| 4783 | Py_CLEAR(tmp); |
| 4784 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4785 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4786 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 4787 | } |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4788 | return 1; |
| 4789 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4790 | tmp = _PyObject_GetAttrId(obj, &PyId_annotation); |
| 4791 | if (tmp != NULL) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4792 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4793 | res = obj2ast_expr(tmp, &annotation, arena); |
| 4794 | if (res != 0) goto failed; |
| 4795 | Py_CLEAR(tmp); |
| 4796 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4797 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4798 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 4799 | } |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4800 | return 1; |
| 4801 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4802 | tmp = get_not_none(obj, &PyId_value); |
| 4803 | if (tmp != NULL) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4804 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4805 | res = obj2ast_expr(tmp, &value, arena); |
| 4806 | if (res != 0) goto failed; |
| 4807 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4808 | } else if (PyErr_Occurred()) { |
| 4809 | return 1; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4810 | } else { |
| 4811 | value = NULL; |
| 4812 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4813 | tmp = _PyObject_GetAttrId(obj, &PyId_simple); |
| 4814 | if (tmp != NULL) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4815 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4816 | res = obj2ast_int(tmp, &simple, arena); |
| 4817 | if (res != 0) goto failed; |
| 4818 | Py_CLEAR(tmp); |
| 4819 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4820 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4821 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 4822 | } |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 4823 | return 1; |
| 4824 | } |
| 4825 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
| 4826 | arena); |
| 4827 | if (*out == NULL) goto failed; |
| 4828 | return 0; |
| 4829 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4830 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 4831 | if (isinstance == -1) { |
| 4832 | return 1; |
| 4833 | } |
| 4834 | if (isinstance) { |
| 4835 | expr_ty target; |
| 4836 | expr_ty iter; |
| 4837 | asdl_seq* body; |
| 4838 | asdl_seq* orelse; |
| 4839 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4840 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 4841 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4842 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4843 | res = obj2ast_expr(tmp, &target, arena); |
| 4844 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4845 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4846 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4847 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4848 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 4849 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4850 | return 1; |
| 4851 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4852 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
| 4853 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4854 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4855 | res = obj2ast_expr(tmp, &iter, arena); |
| 4856 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4857 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4858 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4859 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4860 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 4861 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4862 | return 1; |
| 4863 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4864 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4865 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4866 | int res; |
| 4867 | Py_ssize_t len; |
| 4868 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4869 | if (!PyList_Check(tmp)) { |
| 4870 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4871 | goto failed; |
| 4872 | } |
| 4873 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4874 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4875 | if (body == NULL) goto failed; |
| 4876 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4877 | stmt_ty val; |
| 4878 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4879 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4880 | if (len != PyList_GET_SIZE(tmp)) { |
| 4881 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 4882 | goto failed; |
| 4883 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4884 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4885 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4886 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4887 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4888 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4889 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 4890 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4891 | return 1; |
| 4892 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4893 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4894 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4895 | int res; |
| 4896 | Py_ssize_t len; |
| 4897 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4898 | if (!PyList_Check(tmp)) { |
| 4899 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4900 | goto failed; |
| 4901 | } |
| 4902 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4903 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4904 | if (orelse == NULL) goto failed; |
| 4905 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4906 | stmt_ty val; |
| 4907 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4908 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4909 | if (len != PyList_GET_SIZE(tmp)) { |
| 4910 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 4911 | goto failed; |
| 4912 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4913 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4914 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4915 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4916 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4917 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4918 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 4919 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4920 | return 1; |
| 4921 | } |
| 4922 | *out = For(target, iter, body, orelse, lineno, col_offset, arena); |
| 4923 | if (*out == NULL) goto failed; |
| 4924 | return 0; |
| 4925 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4926 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFor_type); |
| 4927 | if (isinstance == -1) { |
| 4928 | return 1; |
| 4929 | } |
| 4930 | if (isinstance) { |
| 4931 | expr_ty target; |
| 4932 | expr_ty iter; |
| 4933 | asdl_seq* body; |
| 4934 | asdl_seq* orelse; |
| 4935 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4936 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 4937 | if (tmp != NULL) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4938 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4939 | res = obj2ast_expr(tmp, &target, arena); |
| 4940 | if (res != 0) goto failed; |
| 4941 | Py_CLEAR(tmp); |
| 4942 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4943 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4944 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 4945 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4946 | return 1; |
| 4947 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4948 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
| 4949 | if (tmp != NULL) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4950 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4951 | res = obj2ast_expr(tmp, &iter, arena); |
| 4952 | if (res != 0) goto failed; |
| 4953 | Py_CLEAR(tmp); |
| 4954 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4955 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4956 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 4957 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4958 | return 1; |
| 4959 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4960 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4961 | if (tmp != NULL) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4962 | int res; |
| 4963 | Py_ssize_t len; |
| 4964 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4965 | if (!PyList_Check(tmp)) { |
| 4966 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4967 | goto failed; |
| 4968 | } |
| 4969 | len = PyList_GET_SIZE(tmp); |
| 4970 | body = _Py_asdl_seq_new(len, arena); |
| 4971 | if (body == NULL) goto failed; |
| 4972 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4973 | stmt_ty val; |
| 4974 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4975 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4976 | if (len != PyList_GET_SIZE(tmp)) { |
| 4977 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 4978 | goto failed; |
| 4979 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4980 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4981 | } |
| 4982 | Py_CLEAR(tmp); |
| 4983 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4984 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 4985 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 4986 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4987 | return 1; |
| 4988 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 4989 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4990 | if (tmp != NULL) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4991 | int res; |
| 4992 | Py_ssize_t len; |
| 4993 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4994 | if (!PyList_Check(tmp)) { |
| 4995 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4996 | goto failed; |
| 4997 | } |
| 4998 | len = PyList_GET_SIZE(tmp); |
| 4999 | orelse = _Py_asdl_seq_new(len, arena); |
| 5000 | if (orelse == NULL) goto failed; |
| 5001 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5002 | stmt_ty val; |
| 5003 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5004 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5005 | if (len != PyList_GET_SIZE(tmp)) { |
| 5006 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 5007 | goto failed; |
| 5008 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5009 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5010 | } |
| 5011 | Py_CLEAR(tmp); |
| 5012 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5013 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5014 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 5015 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5016 | return 1; |
| 5017 | } |
| 5018 | *out = AsyncFor(target, iter, body, orelse, lineno, col_offset, arena); |
| 5019 | if (*out == NULL) goto failed; |
| 5020 | return 0; |
| 5021 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5022 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 5023 | if (isinstance == -1) { |
| 5024 | return 1; |
| 5025 | } |
| 5026 | if (isinstance) { |
| 5027 | expr_ty test; |
| 5028 | asdl_seq* body; |
| 5029 | asdl_seq* orelse; |
| 5030 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5031 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 5032 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5033 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5034 | res = obj2ast_expr(tmp, &test, arena); |
| 5035 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5036 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5037 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5038 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5039 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 5040 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5041 | return 1; |
| 5042 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5043 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 5044 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5045 | int res; |
| 5046 | Py_ssize_t len; |
| 5047 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5048 | if (!PyList_Check(tmp)) { |
| 5049 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5050 | goto failed; |
| 5051 | } |
| 5052 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5053 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5054 | if (body == NULL) goto failed; |
| 5055 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5056 | stmt_ty val; |
| 5057 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5058 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5059 | if (len != PyList_GET_SIZE(tmp)) { |
| 5060 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 5061 | goto failed; |
| 5062 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5063 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5064 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5065 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5066 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5067 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5068 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 5069 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5070 | return 1; |
| 5071 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5072 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 5073 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5074 | int res; |
| 5075 | Py_ssize_t len; |
| 5076 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5077 | if (!PyList_Check(tmp)) { |
| 5078 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5079 | goto failed; |
| 5080 | } |
| 5081 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5082 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5083 | if (orelse == NULL) goto failed; |
| 5084 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5085 | stmt_ty val; |
| 5086 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5087 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5088 | if (len != PyList_GET_SIZE(tmp)) { |
| 5089 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 5090 | goto failed; |
| 5091 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5092 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5093 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5094 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5095 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5096 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5097 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 5098 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5099 | return 1; |
| 5100 | } |
| 5101 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 5102 | if (*out == NULL) goto failed; |
| 5103 | return 0; |
| 5104 | } |
| 5105 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 5106 | if (isinstance == -1) { |
| 5107 | return 1; |
| 5108 | } |
| 5109 | if (isinstance) { |
| 5110 | expr_ty test; |
| 5111 | asdl_seq* body; |
| 5112 | asdl_seq* orelse; |
| 5113 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5114 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 5115 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5116 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5117 | res = obj2ast_expr(tmp, &test, arena); |
| 5118 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5119 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5120 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5121 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5122 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 5123 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5124 | return 1; |
| 5125 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5126 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 5127 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5128 | int res; |
| 5129 | Py_ssize_t len; |
| 5130 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5131 | if (!PyList_Check(tmp)) { |
| 5132 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5133 | goto failed; |
| 5134 | } |
| 5135 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5136 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5137 | if (body == NULL) goto failed; |
| 5138 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5139 | stmt_ty val; |
| 5140 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5141 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5142 | if (len != PyList_GET_SIZE(tmp)) { |
| 5143 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 5144 | goto failed; |
| 5145 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5146 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5147 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5148 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5149 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5150 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5151 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 5152 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5153 | return 1; |
| 5154 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5155 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 5156 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5157 | int res; |
| 5158 | Py_ssize_t len; |
| 5159 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5160 | if (!PyList_Check(tmp)) { |
| 5161 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5162 | goto failed; |
| 5163 | } |
| 5164 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5165 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5166 | if (orelse == NULL) goto failed; |
| 5167 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5168 | stmt_ty val; |
| 5169 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5170 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5171 | if (len != PyList_GET_SIZE(tmp)) { |
| 5172 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 5173 | goto failed; |
| 5174 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5175 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5176 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5177 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5178 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5179 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5180 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 5181 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5182 | return 1; |
| 5183 | } |
| 5184 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 5185 | if (*out == NULL) goto failed; |
| 5186 | return 0; |
| 5187 | } |
| 5188 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 5189 | if (isinstance == -1) { |
| 5190 | return 1; |
| 5191 | } |
| 5192 | if (isinstance) { |
| 5193 | asdl_seq* items; |
| 5194 | asdl_seq* body; |
| 5195 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5196 | tmp = _PyObject_GetAttrId(obj, &PyId_items); |
| 5197 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5198 | int res; |
| 5199 | Py_ssize_t len; |
| 5200 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5201 | if (!PyList_Check(tmp)) { |
| 5202 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5203 | goto failed; |
| 5204 | } |
| 5205 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5206 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5207 | if (items == NULL) goto failed; |
| 5208 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5209 | withitem_ty val; |
| 5210 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5211 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5212 | if (len != PyList_GET_SIZE(tmp)) { |
| 5213 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 5214 | goto failed; |
| 5215 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5216 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5217 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5218 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5219 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5220 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5221 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 5222 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5223 | return 1; |
| 5224 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5225 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 5226 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5227 | int res; |
| 5228 | Py_ssize_t len; |
| 5229 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5230 | if (!PyList_Check(tmp)) { |
| 5231 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5232 | goto failed; |
| 5233 | } |
| 5234 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5235 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5236 | if (body == NULL) goto failed; |
| 5237 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5238 | stmt_ty val; |
| 5239 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5240 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5241 | if (len != PyList_GET_SIZE(tmp)) { |
| 5242 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 5243 | goto failed; |
| 5244 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5245 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5246 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5247 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5248 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5249 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5250 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 5251 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5252 | return 1; |
| 5253 | } |
| 5254 | *out = With(items, body, lineno, col_offset, arena); |
| 5255 | if (*out == NULL) goto failed; |
| 5256 | return 0; |
| 5257 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5258 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncWith_type); |
| 5259 | if (isinstance == -1) { |
| 5260 | return 1; |
| 5261 | } |
| 5262 | if (isinstance) { |
| 5263 | asdl_seq* items; |
| 5264 | asdl_seq* body; |
| 5265 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5266 | tmp = _PyObject_GetAttrId(obj, &PyId_items); |
| 5267 | if (tmp != NULL) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5268 | int res; |
| 5269 | Py_ssize_t len; |
| 5270 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5271 | if (!PyList_Check(tmp)) { |
| 5272 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5273 | goto failed; |
| 5274 | } |
| 5275 | len = PyList_GET_SIZE(tmp); |
| 5276 | items = _Py_asdl_seq_new(len, arena); |
| 5277 | if (items == NULL) goto failed; |
| 5278 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5279 | withitem_ty val; |
| 5280 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5281 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5282 | if (len != PyList_GET_SIZE(tmp)) { |
| 5283 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 5284 | goto failed; |
| 5285 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5286 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5287 | } |
| 5288 | Py_CLEAR(tmp); |
| 5289 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5290 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5291 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 5292 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5293 | return 1; |
| 5294 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5295 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 5296 | if (tmp != NULL) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5297 | int res; |
| 5298 | Py_ssize_t len; |
| 5299 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5300 | if (!PyList_Check(tmp)) { |
| 5301 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5302 | goto failed; |
| 5303 | } |
| 5304 | len = PyList_GET_SIZE(tmp); |
| 5305 | body = _Py_asdl_seq_new(len, arena); |
| 5306 | if (body == NULL) goto failed; |
| 5307 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5308 | stmt_ty val; |
| 5309 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5310 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5311 | if (len != PyList_GET_SIZE(tmp)) { |
| 5312 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 5313 | goto failed; |
| 5314 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5315 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5316 | } |
| 5317 | Py_CLEAR(tmp); |
| 5318 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5319 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5320 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 5321 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5322 | return 1; |
| 5323 | } |
| 5324 | *out = AsyncWith(items, body, lineno, col_offset, arena); |
| 5325 | if (*out == NULL) goto failed; |
| 5326 | return 0; |
| 5327 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5328 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 5329 | if (isinstance == -1) { |
| 5330 | return 1; |
| 5331 | } |
| 5332 | if (isinstance) { |
| 5333 | expr_ty exc; |
| 5334 | expr_ty cause; |
| 5335 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5336 | tmp = get_not_none(obj, &PyId_exc); |
| 5337 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5338 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5339 | res = obj2ast_expr(tmp, &exc, arena); |
| 5340 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5341 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5342 | } else if (PyErr_Occurred()) { |
| 5343 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5344 | } else { |
| 5345 | exc = NULL; |
| 5346 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5347 | tmp = get_not_none(obj, &PyId_cause); |
| 5348 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5349 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5350 | res = obj2ast_expr(tmp, &cause, arena); |
| 5351 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5352 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5353 | } else if (PyErr_Occurred()) { |
| 5354 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5355 | } else { |
| 5356 | cause = NULL; |
| 5357 | } |
| 5358 | *out = Raise(exc, cause, lineno, col_offset, arena); |
| 5359 | if (*out == NULL) goto failed; |
| 5360 | return 0; |
| 5361 | } |
| 5362 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
| 5363 | if (isinstance == -1) { |
| 5364 | return 1; |
| 5365 | } |
| 5366 | if (isinstance) { |
| 5367 | asdl_seq* body; |
| 5368 | asdl_seq* handlers; |
| 5369 | asdl_seq* orelse; |
| 5370 | asdl_seq* finalbody; |
| 5371 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5372 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 5373 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5374 | int res; |
| 5375 | Py_ssize_t len; |
| 5376 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5377 | if (!PyList_Check(tmp)) { |
| 5378 | PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5379 | goto failed; |
| 5380 | } |
| 5381 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5382 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5383 | if (body == NULL) goto failed; |
| 5384 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5385 | stmt_ty val; |
| 5386 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5387 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5388 | if (len != PyList_GET_SIZE(tmp)) { |
| 5389 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 5390 | goto failed; |
| 5391 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5392 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5393 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5394 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5395 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5396 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5397 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 5398 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5399 | return 1; |
| 5400 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5401 | tmp = _PyObject_GetAttrId(obj, &PyId_handlers); |
| 5402 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5403 | int res; |
| 5404 | Py_ssize_t len; |
| 5405 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5406 | if (!PyList_Check(tmp)) { |
| 5407 | PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5408 | goto failed; |
| 5409 | } |
| 5410 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5411 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5412 | if (handlers == NULL) goto failed; |
| 5413 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5414 | excepthandler_ty val; |
| 5415 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5416 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5417 | if (len != PyList_GET_SIZE(tmp)) { |
| 5418 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 5419 | goto failed; |
| 5420 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5421 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5422 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5423 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5424 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5425 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5426 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 5427 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5428 | return 1; |
| 5429 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5430 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 5431 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5432 | int res; |
| 5433 | Py_ssize_t len; |
| 5434 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5435 | if (!PyList_Check(tmp)) { |
| 5436 | PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5437 | goto failed; |
| 5438 | } |
| 5439 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5440 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5441 | if (orelse == NULL) goto failed; |
| 5442 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5443 | stmt_ty val; |
| 5444 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5445 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5446 | if (len != PyList_GET_SIZE(tmp)) { |
| 5447 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 5448 | goto failed; |
| 5449 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5450 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5451 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5452 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5453 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5454 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5455 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 5456 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5457 | return 1; |
| 5458 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5459 | tmp = _PyObject_GetAttrId(obj, &PyId_finalbody); |
| 5460 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5461 | int res; |
| 5462 | Py_ssize_t len; |
| 5463 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5464 | if (!PyList_Check(tmp)) { |
| 5465 | PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5466 | goto failed; |
| 5467 | } |
| 5468 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5469 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5470 | if (finalbody == NULL) goto failed; |
| 5471 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5472 | stmt_ty val; |
| 5473 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5474 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5475 | if (len != PyList_GET_SIZE(tmp)) { |
| 5476 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 5477 | goto failed; |
| 5478 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5479 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5480 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5481 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5482 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5483 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5484 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 5485 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5486 | return 1; |
| 5487 | } |
| 5488 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
| 5489 | arena); |
| 5490 | if (*out == NULL) goto failed; |
| 5491 | return 0; |
| 5492 | } |
| 5493 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 5494 | if (isinstance == -1) { |
| 5495 | return 1; |
| 5496 | } |
| 5497 | if (isinstance) { |
| 5498 | expr_ty test; |
| 5499 | expr_ty msg; |
| 5500 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5501 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 5502 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5503 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5504 | res = obj2ast_expr(tmp, &test, arena); |
| 5505 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5506 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5507 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5508 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5509 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 5510 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5511 | return 1; |
| 5512 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5513 | tmp = get_not_none(obj, &PyId_msg); |
| 5514 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5515 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5516 | res = obj2ast_expr(tmp, &msg, arena); |
| 5517 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5518 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5519 | } else if (PyErr_Occurred()) { |
| 5520 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5521 | } else { |
| 5522 | msg = NULL; |
| 5523 | } |
| 5524 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 5525 | if (*out == NULL) goto failed; |
| 5526 | return 0; |
| 5527 | } |
| 5528 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 5529 | if (isinstance == -1) { |
| 5530 | return 1; |
| 5531 | } |
| 5532 | if (isinstance) { |
| 5533 | asdl_seq* names; |
| 5534 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5535 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 5536 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5537 | int res; |
| 5538 | Py_ssize_t len; |
| 5539 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5540 | if (!PyList_Check(tmp)) { |
| 5541 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5542 | goto failed; |
| 5543 | } |
| 5544 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5545 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5546 | if (names == NULL) goto failed; |
| 5547 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5548 | alias_ty val; |
| 5549 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5550 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5551 | if (len != PyList_GET_SIZE(tmp)) { |
| 5552 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 5553 | goto failed; |
| 5554 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5555 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5556 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5557 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5558 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5559 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5560 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 5561 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5562 | return 1; |
| 5563 | } |
| 5564 | *out = Import(names, lineno, col_offset, arena); |
| 5565 | if (*out == NULL) goto failed; |
| 5566 | return 0; |
| 5567 | } |
| 5568 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 5569 | if (isinstance == -1) { |
| 5570 | return 1; |
| 5571 | } |
| 5572 | if (isinstance) { |
| 5573 | identifier module; |
| 5574 | asdl_seq* names; |
| 5575 | int level; |
| 5576 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5577 | tmp = get_not_none(obj, &PyId_module); |
| 5578 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5579 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5580 | res = obj2ast_identifier(tmp, &module, arena); |
| 5581 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5582 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5583 | } else if (PyErr_Occurred()) { |
| 5584 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5585 | } else { |
| 5586 | module = NULL; |
| 5587 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5588 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 5589 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5590 | int res; |
| 5591 | Py_ssize_t len; |
| 5592 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5593 | if (!PyList_Check(tmp)) { |
| 5594 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5595 | goto failed; |
| 5596 | } |
| 5597 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5598 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5599 | if (names == NULL) goto failed; |
| 5600 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5601 | alias_ty val; |
| 5602 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5603 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5604 | if (len != PyList_GET_SIZE(tmp)) { |
| 5605 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 5606 | goto failed; |
| 5607 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5608 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5609 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5610 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5611 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5612 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5613 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 5614 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5615 | return 1; |
| 5616 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5617 | tmp = get_not_none(obj, &PyId_level); |
| 5618 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5619 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5620 | res = obj2ast_int(tmp, &level, arena); |
| 5621 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5622 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5623 | } else if (PyErr_Occurred()) { |
| 5624 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5625 | } else { |
| 5626 | level = 0; |
| 5627 | } |
| 5628 | *out = ImportFrom(module, names, level, lineno, col_offset, arena); |
| 5629 | if (*out == NULL) goto failed; |
| 5630 | return 0; |
| 5631 | } |
| 5632 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 5633 | if (isinstance == -1) { |
| 5634 | return 1; |
| 5635 | } |
| 5636 | if (isinstance) { |
| 5637 | asdl_seq* names; |
| 5638 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5639 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 5640 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5641 | int res; |
| 5642 | Py_ssize_t len; |
| 5643 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5644 | if (!PyList_Check(tmp)) { |
| 5645 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5646 | goto failed; |
| 5647 | } |
| 5648 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5649 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5650 | if (names == NULL) goto failed; |
| 5651 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5652 | identifier val; |
| 5653 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5654 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5655 | if (len != PyList_GET_SIZE(tmp)) { |
| 5656 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 5657 | goto failed; |
| 5658 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5659 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5660 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5661 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5662 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5663 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5664 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 5665 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5666 | return 1; |
| 5667 | } |
| 5668 | *out = Global(names, lineno, col_offset, arena); |
| 5669 | if (*out == NULL) goto failed; |
| 5670 | return 0; |
| 5671 | } |
| 5672 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 5673 | if (isinstance == -1) { |
| 5674 | return 1; |
| 5675 | } |
| 5676 | if (isinstance) { |
| 5677 | asdl_seq* names; |
| 5678 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5679 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 5680 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5681 | int res; |
| 5682 | Py_ssize_t len; |
| 5683 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5684 | if (!PyList_Check(tmp)) { |
| 5685 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5686 | goto failed; |
| 5687 | } |
| 5688 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5689 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5690 | if (names == NULL) goto failed; |
| 5691 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5692 | identifier val; |
| 5693 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5694 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5695 | if (len != PyList_GET_SIZE(tmp)) { |
| 5696 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 5697 | goto failed; |
| 5698 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5699 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5700 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5701 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5702 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5703 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5704 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 5705 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5706 | return 1; |
| 5707 | } |
| 5708 | *out = Nonlocal(names, lineno, col_offset, arena); |
| 5709 | if (*out == NULL) goto failed; |
| 5710 | return 0; |
| 5711 | } |
| 5712 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 5713 | if (isinstance == -1) { |
| 5714 | return 1; |
| 5715 | } |
| 5716 | if (isinstance) { |
| 5717 | expr_ty value; |
| 5718 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5719 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5720 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5721 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5722 | res = obj2ast_expr(tmp, &value, arena); |
| 5723 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5724 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5725 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5726 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5727 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 5728 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5729 | return 1; |
| 5730 | } |
| 5731 | *out = Expr(value, lineno, col_offset, arena); |
| 5732 | if (*out == NULL) goto failed; |
| 5733 | return 0; |
| 5734 | } |
| 5735 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 5736 | if (isinstance == -1) { |
| 5737 | return 1; |
| 5738 | } |
| 5739 | if (isinstance) { |
| 5740 | |
| 5741 | *out = Pass(lineno, col_offset, arena); |
| 5742 | if (*out == NULL) goto failed; |
| 5743 | return 0; |
| 5744 | } |
| 5745 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 5746 | if (isinstance == -1) { |
| 5747 | return 1; |
| 5748 | } |
| 5749 | if (isinstance) { |
| 5750 | |
| 5751 | *out = Break(lineno, col_offset, arena); |
| 5752 | if (*out == NULL) goto failed; |
| 5753 | return 0; |
| 5754 | } |
| 5755 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 5756 | if (isinstance == -1) { |
| 5757 | return 1; |
| 5758 | } |
| 5759 | if (isinstance) { |
| 5760 | |
| 5761 | *out = Continue(lineno, col_offset, arena); |
| 5762 | if (*out == NULL) goto failed; |
| 5763 | return 0; |
| 5764 | } |
| 5765 | |
| 5766 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 5767 | failed: |
| 5768 | Py_XDECREF(tmp); |
| 5769 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5770 | } |
| 5771 | |
| 5772 | int |
| 5773 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 5774 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5775 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5776 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5777 | PyObject *tmp = NULL; |
| 5778 | int lineno; |
| 5779 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5780 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5781 | if (obj == Py_None) { |
| 5782 | *out = NULL; |
| 5783 | return 0; |
| 5784 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5785 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 5786 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5787 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5788 | res = obj2ast_int(tmp, &lineno, arena); |
| 5789 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5790 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5791 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5792 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5793 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 5794 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5795 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5796 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5797 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 5798 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5799 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5800 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5801 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5802 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5803 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5804 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5805 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 5806 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5807 | return 1; |
| 5808 | } |
| 5809 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 5810 | if (isinstance == -1) { |
| 5811 | return 1; |
| 5812 | } |
| 5813 | if (isinstance) { |
| 5814 | boolop_ty op; |
| 5815 | asdl_seq* values; |
| 5816 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5817 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 5818 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5819 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5820 | res = obj2ast_boolop(tmp, &op, arena); |
| 5821 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5822 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5823 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5824 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5825 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 5826 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5827 | return 1; |
| 5828 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5829 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
| 5830 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5831 | int res; |
| 5832 | Py_ssize_t len; |
| 5833 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5834 | if (!PyList_Check(tmp)) { |
| 5835 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5836 | goto failed; |
| 5837 | } |
| 5838 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5839 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5840 | if (values == NULL) goto failed; |
| 5841 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5842 | expr_ty val; |
| 5843 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5844 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5845 | if (len != PyList_GET_SIZE(tmp)) { |
| 5846 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 5847 | goto failed; |
| 5848 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5849 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5850 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5851 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5852 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5853 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5854 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 5855 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5856 | return 1; |
| 5857 | } |
| 5858 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 5859 | if (*out == NULL) goto failed; |
| 5860 | return 0; |
| 5861 | } |
| 5862 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 5863 | if (isinstance == -1) { |
| 5864 | return 1; |
| 5865 | } |
| 5866 | if (isinstance) { |
| 5867 | expr_ty left; |
| 5868 | operator_ty op; |
| 5869 | expr_ty right; |
| 5870 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5871 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
| 5872 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5873 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5874 | res = obj2ast_expr(tmp, &left, arena); |
| 5875 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5876 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5877 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5878 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5879 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 5880 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5881 | return 1; |
| 5882 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5883 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 5884 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5885 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5886 | res = obj2ast_operator(tmp, &op, arena); |
| 5887 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5888 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5889 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5890 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5891 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 5892 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5893 | return 1; |
| 5894 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5895 | tmp = _PyObject_GetAttrId(obj, &PyId_right); |
| 5896 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5897 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5898 | res = obj2ast_expr(tmp, &right, arena); |
| 5899 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5900 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5901 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5902 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5903 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 5904 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5905 | return 1; |
| 5906 | } |
| 5907 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 5908 | if (*out == NULL) goto failed; |
| 5909 | return 0; |
| 5910 | } |
| 5911 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 5912 | if (isinstance == -1) { |
| 5913 | return 1; |
| 5914 | } |
| 5915 | if (isinstance) { |
| 5916 | unaryop_ty op; |
| 5917 | expr_ty operand; |
| 5918 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5919 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 5920 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5921 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5922 | res = obj2ast_unaryop(tmp, &op, arena); |
| 5923 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5924 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5925 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5926 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5927 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 5928 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5929 | return 1; |
| 5930 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5931 | tmp = _PyObject_GetAttrId(obj, &PyId_operand); |
| 5932 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5933 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5934 | res = obj2ast_expr(tmp, &operand, arena); |
| 5935 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5936 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5937 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5938 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5939 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 5940 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5941 | return 1; |
| 5942 | } |
| 5943 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 5944 | if (*out == NULL) goto failed; |
| 5945 | return 0; |
| 5946 | } |
| 5947 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 5948 | if (isinstance == -1) { |
| 5949 | return 1; |
| 5950 | } |
| 5951 | if (isinstance) { |
| 5952 | arguments_ty args; |
| 5953 | expr_ty body; |
| 5954 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5955 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 5956 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5957 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5958 | res = obj2ast_arguments(tmp, &args, arena); |
| 5959 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5960 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5961 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5962 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5963 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 5964 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5965 | return 1; |
| 5966 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5967 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 5968 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5969 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5970 | res = obj2ast_expr(tmp, &body, arena); |
| 5971 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5972 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5973 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5974 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 5975 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 5976 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5977 | return 1; |
| 5978 | } |
| 5979 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 5980 | if (*out == NULL) goto failed; |
| 5981 | return 0; |
| 5982 | } |
| 5983 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 5984 | if (isinstance == -1) { |
| 5985 | return 1; |
| 5986 | } |
| 5987 | if (isinstance) { |
| 5988 | expr_ty test; |
| 5989 | expr_ty body; |
| 5990 | expr_ty orelse; |
| 5991 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5992 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 5993 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5994 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5995 | res = obj2ast_expr(tmp, &test, arena); |
| 5996 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5997 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5998 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 5999 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6000 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 6001 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6002 | return 1; |
| 6003 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6004 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 6005 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6006 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6007 | res = obj2ast_expr(tmp, &body, arena); |
| 6008 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6009 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6010 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6011 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6012 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 6013 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6014 | return 1; |
| 6015 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6016 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 6017 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6018 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6019 | res = obj2ast_expr(tmp, &orelse, arena); |
| 6020 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6021 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6022 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6023 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6024 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 6025 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6026 | return 1; |
| 6027 | } |
| 6028 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 6029 | if (*out == NULL) goto failed; |
| 6030 | return 0; |
| 6031 | } |
| 6032 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 6033 | if (isinstance == -1) { |
| 6034 | return 1; |
| 6035 | } |
| 6036 | if (isinstance) { |
| 6037 | asdl_seq* keys; |
| 6038 | asdl_seq* values; |
| 6039 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6040 | tmp = _PyObject_GetAttrId(obj, &PyId_keys); |
| 6041 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6042 | int res; |
| 6043 | Py_ssize_t len; |
| 6044 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6045 | if (!PyList_Check(tmp)) { |
| 6046 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6047 | goto failed; |
| 6048 | } |
| 6049 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6050 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6051 | if (keys == NULL) goto failed; |
| 6052 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6053 | expr_ty val; |
| 6054 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6055 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6056 | if (len != PyList_GET_SIZE(tmp)) { |
| 6057 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 6058 | goto failed; |
| 6059 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6060 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6061 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6062 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6063 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6064 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6065 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 6066 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6067 | return 1; |
| 6068 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6069 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
| 6070 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6071 | int res; |
| 6072 | Py_ssize_t len; |
| 6073 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6074 | if (!PyList_Check(tmp)) { |
| 6075 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6076 | goto failed; |
| 6077 | } |
| 6078 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6079 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6080 | if (values == NULL) goto failed; |
| 6081 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6082 | expr_ty val; |
| 6083 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6084 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6085 | if (len != PyList_GET_SIZE(tmp)) { |
| 6086 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 6087 | goto failed; |
| 6088 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6089 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6090 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6091 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6092 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6093 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6094 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 6095 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6096 | return 1; |
| 6097 | } |
| 6098 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 6099 | if (*out == NULL) goto failed; |
| 6100 | return 0; |
| 6101 | } |
| 6102 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 6103 | if (isinstance == -1) { |
| 6104 | return 1; |
| 6105 | } |
| 6106 | if (isinstance) { |
| 6107 | asdl_seq* elts; |
| 6108 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6109 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
| 6110 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6111 | int res; |
| 6112 | Py_ssize_t len; |
| 6113 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6114 | if (!PyList_Check(tmp)) { |
| 6115 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6116 | goto failed; |
| 6117 | } |
| 6118 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6119 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6120 | if (elts == NULL) goto failed; |
| 6121 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6122 | expr_ty val; |
| 6123 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6124 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6125 | if (len != PyList_GET_SIZE(tmp)) { |
| 6126 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 6127 | goto failed; |
| 6128 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6129 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6130 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6131 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6132 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6133 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6134 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 6135 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6136 | return 1; |
| 6137 | } |
| 6138 | *out = Set(elts, lineno, col_offset, arena); |
| 6139 | if (*out == NULL) goto failed; |
| 6140 | return 0; |
| 6141 | } |
| 6142 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 6143 | if (isinstance == -1) { |
| 6144 | return 1; |
| 6145 | } |
| 6146 | if (isinstance) { |
| 6147 | expr_ty elt; |
| 6148 | asdl_seq* generators; |
| 6149 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6150 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
| 6151 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6152 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6153 | res = obj2ast_expr(tmp, &elt, arena); |
| 6154 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6155 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6156 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6157 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6158 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 6159 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6160 | return 1; |
| 6161 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6162 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 6163 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6164 | int res; |
| 6165 | Py_ssize_t len; |
| 6166 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6167 | if (!PyList_Check(tmp)) { |
| 6168 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6169 | goto failed; |
| 6170 | } |
| 6171 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6172 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6173 | if (generators == NULL) goto failed; |
| 6174 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6175 | comprehension_ty val; |
| 6176 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6177 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6178 | if (len != PyList_GET_SIZE(tmp)) { |
| 6179 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 6180 | goto failed; |
| 6181 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6182 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6183 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6184 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6185 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6186 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6187 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 6188 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6189 | return 1; |
| 6190 | } |
| 6191 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 6192 | if (*out == NULL) goto failed; |
| 6193 | return 0; |
| 6194 | } |
| 6195 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 6196 | if (isinstance == -1) { |
| 6197 | return 1; |
| 6198 | } |
| 6199 | if (isinstance) { |
| 6200 | expr_ty elt; |
| 6201 | asdl_seq* generators; |
| 6202 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6203 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
| 6204 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6205 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6206 | res = obj2ast_expr(tmp, &elt, arena); |
| 6207 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6208 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6209 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6210 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6211 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 6212 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6213 | return 1; |
| 6214 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6215 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 6216 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6217 | int res; |
| 6218 | Py_ssize_t len; |
| 6219 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6220 | if (!PyList_Check(tmp)) { |
| 6221 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6222 | goto failed; |
| 6223 | } |
| 6224 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6225 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6226 | if (generators == NULL) goto failed; |
| 6227 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6228 | comprehension_ty val; |
| 6229 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6230 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6231 | if (len != PyList_GET_SIZE(tmp)) { |
| 6232 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 6233 | goto failed; |
| 6234 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6235 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6236 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6237 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6238 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6239 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6240 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 6241 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6242 | return 1; |
| 6243 | } |
| 6244 | *out = SetComp(elt, generators, lineno, col_offset, arena); |
| 6245 | if (*out == NULL) goto failed; |
| 6246 | return 0; |
| 6247 | } |
| 6248 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 6249 | if (isinstance == -1) { |
| 6250 | return 1; |
| 6251 | } |
| 6252 | if (isinstance) { |
| 6253 | expr_ty key; |
| 6254 | expr_ty value; |
| 6255 | asdl_seq* generators; |
| 6256 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6257 | tmp = _PyObject_GetAttrId(obj, &PyId_key); |
| 6258 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6259 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6260 | res = obj2ast_expr(tmp, &key, arena); |
| 6261 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6262 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6263 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6264 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6265 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 6266 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6267 | return 1; |
| 6268 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6269 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6270 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6271 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6272 | res = obj2ast_expr(tmp, &value, arena); |
| 6273 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6274 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6275 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6276 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6277 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 6278 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6279 | return 1; |
| 6280 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6281 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 6282 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6283 | int res; |
| 6284 | Py_ssize_t len; |
| 6285 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6286 | if (!PyList_Check(tmp)) { |
| 6287 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6288 | goto failed; |
| 6289 | } |
| 6290 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6291 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6292 | if (generators == NULL) goto failed; |
| 6293 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6294 | comprehension_ty val; |
| 6295 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6296 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6297 | if (len != PyList_GET_SIZE(tmp)) { |
| 6298 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 6299 | goto failed; |
| 6300 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6301 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6302 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6303 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6304 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6305 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6306 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 6307 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6308 | return 1; |
| 6309 | } |
| 6310 | *out = DictComp(key, value, generators, lineno, col_offset, arena); |
| 6311 | if (*out == NULL) goto failed; |
| 6312 | return 0; |
| 6313 | } |
| 6314 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 6315 | if (isinstance == -1) { |
| 6316 | return 1; |
| 6317 | } |
| 6318 | if (isinstance) { |
| 6319 | expr_ty elt; |
| 6320 | asdl_seq* generators; |
| 6321 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6322 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
| 6323 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6324 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6325 | res = obj2ast_expr(tmp, &elt, arena); |
| 6326 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6327 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6328 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6329 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6330 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 6331 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6332 | return 1; |
| 6333 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6334 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 6335 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6336 | int res; |
| 6337 | Py_ssize_t len; |
| 6338 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6339 | if (!PyList_Check(tmp)) { |
| 6340 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6341 | goto failed; |
| 6342 | } |
| 6343 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6344 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6345 | if (generators == NULL) goto failed; |
| 6346 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6347 | comprehension_ty val; |
| 6348 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6349 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6350 | if (len != PyList_GET_SIZE(tmp)) { |
| 6351 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 6352 | goto failed; |
| 6353 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6354 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6355 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6356 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6357 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6358 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6359 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 6360 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6361 | return 1; |
| 6362 | } |
| 6363 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 6364 | if (*out == NULL) goto failed; |
| 6365 | return 0; |
| 6366 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6367 | isinstance = PyObject_IsInstance(obj, (PyObject*)Await_type); |
| 6368 | if (isinstance == -1) { |
| 6369 | return 1; |
| 6370 | } |
| 6371 | if (isinstance) { |
| 6372 | expr_ty value; |
| 6373 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6374 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6375 | if (tmp != NULL) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6376 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6377 | res = obj2ast_expr(tmp, &value, arena); |
| 6378 | if (res != 0) goto failed; |
| 6379 | Py_CLEAR(tmp); |
| 6380 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6381 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6382 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 6383 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6384 | return 1; |
| 6385 | } |
| 6386 | *out = Await(value, lineno, col_offset, arena); |
| 6387 | if (*out == NULL) goto failed; |
| 6388 | return 0; |
| 6389 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6390 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 6391 | if (isinstance == -1) { |
| 6392 | return 1; |
| 6393 | } |
| 6394 | if (isinstance) { |
| 6395 | expr_ty value; |
| 6396 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6397 | tmp = get_not_none(obj, &PyId_value); |
| 6398 | if (tmp != NULL) { |
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_expr(tmp, &value, 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 | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6403 | } else if (PyErr_Occurred()) { |
| 6404 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6405 | } else { |
| 6406 | value = NULL; |
| 6407 | } |
| 6408 | *out = Yield(value, lineno, col_offset, arena); |
| 6409 | if (*out == NULL) goto failed; |
| 6410 | return 0; |
| 6411 | } |
| 6412 | isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); |
| 6413 | if (isinstance == -1) { |
| 6414 | return 1; |
| 6415 | } |
| 6416 | if (isinstance) { |
| 6417 | expr_ty value; |
| 6418 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6419 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6420 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6421 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6422 | res = obj2ast_expr(tmp, &value, arena); |
| 6423 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6424 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6425 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6426 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6427 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 6428 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6429 | return 1; |
| 6430 | } |
| 6431 | *out = YieldFrom(value, lineno, col_offset, arena); |
| 6432 | if (*out == NULL) goto failed; |
| 6433 | return 0; |
| 6434 | } |
| 6435 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 6436 | if (isinstance == -1) { |
| 6437 | return 1; |
| 6438 | } |
| 6439 | if (isinstance) { |
| 6440 | expr_ty left; |
| 6441 | asdl_int_seq* ops; |
| 6442 | asdl_seq* comparators; |
| 6443 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6444 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
| 6445 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6446 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6447 | res = obj2ast_expr(tmp, &left, arena); |
| 6448 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6449 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6450 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6451 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6452 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 6453 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6454 | return 1; |
| 6455 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6456 | tmp = _PyObject_GetAttrId(obj, &PyId_ops); |
| 6457 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6458 | int res; |
| 6459 | Py_ssize_t len; |
| 6460 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6461 | if (!PyList_Check(tmp)) { |
| 6462 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6463 | goto failed; |
| 6464 | } |
| 6465 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6466 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6467 | if (ops == NULL) goto failed; |
| 6468 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6469 | cmpop_ty val; |
| 6470 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6471 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6472 | if (len != PyList_GET_SIZE(tmp)) { |
| 6473 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 6474 | goto failed; |
| 6475 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6476 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6477 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6478 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6479 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6480 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6481 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 6482 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6483 | return 1; |
| 6484 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6485 | tmp = _PyObject_GetAttrId(obj, &PyId_comparators); |
| 6486 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6487 | int res; |
| 6488 | Py_ssize_t len; |
| 6489 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6490 | if (!PyList_Check(tmp)) { |
| 6491 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6492 | goto failed; |
| 6493 | } |
| 6494 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6495 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6496 | if (comparators == NULL) goto failed; |
| 6497 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6498 | expr_ty val; |
| 6499 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6500 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6501 | if (len != PyList_GET_SIZE(tmp)) { |
| 6502 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 6503 | goto failed; |
| 6504 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6505 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6506 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6507 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6508 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6509 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6510 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 6511 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6512 | return 1; |
| 6513 | } |
| 6514 | *out = Compare(left, ops, comparators, lineno, col_offset, arena); |
| 6515 | if (*out == NULL) goto failed; |
| 6516 | return 0; |
| 6517 | } |
| 6518 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 6519 | if (isinstance == -1) { |
| 6520 | return 1; |
| 6521 | } |
| 6522 | if (isinstance) { |
| 6523 | expr_ty func; |
| 6524 | asdl_seq* args; |
| 6525 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6526 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6527 | tmp = _PyObject_GetAttrId(obj, &PyId_func); |
| 6528 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6529 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6530 | res = obj2ast_expr(tmp, &func, arena); |
| 6531 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6532 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6533 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6534 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6535 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 6536 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6537 | return 1; |
| 6538 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6539 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 6540 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6541 | int res; |
| 6542 | Py_ssize_t len; |
| 6543 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6544 | if (!PyList_Check(tmp)) { |
| 6545 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6546 | goto failed; |
| 6547 | } |
| 6548 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6549 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6550 | if (args == NULL) goto failed; |
| 6551 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6552 | expr_ty val; |
| 6553 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6554 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6555 | if (len != PyList_GET_SIZE(tmp)) { |
| 6556 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 6557 | goto failed; |
| 6558 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6559 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6560 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6561 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6562 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6563 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6564 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 6565 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6566 | return 1; |
| 6567 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6568 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
| 6569 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6570 | int res; |
| 6571 | Py_ssize_t len; |
| 6572 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6573 | if (!PyList_Check(tmp)) { |
| 6574 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6575 | goto failed; |
| 6576 | } |
| 6577 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6578 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6579 | if (keywords == NULL) goto failed; |
| 6580 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6581 | keyword_ty val; |
| 6582 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6583 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6584 | if (len != PyList_GET_SIZE(tmp)) { |
| 6585 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 6586 | goto failed; |
| 6587 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6588 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6589 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6590 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6591 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6592 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6593 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 6594 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6595 | return 1; |
| 6596 | } |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 6597 | *out = Call(func, args, keywords, lineno, col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6598 | if (*out == NULL) goto failed; |
| 6599 | return 0; |
| 6600 | } |
| 6601 | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); |
| 6602 | if (isinstance == -1) { |
| 6603 | return 1; |
| 6604 | } |
| 6605 | if (isinstance) { |
| 6606 | object n; |
| 6607 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6608 | tmp = _PyObject_GetAttrId(obj, &PyId_n); |
| 6609 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6610 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6611 | res = obj2ast_object(tmp, &n, arena); |
| 6612 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6613 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6614 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6615 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6616 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 6617 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6618 | return 1; |
| 6619 | } |
| 6620 | *out = Num(n, lineno, col_offset, arena); |
| 6621 | if (*out == NULL) goto failed; |
| 6622 | return 0; |
| 6623 | } |
| 6624 | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); |
| 6625 | if (isinstance == -1) { |
| 6626 | return 1; |
| 6627 | } |
| 6628 | if (isinstance) { |
| 6629 | string s; |
| 6630 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6631 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
| 6632 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6633 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6634 | res = obj2ast_string(tmp, &s, arena); |
| 6635 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6636 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6637 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6638 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6639 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 6640 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6641 | return 1; |
| 6642 | } |
| 6643 | *out = Str(s, lineno, col_offset, arena); |
| 6644 | if (*out == NULL) goto failed; |
| 6645 | return 0; |
| 6646 | } |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6647 | isinstance = PyObject_IsInstance(obj, (PyObject*)FormattedValue_type); |
| 6648 | if (isinstance == -1) { |
| 6649 | return 1; |
| 6650 | } |
| 6651 | if (isinstance) { |
| 6652 | expr_ty value; |
| 6653 | int conversion; |
| 6654 | expr_ty format_spec; |
| 6655 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6656 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6657 | if (tmp != NULL) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6658 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6659 | res = obj2ast_expr(tmp, &value, arena); |
| 6660 | if (res != 0) goto failed; |
| 6661 | Py_CLEAR(tmp); |
| 6662 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6663 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6664 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 6665 | } |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6666 | return 1; |
| 6667 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6668 | tmp = get_not_none(obj, &PyId_conversion); |
| 6669 | if (tmp != NULL) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6670 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6671 | res = obj2ast_int(tmp, &conversion, arena); |
| 6672 | if (res != 0) goto failed; |
| 6673 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6674 | } else if (PyErr_Occurred()) { |
| 6675 | return 1; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6676 | } else { |
| 6677 | conversion = 0; |
| 6678 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6679 | tmp = get_not_none(obj, &PyId_format_spec); |
| 6680 | if (tmp != NULL) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6681 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6682 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 6683 | if (res != 0) goto failed; |
| 6684 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6685 | } else if (PyErr_Occurred()) { |
| 6686 | return 1; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6687 | } else { |
| 6688 | format_spec = NULL; |
| 6689 | } |
| 6690 | *out = FormattedValue(value, conversion, format_spec, lineno, |
| 6691 | col_offset, arena); |
| 6692 | if (*out == NULL) goto failed; |
| 6693 | return 0; |
| 6694 | } |
| 6695 | isinstance = PyObject_IsInstance(obj, (PyObject*)JoinedStr_type); |
| 6696 | if (isinstance == -1) { |
| 6697 | return 1; |
| 6698 | } |
| 6699 | if (isinstance) { |
| 6700 | asdl_seq* values; |
| 6701 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6702 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
| 6703 | if (tmp != NULL) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6704 | int res; |
| 6705 | Py_ssize_t len; |
| 6706 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6707 | if (!PyList_Check(tmp)) { |
| 6708 | PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6709 | goto failed; |
| 6710 | } |
| 6711 | len = PyList_GET_SIZE(tmp); |
| 6712 | values = _Py_asdl_seq_new(len, arena); |
| 6713 | if (values == NULL) goto failed; |
| 6714 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6715 | expr_ty val; |
| 6716 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6717 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 6718 | if (len != PyList_GET_SIZE(tmp)) { |
| 6719 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 6720 | goto failed; |
| 6721 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6722 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6723 | } |
| 6724 | Py_CLEAR(tmp); |
| 6725 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6726 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6727 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 6728 | } |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6729 | return 1; |
| 6730 | } |
| 6731 | *out = JoinedStr(values, lineno, col_offset, arena); |
| 6732 | if (*out == NULL) goto failed; |
| 6733 | return 0; |
| 6734 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6735 | isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); |
| 6736 | if (isinstance == -1) { |
| 6737 | return 1; |
| 6738 | } |
| 6739 | if (isinstance) { |
| 6740 | bytes s; |
| 6741 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6742 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
| 6743 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6744 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6745 | res = obj2ast_bytes(tmp, &s, arena); |
| 6746 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6747 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6748 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6749 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6750 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); |
| 6751 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6752 | return 1; |
| 6753 | } |
| 6754 | *out = Bytes(s, lineno, col_offset, arena); |
| 6755 | if (*out == NULL) goto failed; |
| 6756 | return 0; |
| 6757 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6758 | isinstance = PyObject_IsInstance(obj, (PyObject*)NameConstant_type); |
| 6759 | if (isinstance == -1) { |
| 6760 | return 1; |
| 6761 | } |
| 6762 | if (isinstance) { |
| 6763 | singleton value; |
| 6764 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6765 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6766 | if (tmp != NULL) { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6767 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6768 | res = obj2ast_singleton(tmp, &value, arena); |
| 6769 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 6770 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6771 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6772 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6773 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NameConstant"); |
| 6774 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6775 | return 1; |
| 6776 | } |
| 6777 | *out = NameConstant(value, lineno, col_offset, arena); |
| 6778 | if (*out == NULL) goto failed; |
| 6779 | return 0; |
| 6780 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6781 | isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); |
| 6782 | if (isinstance == -1) { |
| 6783 | return 1; |
| 6784 | } |
| 6785 | if (isinstance) { |
| 6786 | |
| 6787 | *out = Ellipsis(lineno, col_offset, arena); |
| 6788 | if (*out == NULL) goto failed; |
| 6789 | return 0; |
| 6790 | } |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 6791 | isinstance = PyObject_IsInstance(obj, (PyObject*)Constant_type); |
| 6792 | if (isinstance == -1) { |
| 6793 | return 1; |
| 6794 | } |
| 6795 | if (isinstance) { |
| 6796 | constant value; |
| 6797 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6798 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6799 | if (tmp != NULL) { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 6800 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 6801 | res = obj2ast_constant(tmp, &value, arena); |
| 6802 | if (res != 0) goto failed; |
| 6803 | Py_CLEAR(tmp); |
| 6804 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6805 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6806 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 6807 | } |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 6808 | return 1; |
| 6809 | } |
| 6810 | *out = Constant(value, lineno, col_offset, arena); |
| 6811 | if (*out == NULL) goto failed; |
| 6812 | return 0; |
| 6813 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6814 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 6815 | if (isinstance == -1) { |
| 6816 | return 1; |
| 6817 | } |
| 6818 | if (isinstance) { |
| 6819 | expr_ty value; |
| 6820 | identifier attr; |
| 6821 | expr_context_ty ctx; |
| 6822 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6823 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6824 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6825 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6826 | res = obj2ast_expr(tmp, &value, arena); |
| 6827 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6828 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6829 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6830 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6831 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 6832 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6833 | return 1; |
| 6834 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6835 | tmp = _PyObject_GetAttrId(obj, &PyId_attr); |
| 6836 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6837 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6838 | res = obj2ast_identifier(tmp, &attr, arena); |
| 6839 | if (res != 0) goto failed; |
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 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6842 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6843 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 6844 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6845 | return 1; |
| 6846 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6847 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6848 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6849 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6850 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6851 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6852 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6853 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6854 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6855 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 6856 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6857 | return 1; |
| 6858 | } |
| 6859 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 6860 | if (*out == NULL) goto failed; |
| 6861 | return 0; |
| 6862 | } |
| 6863 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 6864 | if (isinstance == -1) { |
| 6865 | return 1; |
| 6866 | } |
| 6867 | if (isinstance) { |
| 6868 | expr_ty value; |
| 6869 | slice_ty slice; |
| 6870 | expr_context_ty ctx; |
| 6871 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6872 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6873 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6874 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6875 | res = obj2ast_expr(tmp, &value, arena); |
| 6876 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6877 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6878 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6879 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6880 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 6881 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6882 | return 1; |
| 6883 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6884 | tmp = _PyObject_GetAttrId(obj, &PyId_slice); |
| 6885 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6886 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6887 | res = obj2ast_slice(tmp, &slice, arena); |
| 6888 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6889 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6890 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6891 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6892 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 6893 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6894 | return 1; |
| 6895 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6896 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6897 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6898 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6899 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6900 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6901 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6902 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6903 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6904 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 6905 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6906 | return 1; |
| 6907 | } |
| 6908 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 6909 | if (*out == NULL) goto failed; |
| 6910 | return 0; |
| 6911 | } |
| 6912 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 6913 | if (isinstance == -1) { |
| 6914 | return 1; |
| 6915 | } |
| 6916 | if (isinstance) { |
| 6917 | expr_ty value; |
| 6918 | expr_context_ty ctx; |
| 6919 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6920 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6921 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6922 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6923 | res = obj2ast_expr(tmp, &value, arena); |
| 6924 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6925 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6926 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6927 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6928 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 6929 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6930 | return 1; |
| 6931 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6932 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6933 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6934 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6935 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6936 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6937 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6938 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6939 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6940 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 6941 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6942 | return 1; |
| 6943 | } |
| 6944 | *out = Starred(value, ctx, lineno, col_offset, arena); |
| 6945 | if (*out == NULL) goto failed; |
| 6946 | return 0; |
| 6947 | } |
| 6948 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 6949 | if (isinstance == -1) { |
| 6950 | return 1; |
| 6951 | } |
| 6952 | if (isinstance) { |
| 6953 | identifier id; |
| 6954 | expr_context_ty ctx; |
| 6955 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6956 | tmp = _PyObject_GetAttrId(obj, &PyId_id); |
| 6957 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6958 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6959 | res = obj2ast_identifier(tmp, &id, arena); |
| 6960 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6961 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6962 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6963 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6964 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 6965 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6966 | return 1; |
| 6967 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6968 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6969 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6970 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6971 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6972 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6973 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6974 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6975 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 6976 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 6977 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6978 | return 1; |
| 6979 | } |
| 6980 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 6981 | if (*out == NULL) goto failed; |
| 6982 | return 0; |
| 6983 | } |
| 6984 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 6985 | if (isinstance == -1) { |
| 6986 | return 1; |
| 6987 | } |
| 6988 | if (isinstance) { |
| 6989 | asdl_seq* elts; |
| 6990 | expr_context_ty ctx; |
| 6991 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 6992 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
| 6993 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6994 | int res; |
| 6995 | Py_ssize_t len; |
| 6996 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6997 | if (!PyList_Check(tmp)) { |
| 6998 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6999 | goto failed; |
| 7000 | } |
| 7001 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7002 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7003 | if (elts == NULL) goto failed; |
| 7004 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7005 | expr_ty val; |
| 7006 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7007 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7008 | if (len != PyList_GET_SIZE(tmp)) { |
| 7009 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 7010 | goto failed; |
| 7011 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7012 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7013 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7014 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7015 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7016 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7017 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 7018 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7019 | return 1; |
| 7020 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7021 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 7022 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7023 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7024 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7025 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7026 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7027 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7028 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7029 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 7030 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7031 | return 1; |
| 7032 | } |
| 7033 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 7034 | if (*out == NULL) goto failed; |
| 7035 | return 0; |
| 7036 | } |
| 7037 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 7038 | if (isinstance == -1) { |
| 7039 | return 1; |
| 7040 | } |
| 7041 | if (isinstance) { |
| 7042 | asdl_seq* elts; |
| 7043 | expr_context_ty ctx; |
| 7044 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7045 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
| 7046 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7047 | int res; |
| 7048 | Py_ssize_t len; |
| 7049 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7050 | if (!PyList_Check(tmp)) { |
| 7051 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7052 | goto failed; |
| 7053 | } |
| 7054 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7055 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7056 | if (elts == NULL) goto failed; |
| 7057 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7058 | expr_ty val; |
| 7059 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7060 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7061 | if (len != PyList_GET_SIZE(tmp)) { |
| 7062 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 7063 | goto failed; |
| 7064 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7065 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7066 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7067 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7068 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7069 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7070 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 7071 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7072 | return 1; |
| 7073 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7074 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 7075 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7076 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7077 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 7078 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7079 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7080 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7081 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7082 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 7083 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7084 | return 1; |
| 7085 | } |
| 7086 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 7087 | if (*out == NULL) goto failed; |
| 7088 | return 0; |
| 7089 | } |
| 7090 | |
| 7091 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 7092 | failed: |
| 7093 | Py_XDECREF(tmp); |
| 7094 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7095 | } |
| 7096 | |
| 7097 | int |
| 7098 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 7099 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7100 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7101 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7102 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 7103 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7104 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7105 | } |
| 7106 | if (isinstance) { |
| 7107 | *out = Load; |
| 7108 | return 0; |
| 7109 | } |
| 7110 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 7111 | if (isinstance == -1) { |
| 7112 | return 1; |
| 7113 | } |
| 7114 | if (isinstance) { |
| 7115 | *out = Store; |
| 7116 | return 0; |
| 7117 | } |
| 7118 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 7119 | if (isinstance == -1) { |
| 7120 | return 1; |
| 7121 | } |
| 7122 | if (isinstance) { |
| 7123 | *out = Del; |
| 7124 | return 0; |
| 7125 | } |
| 7126 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 7127 | if (isinstance == -1) { |
| 7128 | return 1; |
| 7129 | } |
| 7130 | if (isinstance) { |
| 7131 | *out = AugLoad; |
| 7132 | return 0; |
| 7133 | } |
| 7134 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 7135 | if (isinstance == -1) { |
| 7136 | return 1; |
| 7137 | } |
| 7138 | if (isinstance) { |
| 7139 | *out = AugStore; |
| 7140 | return 0; |
| 7141 | } |
| 7142 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 7143 | if (isinstance == -1) { |
| 7144 | return 1; |
| 7145 | } |
| 7146 | if (isinstance) { |
| 7147 | *out = Param; |
| 7148 | return 0; |
| 7149 | } |
| 7150 | |
| 7151 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 7152 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7153 | } |
| 7154 | |
| 7155 | int |
| 7156 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 7157 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7158 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7159 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7160 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7161 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7162 | if (obj == Py_None) { |
| 7163 | *out = NULL; |
| 7164 | return 0; |
| 7165 | } |
| 7166 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 7167 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7168 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7169 | } |
| 7170 | if (isinstance) { |
| 7171 | expr_ty lower; |
| 7172 | expr_ty upper; |
| 7173 | expr_ty step; |
| 7174 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7175 | tmp = get_not_none(obj, &PyId_lower); |
| 7176 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7177 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7178 | res = obj2ast_expr(tmp, &lower, arena); |
| 7179 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7180 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7181 | } else if (PyErr_Occurred()) { |
| 7182 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7183 | } else { |
| 7184 | lower = NULL; |
| 7185 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7186 | tmp = get_not_none(obj, &PyId_upper); |
| 7187 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7188 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7189 | res = obj2ast_expr(tmp, &upper, arena); |
| 7190 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7191 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7192 | } else if (PyErr_Occurred()) { |
| 7193 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7194 | } else { |
| 7195 | upper = NULL; |
| 7196 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7197 | tmp = get_not_none(obj, &PyId_step); |
| 7198 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7199 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7200 | res = obj2ast_expr(tmp, &step, arena); |
| 7201 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7202 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7203 | } else if (PyErr_Occurred()) { |
| 7204 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7205 | } else { |
| 7206 | step = NULL; |
| 7207 | } |
| 7208 | *out = Slice(lower, upper, step, arena); |
| 7209 | if (*out == NULL) goto failed; |
| 7210 | return 0; |
| 7211 | } |
| 7212 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 7213 | if (isinstance == -1) { |
| 7214 | return 1; |
| 7215 | } |
| 7216 | if (isinstance) { |
| 7217 | asdl_seq* dims; |
| 7218 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7219 | tmp = _PyObject_GetAttrId(obj, &PyId_dims); |
| 7220 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7221 | int res; |
| 7222 | Py_ssize_t len; |
| 7223 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7224 | if (!PyList_Check(tmp)) { |
| 7225 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7226 | goto failed; |
| 7227 | } |
| 7228 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7229 | dims = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7230 | if (dims == NULL) goto failed; |
| 7231 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7232 | slice_ty val; |
| 7233 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7234 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7235 | if (len != PyList_GET_SIZE(tmp)) { |
| 7236 | PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration"); |
| 7237 | goto failed; |
| 7238 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7239 | asdl_seq_SET(dims, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7240 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7241 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7242 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7243 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7244 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 7245 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7246 | return 1; |
| 7247 | } |
| 7248 | *out = ExtSlice(dims, arena); |
| 7249 | if (*out == NULL) goto failed; |
| 7250 | return 0; |
| 7251 | } |
| 7252 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 7253 | if (isinstance == -1) { |
| 7254 | return 1; |
| 7255 | } |
| 7256 | if (isinstance) { |
| 7257 | expr_ty value; |
| 7258 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7259 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 7260 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7261 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7262 | res = obj2ast_expr(tmp, &value, arena); |
| 7263 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7264 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7265 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7266 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7267 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 7268 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7269 | return 1; |
| 7270 | } |
| 7271 | *out = Index(value, arena); |
| 7272 | if (*out == NULL) goto failed; |
| 7273 | return 0; |
| 7274 | } |
| 7275 | |
| 7276 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 7277 | failed: |
| 7278 | Py_XDECREF(tmp); |
| 7279 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7280 | } |
| 7281 | |
| 7282 | int |
| 7283 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 7284 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7285 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7286 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7287 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 7288 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7289 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7290 | } |
| 7291 | if (isinstance) { |
| 7292 | *out = And; |
| 7293 | return 0; |
| 7294 | } |
| 7295 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 7296 | if (isinstance == -1) { |
| 7297 | return 1; |
| 7298 | } |
| 7299 | if (isinstance) { |
| 7300 | *out = Or; |
| 7301 | return 0; |
| 7302 | } |
| 7303 | |
| 7304 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 7305 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7306 | } |
| 7307 | |
| 7308 | int |
| 7309 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 7310 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7311 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7312 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7313 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 7314 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7315 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7316 | } |
| 7317 | if (isinstance) { |
| 7318 | *out = Add; |
| 7319 | return 0; |
| 7320 | } |
| 7321 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 7322 | if (isinstance == -1) { |
| 7323 | return 1; |
| 7324 | } |
| 7325 | if (isinstance) { |
| 7326 | *out = Sub; |
| 7327 | return 0; |
| 7328 | } |
| 7329 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 7330 | if (isinstance == -1) { |
| 7331 | return 1; |
| 7332 | } |
| 7333 | if (isinstance) { |
| 7334 | *out = Mult; |
| 7335 | return 0; |
| 7336 | } |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 7337 | isinstance = PyObject_IsInstance(obj, (PyObject *)MatMult_type); |
| 7338 | if (isinstance == -1) { |
| 7339 | return 1; |
| 7340 | } |
| 7341 | if (isinstance) { |
| 7342 | *out = MatMult; |
| 7343 | return 0; |
| 7344 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7345 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 7346 | if (isinstance == -1) { |
| 7347 | return 1; |
| 7348 | } |
| 7349 | if (isinstance) { |
| 7350 | *out = Div; |
| 7351 | return 0; |
| 7352 | } |
| 7353 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 7354 | if (isinstance == -1) { |
| 7355 | return 1; |
| 7356 | } |
| 7357 | if (isinstance) { |
| 7358 | *out = Mod; |
| 7359 | return 0; |
| 7360 | } |
| 7361 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 7362 | if (isinstance == -1) { |
| 7363 | return 1; |
| 7364 | } |
| 7365 | if (isinstance) { |
| 7366 | *out = Pow; |
| 7367 | return 0; |
| 7368 | } |
| 7369 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 7370 | if (isinstance == -1) { |
| 7371 | return 1; |
| 7372 | } |
| 7373 | if (isinstance) { |
| 7374 | *out = LShift; |
| 7375 | return 0; |
| 7376 | } |
| 7377 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 7378 | if (isinstance == -1) { |
| 7379 | return 1; |
| 7380 | } |
| 7381 | if (isinstance) { |
| 7382 | *out = RShift; |
| 7383 | return 0; |
| 7384 | } |
| 7385 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 7386 | if (isinstance == -1) { |
| 7387 | return 1; |
| 7388 | } |
| 7389 | if (isinstance) { |
| 7390 | *out = BitOr; |
| 7391 | return 0; |
| 7392 | } |
| 7393 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 7394 | if (isinstance == -1) { |
| 7395 | return 1; |
| 7396 | } |
| 7397 | if (isinstance) { |
| 7398 | *out = BitXor; |
| 7399 | return 0; |
| 7400 | } |
| 7401 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 7402 | if (isinstance == -1) { |
| 7403 | return 1; |
| 7404 | } |
| 7405 | if (isinstance) { |
| 7406 | *out = BitAnd; |
| 7407 | return 0; |
| 7408 | } |
| 7409 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 7410 | if (isinstance == -1) { |
| 7411 | return 1; |
| 7412 | } |
| 7413 | if (isinstance) { |
| 7414 | *out = FloorDiv; |
| 7415 | return 0; |
| 7416 | } |
| 7417 | |
| 7418 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 7419 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7420 | } |
| 7421 | |
| 7422 | int |
| 7423 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 7424 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7425 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7426 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7427 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 7428 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7429 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7430 | } |
| 7431 | if (isinstance) { |
| 7432 | *out = Invert; |
| 7433 | return 0; |
| 7434 | } |
| 7435 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 7436 | if (isinstance == -1) { |
| 7437 | return 1; |
| 7438 | } |
| 7439 | if (isinstance) { |
| 7440 | *out = Not; |
| 7441 | return 0; |
| 7442 | } |
| 7443 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 7444 | if (isinstance == -1) { |
| 7445 | return 1; |
| 7446 | } |
| 7447 | if (isinstance) { |
| 7448 | *out = UAdd; |
| 7449 | return 0; |
| 7450 | } |
| 7451 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 7452 | if (isinstance == -1) { |
| 7453 | return 1; |
| 7454 | } |
| 7455 | if (isinstance) { |
| 7456 | *out = USub; |
| 7457 | return 0; |
| 7458 | } |
| 7459 | |
| 7460 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 7461 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7462 | } |
| 7463 | |
| 7464 | int |
| 7465 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 7466 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7467 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7468 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7469 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 7470 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7471 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7472 | } |
| 7473 | if (isinstance) { |
| 7474 | *out = Eq; |
| 7475 | return 0; |
| 7476 | } |
| 7477 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 7478 | if (isinstance == -1) { |
| 7479 | return 1; |
| 7480 | } |
| 7481 | if (isinstance) { |
| 7482 | *out = NotEq; |
| 7483 | return 0; |
| 7484 | } |
| 7485 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 7486 | if (isinstance == -1) { |
| 7487 | return 1; |
| 7488 | } |
| 7489 | if (isinstance) { |
| 7490 | *out = Lt; |
| 7491 | return 0; |
| 7492 | } |
| 7493 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 7494 | if (isinstance == -1) { |
| 7495 | return 1; |
| 7496 | } |
| 7497 | if (isinstance) { |
| 7498 | *out = LtE; |
| 7499 | return 0; |
| 7500 | } |
| 7501 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 7502 | if (isinstance == -1) { |
| 7503 | return 1; |
| 7504 | } |
| 7505 | if (isinstance) { |
| 7506 | *out = Gt; |
| 7507 | return 0; |
| 7508 | } |
| 7509 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 7510 | if (isinstance == -1) { |
| 7511 | return 1; |
| 7512 | } |
| 7513 | if (isinstance) { |
| 7514 | *out = GtE; |
| 7515 | return 0; |
| 7516 | } |
| 7517 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 7518 | if (isinstance == -1) { |
| 7519 | return 1; |
| 7520 | } |
| 7521 | if (isinstance) { |
| 7522 | *out = Is; |
| 7523 | return 0; |
| 7524 | } |
| 7525 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 7526 | if (isinstance == -1) { |
| 7527 | return 1; |
| 7528 | } |
| 7529 | if (isinstance) { |
| 7530 | *out = IsNot; |
| 7531 | return 0; |
| 7532 | } |
| 7533 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 7534 | if (isinstance == -1) { |
| 7535 | return 1; |
| 7536 | } |
| 7537 | if (isinstance) { |
| 7538 | *out = In; |
| 7539 | return 0; |
| 7540 | } |
| 7541 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 7542 | if (isinstance == -1) { |
| 7543 | return 1; |
| 7544 | } |
| 7545 | if (isinstance) { |
| 7546 | *out = NotIn; |
| 7547 | return 0; |
| 7548 | } |
| 7549 | |
| 7550 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 7551 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7552 | } |
| 7553 | |
| 7554 | int |
| 7555 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 7556 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7557 | PyObject* tmp = NULL; |
| 7558 | expr_ty target; |
| 7559 | expr_ty iter; |
| 7560 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 7561 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7562 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7563 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 7564 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7565 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7566 | res = obj2ast_expr(tmp, &target, arena); |
| 7567 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7568 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7569 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7570 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7571 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 7572 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7573 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7574 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7575 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
| 7576 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7577 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7578 | res = obj2ast_expr(tmp, &iter, arena); |
| 7579 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7580 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7581 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7582 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7583 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 7584 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7585 | return 1; |
| 7586 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7587 | tmp = _PyObject_GetAttrId(obj, &PyId_ifs); |
| 7588 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7589 | int res; |
| 7590 | Py_ssize_t len; |
| 7591 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7592 | if (!PyList_Check(tmp)) { |
| 7593 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7594 | goto failed; |
| 7595 | } |
| 7596 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7597 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7598 | if (ifs == NULL) goto failed; |
| 7599 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7600 | expr_ty val; |
| 7601 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7602 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7603 | if (len != PyList_GET_SIZE(tmp)) { |
| 7604 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 7605 | goto failed; |
| 7606 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7607 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7608 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7609 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7610 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7611 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7612 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 7613 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7614 | return 1; |
| 7615 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7616 | tmp = _PyObject_GetAttrId(obj, &PyId_is_async); |
| 7617 | if (tmp != NULL) { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 7618 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 7619 | res = obj2ast_int(tmp, &is_async, arena); |
| 7620 | if (res != 0) goto failed; |
| 7621 | Py_CLEAR(tmp); |
| 7622 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7623 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7624 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 7625 | } |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 7626 | return 1; |
| 7627 | } |
| 7628 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7629 | return 0; |
| 7630 | failed: |
| 7631 | Py_XDECREF(tmp); |
| 7632 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7633 | } |
| 7634 | |
| 7635 | int |
| 7636 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 7637 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7638 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 7639 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7640 | PyObject *tmp = NULL; |
| 7641 | int lineno; |
| 7642 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7643 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7644 | if (obj == Py_None) { |
| 7645 | *out = NULL; |
| 7646 | return 0; |
| 7647 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7648 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 7649 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7650 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7651 | res = obj2ast_int(tmp, &lineno, arena); |
| 7652 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7653 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7654 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7655 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7656 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 7657 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7658 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7659 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7660 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 7661 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7662 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7663 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7664 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7665 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7666 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7667 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7668 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 7669 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7670 | return 1; |
| 7671 | } |
| 7672 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 7673 | if (isinstance == -1) { |
| 7674 | return 1; |
| 7675 | } |
| 7676 | if (isinstance) { |
| 7677 | expr_ty type; |
| 7678 | identifier name; |
| 7679 | asdl_seq* body; |
| 7680 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7681 | tmp = get_not_none(obj, &PyId_type); |
| 7682 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7683 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7684 | res = obj2ast_expr(tmp, &type, arena); |
| 7685 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7686 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7687 | } else if (PyErr_Occurred()) { |
| 7688 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7689 | } else { |
| 7690 | type = NULL; |
| 7691 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7692 | tmp = get_not_none(obj, &PyId_name); |
| 7693 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7694 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7695 | res = obj2ast_identifier(tmp, &name, arena); |
| 7696 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7697 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7698 | } else if (PyErr_Occurred()) { |
| 7699 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7700 | } else { |
| 7701 | name = NULL; |
| 7702 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7703 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 7704 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7705 | int res; |
| 7706 | Py_ssize_t len; |
| 7707 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7708 | if (!PyList_Check(tmp)) { |
| 7709 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7710 | goto failed; |
| 7711 | } |
| 7712 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7713 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7714 | if (body == NULL) goto failed; |
| 7715 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7716 | stmt_ty val; |
| 7717 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7718 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7719 | if (len != PyList_GET_SIZE(tmp)) { |
| 7720 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 7721 | goto failed; |
| 7722 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7723 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7724 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7725 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7726 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7727 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7728 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 7729 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7730 | return 1; |
| 7731 | } |
| 7732 | *out = ExceptHandler(type, name, body, lineno, col_offset, arena); |
| 7733 | if (*out == NULL) goto failed; |
| 7734 | return 0; |
| 7735 | } |
| 7736 | |
| 7737 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 7738 | failed: |
| 7739 | Py_XDECREF(tmp); |
| 7740 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7741 | } |
| 7742 | |
| 7743 | int |
| 7744 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 7745 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7746 | PyObject* tmp = NULL; |
| 7747 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7748 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7749 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7750 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7751 | arg_ty kwarg; |
| 7752 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7753 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7754 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 7755 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7756 | int res; |
| 7757 | Py_ssize_t len; |
| 7758 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7759 | if (!PyList_Check(tmp)) { |
| 7760 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7761 | goto failed; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7762 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7763 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7764 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7765 | if (args == NULL) goto failed; |
| 7766 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7767 | arg_ty val; |
| 7768 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7769 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7770 | if (len != PyList_GET_SIZE(tmp)) { |
| 7771 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 7772 | goto failed; |
| 7773 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7774 | asdl_seq_SET(args, i, val); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7775 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7776 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7777 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7778 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7779 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 7780 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7781 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7782 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7783 | tmp = get_not_none(obj, &PyId_vararg); |
| 7784 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7785 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7786 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7787 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7788 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7789 | } else if (PyErr_Occurred()) { |
| 7790 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7791 | } else { |
| 7792 | vararg = NULL; |
| 7793 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7794 | tmp = _PyObject_GetAttrId(obj, &PyId_kwonlyargs); |
| 7795 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7796 | int res; |
| 7797 | Py_ssize_t len; |
| 7798 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7799 | if (!PyList_Check(tmp)) { |
| 7800 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7801 | goto failed; |
| 7802 | } |
| 7803 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7804 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7805 | if (kwonlyargs == NULL) goto failed; |
| 7806 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7807 | arg_ty val; |
| 7808 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7809 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7810 | if (len != PyList_GET_SIZE(tmp)) { |
| 7811 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 7812 | goto failed; |
| 7813 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7814 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7815 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7816 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7817 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7818 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7819 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 7820 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7821 | return 1; |
| 7822 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7823 | tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults); |
| 7824 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7825 | int res; |
| 7826 | Py_ssize_t len; |
| 7827 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7828 | if (!PyList_Check(tmp)) { |
| 7829 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7830 | goto failed; |
| 7831 | } |
| 7832 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7833 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7834 | if (kw_defaults == NULL) goto failed; |
| 7835 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7836 | expr_ty val; |
| 7837 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7838 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7839 | if (len != PyList_GET_SIZE(tmp)) { |
| 7840 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 7841 | goto failed; |
| 7842 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7843 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7844 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7845 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7846 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7847 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7848 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 7849 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7850 | return 1; |
| 7851 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7852 | tmp = get_not_none(obj, &PyId_kwarg); |
| 7853 | if (tmp != NULL) { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7854 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7855 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 7856 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 7857 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7858 | } else if (PyErr_Occurred()) { |
| 7859 | return 1; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7860 | } else { |
| 7861 | kwarg = NULL; |
| 7862 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7863 | tmp = _PyObject_GetAttrId(obj, &PyId_defaults); |
| 7864 | if (tmp != NULL) { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7865 | int res; |
| 7866 | Py_ssize_t len; |
| 7867 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7868 | if (!PyList_Check(tmp)) { |
| 7869 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7870 | goto failed; |
| 7871 | } |
| 7872 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7873 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7874 | if (defaults == NULL) goto failed; |
| 7875 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7876 | expr_ty val; |
| 7877 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7878 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7879 | if (len != PyList_GET_SIZE(tmp)) { |
| 7880 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 7881 | goto failed; |
| 7882 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7883 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7884 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 7885 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7886 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7887 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7888 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 7889 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7890 | return 1; |
| 7891 | } |
| 7892 | *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg, defaults, |
| 7893 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7894 | return 0; |
| 7895 | failed: |
| 7896 | Py_XDECREF(tmp); |
| 7897 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7898 | } |
| 7899 | |
| 7900 | int |
| 7901 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 7902 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7903 | PyObject* tmp = NULL; |
| 7904 | identifier arg; |
| 7905 | expr_ty annotation; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 7906 | int lineno; |
| 7907 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7908 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7909 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
| 7910 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7911 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7912 | res = obj2ast_identifier(tmp, &arg, arena); |
| 7913 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7914 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7915 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7916 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7917 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 7918 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7919 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7920 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7921 | tmp = get_not_none(obj, &PyId_annotation); |
| 7922 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7923 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7924 | res = obj2ast_expr(tmp, &annotation, arena); |
| 7925 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7926 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7927 | } else if (PyErr_Occurred()) { |
| 7928 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7929 | } else { |
| 7930 | annotation = NULL; |
| 7931 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7932 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 7933 | if (tmp != NULL) { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 7934 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 7935 | res = obj2ast_int(tmp, &lineno, arena); |
| 7936 | if (res != 0) goto failed; |
| 7937 | Py_CLEAR(tmp); |
| 7938 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7939 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7940 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 7941 | } |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 7942 | return 1; |
| 7943 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7944 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 7945 | if (tmp != NULL) { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 7946 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 7947 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7948 | if (res != 0) goto failed; |
| 7949 | Py_CLEAR(tmp); |
| 7950 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7951 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7952 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 7953 | } |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 7954 | return 1; |
| 7955 | } |
| 7956 | *out = arg(arg, annotation, lineno, col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7957 | return 0; |
| 7958 | failed: |
| 7959 | Py_XDECREF(tmp); |
| 7960 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7961 | } |
| 7962 | |
| 7963 | int |
| 7964 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 7965 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7966 | PyObject* tmp = NULL; |
| 7967 | identifier arg; |
| 7968 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7969 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7970 | tmp = get_not_none(obj, &PyId_arg); |
| 7971 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7972 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7973 | res = obj2ast_identifier(tmp, &arg, arena); |
| 7974 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7975 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7976 | } else if (PyErr_Occurred()) { |
| 7977 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7978 | } else { |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 7979 | arg = NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7980 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7981 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 7982 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7983 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7984 | res = obj2ast_expr(tmp, &value, arena); |
| 7985 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7986 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7987 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 7988 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 7989 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 7990 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7991 | return 1; |
| 7992 | } |
| 7993 | *out = keyword(arg, value, arena); |
| 7994 | return 0; |
| 7995 | failed: |
| 7996 | Py_XDECREF(tmp); |
| 7997 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7998 | } |
| 7999 | |
| 8000 | int |
| 8001 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 8002 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8003 | PyObject* tmp = NULL; |
| 8004 | identifier name; |
| 8005 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8006 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 8007 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 8008 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8009 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8010 | res = obj2ast_identifier(tmp, &name, arena); |
| 8011 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8012 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8013 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 8014 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 8015 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 8016 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8017 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8018 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 8019 | tmp = get_not_none(obj, &PyId_asname); |
| 8020 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8021 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8022 | res = obj2ast_identifier(tmp, &asname, arena); |
| 8023 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8024 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 8025 | } else if (PyErr_Occurred()) { |
| 8026 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8027 | } else { |
| 8028 | asname = NULL; |
| 8029 | } |
| 8030 | *out = alias(name, asname, arena); |
| 8031 | return 0; |
| 8032 | failed: |
| 8033 | Py_XDECREF(tmp); |
| 8034 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8035 | } |
| 8036 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8037 | int |
| 8038 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 8039 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8040 | PyObject* tmp = NULL; |
| 8041 | expr_ty context_expr; |
| 8042 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8043 | |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 8044 | tmp = _PyObject_GetAttrId(obj, &PyId_context_expr); |
| 8045 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8046 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8047 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 8048 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8049 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8050 | } else { |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 8051 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
| 8052 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 8053 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8054 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8055 | } |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 8056 | tmp = get_not_none(obj, &PyId_optional_vars); |
| 8057 | if (tmp != NULL) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8058 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8059 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 8060 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8061 | Py_CLEAR(tmp); |
Serhiy Storchaka | bba2239 | 2017-11-11 16:41:32 +0200 | [diff] [blame] | 8062 | } else if (PyErr_Occurred()) { |
| 8063 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8064 | } else { |
| 8065 | optional_vars = NULL; |
| 8066 | } |
| 8067 | *out = withitem(context_expr, optional_vars, arena); |
| 8068 | return 0; |
| 8069 | failed: |
| 8070 | Py_XDECREF(tmp); |
| 8071 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 8072 | } |
| 8073 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8074 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 8075 | static struct PyModuleDef _astmodule = { |
| 8076 | PyModuleDef_HEAD_INIT, "_ast" |
| 8077 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8078 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 8079 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8080 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8081 | PyObject *m, *d; |
| 8082 | if (!init_types()) return NULL; |
| 8083 | m = PyModule_Create(&_astmodule); |
| 8084 | if (!m) return NULL; |
| 8085 | d = PyModule_GetDict(m); |
| 8086 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8087 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8088 | return NULL; |
| 8089 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; |
| 8090 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return |
| 8091 | NULL; |
| 8092 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) < |
| 8093 | 0) return NULL; |
| 8094 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0) |
| 8095 | return NULL; |
| 8096 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 8097 | NULL; |
| 8098 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL; |
| 8099 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) < |
| 8100 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8101 | if (PyDict_SetItemString(d, "AsyncFunctionDef", |
| 8102 | (PyObject*)AsyncFunctionDef_type) < 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8103 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 8104 | return NULL; |
| 8105 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return |
| 8106 | NULL; |
| 8107 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return |
| 8108 | NULL; |
| 8109 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return |
| 8110 | NULL; |
| 8111 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0) |
| 8112 | return NULL; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 8113 | if (PyDict_SetItemString(d, "AnnAssign", (PyObject*)AnnAssign_type) < 0) |
| 8114 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8115 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8116 | if (PyDict_SetItemString(d, "AsyncFor", (PyObject*)AsyncFor_type) < 0) |
| 8117 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8118 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 8119 | NULL; |
| 8120 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 8121 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8122 | if (PyDict_SetItemString(d, "AsyncWith", (PyObject*)AsyncWith_type) < 0) |
| 8123 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8124 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 8125 | NULL; |
| 8126 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL; |
| 8127 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return |
| 8128 | NULL; |
| 8129 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return |
| 8130 | NULL; |
| 8131 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0) |
| 8132 | return NULL; |
| 8133 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return |
| 8134 | NULL; |
| 8135 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
| 8136 | return NULL; |
| 8137 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL; |
| 8138 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL; |
| 8139 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 8140 | NULL; |
| 8141 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 8142 | return NULL; |
| 8143 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL; |
| 8144 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return |
| 8145 | NULL; |
| 8146 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 8147 | NULL; |
| 8148 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return |
| 8149 | NULL; |
| 8150 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return |
| 8151 | NULL; |
| 8152 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 8153 | NULL; |
| 8154 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL; |
| 8155 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL; |
| 8156 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 8157 | return NULL; |
| 8158 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return |
| 8159 | NULL; |
| 8160 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
| 8161 | return NULL; |
| 8162 | if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) < |
| 8163 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8164 | if (PyDict_SetItemString(d, "Await", (PyObject*)Await_type) < 0) return |
| 8165 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8166 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 8167 | NULL; |
| 8168 | if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0) |
| 8169 | return NULL; |
| 8170 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return |
| 8171 | NULL; |
| 8172 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL; |
| 8173 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return NULL; |
| 8174 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return NULL; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8175 | if (PyDict_SetItemString(d, "FormattedValue", |
| 8176 | (PyObject*)FormattedValue_type) < 0) return NULL; |
| 8177 | if (PyDict_SetItemString(d, "JoinedStr", (PyObject*)JoinedStr_type) < 0) |
| 8178 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8179 | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return |
| 8180 | NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 8181 | if (PyDict_SetItemString(d, "NameConstant", (PyObject*)NameConstant_type) < |
| 8182 | 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8183 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
| 8184 | return NULL; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8185 | if (PyDict_SetItemString(d, "Constant", (PyObject*)Constant_type) < 0) |
| 8186 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8187 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0) |
| 8188 | return NULL; |
| 8189 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0) |
| 8190 | return NULL; |
| 8191 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return |
| 8192 | NULL; |
| 8193 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL; |
| 8194 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL; |
| 8195 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 8196 | NULL; |
| 8197 | if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) < |
| 8198 | 0) return NULL; |
| 8199 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL; |
| 8200 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 8201 | NULL; |
| 8202 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL; |
| 8203 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return |
| 8204 | NULL; |
| 8205 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 8206 | return NULL; |
| 8207 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 8208 | NULL; |
| 8209 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 8210 | NULL; |
| 8211 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 8212 | NULL; |
| 8213 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 8214 | return NULL; |
| 8215 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 8216 | NULL; |
| 8217 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return |
| 8218 | NULL; |
| 8219 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL; |
| 8220 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
| 8221 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 8222 | return NULL; |
| 8223 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL; |
| 8224 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL; |
| 8225 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8226 | if (PyDict_SetItemString(d, "MatMult", (PyObject*)MatMult_type) < 0) return |
| 8227 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8228 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL; |
| 8229 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL; |
| 8230 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL; |
| 8231 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return |
| 8232 | NULL; |
| 8233 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return |
| 8234 | NULL; |
| 8235 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 8236 | NULL; |
| 8237 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return |
| 8238 | NULL; |
| 8239 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return |
| 8240 | NULL; |
| 8241 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 8242 | return NULL; |
| 8243 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return |
| 8244 | NULL; |
| 8245 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return |
| 8246 | NULL; |
| 8247 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL; |
| 8248 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL; |
| 8249 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL; |
| 8250 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 8251 | NULL; |
| 8252 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 8253 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 8254 | NULL; |
| 8255 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 8256 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL; |
| 8257 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 8258 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL; |
| 8259 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 8260 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 8261 | NULL; |
| 8262 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 8263 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 8264 | NULL; |
| 8265 | if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type) |
| 8266 | < 0) return NULL; |
| 8267 | if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type) |
| 8268 | < 0) return NULL; |
| 8269 | if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type) |
| 8270 | < 0) return NULL; |
| 8271 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0) |
| 8272 | return NULL; |
| 8273 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL; |
| 8274 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return |
| 8275 | NULL; |
| 8276 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 8277 | NULL; |
| 8278 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 8279 | return NULL; |
| 8280 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 8281 | } |
| 8282 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8283 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 8284 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8285 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 8286 | if (!init_types()) |
| 8287 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 8288 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8289 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 8290 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8291 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 8292 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8293 | { |
| 8294 | mod_ty res; |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 8295 | PyObject *req_type[3]; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8296 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 8297 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 8298 | |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 8299 | req_type[0] = (PyObject*)Module_type; |
| 8300 | req_type[1] = (PyObject*)Expression_type; |
| 8301 | req_type[2] = (PyObject*)Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 8302 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8303 | assert(0 <= mode && mode <= 2); |
| 8304 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 8305 | if (!init_types()) |
| 8306 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8307 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 8308 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 8309 | if (isinstance == -1) |
| 8310 | return NULL; |
| 8311 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 8312 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 8313 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8314 | return NULL; |
| 8315 | } |
| 8316 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 8317 | return NULL; |
| 8318 | else |
| 8319 | return res; |
| 8320 | } |
| 8321 | |
| 8322 | int PyAST_Check(PyObject* obj) |
| 8323 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 8324 | if (!init_types()) |
| 8325 | return -1; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 8326 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8327 | } |
| 8328 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 8329 | |