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); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 13 | static char *Module_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 14 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 15 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 16 | static PyTypeObject *Interactive_type; |
| 17 | static char *Interactive_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 18 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 19 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 20 | static PyTypeObject *Expression_type; |
| 21 | static char *Expression_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 22 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 23 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 24 | static PyTypeObject *Suite_type; |
| 25 | static char *Suite_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 26 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 27 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 28 | static PyTypeObject *stmt_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 29 | _Py_IDENTIFIER(lineno); |
| 30 | _Py_IDENTIFIER(col_offset); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 31 | static char *stmt_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 32 | "lineno", |
| 33 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 34 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 35 | static PyObject* ast2obj_stmt(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 36 | static PyTypeObject *FunctionDef_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 37 | _Py_IDENTIFIER(name); |
| 38 | _Py_IDENTIFIER(args); |
| 39 | _Py_IDENTIFIER(decorator_list); |
| 40 | _Py_IDENTIFIER(returns); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 41 | static char *FunctionDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 42 | "name", |
| 43 | "args", |
| 44 | "body", |
| 45 | "decorator_list", |
| 46 | "returns", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 47 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 48 | static PyTypeObject *AsyncFunctionDef_type; |
| 49 | static char *AsyncFunctionDef_fields[]={ |
| 50 | "name", |
| 51 | "args", |
| 52 | "body", |
| 53 | "decorator_list", |
| 54 | "returns", |
| 55 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 56 | static PyTypeObject *ClassDef_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 57 | _Py_IDENTIFIER(bases); |
| 58 | _Py_IDENTIFIER(keywords); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 59 | static char *ClassDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 60 | "name", |
| 61 | "bases", |
| 62 | "keywords", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 63 | "body", |
| 64 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 65 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 66 | static PyTypeObject *Return_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 67 | _Py_IDENTIFIER(value); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 68 | static char *Return_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 69 | "value", |
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 *Delete_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 72 | _Py_IDENTIFIER(targets); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 73 | static char *Delete_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 74 | "targets", |
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 *Assign_type; |
| 77 | static char *Assign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 78 | "targets", |
| 79 | "value", |
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 *AugAssign_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 82 | _Py_IDENTIFIER(target); |
| 83 | _Py_IDENTIFIER(op); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 84 | static char *AugAssign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 85 | "target", |
| 86 | "op", |
| 87 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 88 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 89 | static PyTypeObject *For_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 90 | _Py_IDENTIFIER(iter); |
| 91 | _Py_IDENTIFIER(orelse); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 92 | static char *For_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 93 | "target", |
| 94 | "iter", |
| 95 | "body", |
| 96 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 97 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 98 | static PyTypeObject *AsyncFor_type; |
| 99 | static char *AsyncFor_fields[]={ |
| 100 | "target", |
| 101 | "iter", |
| 102 | "body", |
| 103 | "orelse", |
| 104 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 105 | static PyTypeObject *While_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 106 | _Py_IDENTIFIER(test); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 107 | static char *While_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 108 | "test", |
| 109 | "body", |
| 110 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 111 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 112 | static PyTypeObject *If_type; |
| 113 | static char *If_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 114 | "test", |
| 115 | "body", |
| 116 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 117 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 118 | static PyTypeObject *With_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 119 | _Py_IDENTIFIER(items); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 120 | static char *With_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 121 | "items", |
| 122 | "body", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 123 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 124 | static PyTypeObject *AsyncWith_type; |
| 125 | static char *AsyncWith_fields[]={ |
| 126 | "items", |
| 127 | "body", |
| 128 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 129 | static PyTypeObject *Raise_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 130 | _Py_IDENTIFIER(exc); |
| 131 | _Py_IDENTIFIER(cause); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 132 | static char *Raise_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 133 | "exc", |
| 134 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 135 | }; |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 136 | static PyTypeObject *Try_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 137 | _Py_IDENTIFIER(handlers); |
| 138 | _Py_IDENTIFIER(finalbody); |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 139 | static char *Try_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 140 | "body", |
| 141 | "handlers", |
| 142 | "orelse", |
| 143 | "finalbody", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 144 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 145 | static PyTypeObject *Assert_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 146 | _Py_IDENTIFIER(msg); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 147 | static char *Assert_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 148 | "test", |
| 149 | "msg", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 150 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 151 | static PyTypeObject *Import_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 152 | _Py_IDENTIFIER(names); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 153 | static char *Import_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 154 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 155 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 156 | static PyTypeObject *ImportFrom_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 157 | _Py_IDENTIFIER(module); |
| 158 | _Py_IDENTIFIER(level); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 159 | static char *ImportFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 160 | "module", |
| 161 | "names", |
| 162 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 163 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 164 | static PyTypeObject *Global_type; |
| 165 | static char *Global_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 166 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 167 | }; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 168 | static PyTypeObject *Nonlocal_type; |
| 169 | static char *Nonlocal_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 170 | "names", |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 171 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 172 | static PyTypeObject *Expr_type; |
| 173 | static char *Expr_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 174 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 175 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 176 | static PyTypeObject *Pass_type; |
| 177 | static PyTypeObject *Break_type; |
| 178 | static PyTypeObject *Continue_type; |
| 179 | static PyTypeObject *expr_type; |
| 180 | static char *expr_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 181 | "lineno", |
| 182 | "col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 183 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 184 | static PyObject* ast2obj_expr(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 185 | static PyTypeObject *BoolOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 186 | _Py_IDENTIFIER(values); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 187 | static char *BoolOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 188 | "op", |
| 189 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 190 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 191 | static PyTypeObject *BinOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 192 | _Py_IDENTIFIER(left); |
| 193 | _Py_IDENTIFIER(right); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 194 | static char *BinOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 195 | "left", |
| 196 | "op", |
| 197 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 198 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 199 | static PyTypeObject *UnaryOp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 200 | _Py_IDENTIFIER(operand); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 201 | static char *UnaryOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 202 | "op", |
| 203 | "operand", |
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 *Lambda_type; |
| 206 | static char *Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 207 | "args", |
| 208 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 209 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 210 | static PyTypeObject *IfExp_type; |
| 211 | static char *IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 212 | "test", |
| 213 | "body", |
| 214 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 215 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 216 | static PyTypeObject *Dict_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 217 | _Py_IDENTIFIER(keys); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 218 | static char *Dict_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 219 | "keys", |
| 220 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 221 | }; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 222 | static PyTypeObject *Set_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 223 | _Py_IDENTIFIER(elts); |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 224 | static char *Set_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 225 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 226 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 227 | static PyTypeObject *ListComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 228 | _Py_IDENTIFIER(elt); |
| 229 | _Py_IDENTIFIER(generators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 230 | static char *ListComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 231 | "elt", |
| 232 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 233 | }; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 234 | static PyTypeObject *SetComp_type; |
| 235 | static char *SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 236 | "elt", |
| 237 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 238 | }; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 239 | static PyTypeObject *DictComp_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 240 | _Py_IDENTIFIER(key); |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 241 | static char *DictComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 242 | "key", |
| 243 | "value", |
| 244 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 245 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 246 | static PyTypeObject *GeneratorExp_type; |
| 247 | static char *GeneratorExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 248 | "elt", |
| 249 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 250 | }; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 251 | static PyTypeObject *Await_type; |
| 252 | static char *Await_fields[]={ |
| 253 | "value", |
| 254 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 255 | static PyTypeObject *Yield_type; |
| 256 | static char *Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 257 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 258 | }; |
| 259 | static PyTypeObject *YieldFrom_type; |
| 260 | static char *YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 261 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 262 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 263 | static PyTypeObject *Compare_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 264 | _Py_IDENTIFIER(ops); |
| 265 | _Py_IDENTIFIER(comparators); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 266 | static char *Compare_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 267 | "left", |
| 268 | "ops", |
| 269 | "comparators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 270 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 271 | static PyTypeObject *Call_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 272 | _Py_IDENTIFIER(func); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 273 | static char *Call_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 274 | "func", |
| 275 | "args", |
| 276 | "keywords", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 277 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 278 | static PyTypeObject *Num_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 279 | _Py_IDENTIFIER(n); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 280 | static char *Num_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 281 | "n", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 282 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 283 | static PyTypeObject *Str_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 284 | _Py_IDENTIFIER(s); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 285 | static char *Str_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 286 | "s", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 287 | }; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 288 | static PyTypeObject *FormattedValue_type; |
| 289 | _Py_IDENTIFIER(conversion); |
| 290 | _Py_IDENTIFIER(format_spec); |
| 291 | static char *FormattedValue_fields[]={ |
| 292 | "value", |
| 293 | "conversion", |
| 294 | "format_spec", |
| 295 | }; |
| 296 | static PyTypeObject *JoinedStr_type; |
| 297 | static char *JoinedStr_fields[]={ |
| 298 | "values", |
| 299 | }; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 300 | static PyTypeObject *Bytes_type; |
| 301 | static char *Bytes_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 302 | "s", |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 303 | }; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 304 | static PyTypeObject *NameConstant_type; |
| 305 | static char *NameConstant_fields[]={ |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 306 | "value", |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 307 | }; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 308 | static PyTypeObject *Ellipsis_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 309 | static PyTypeObject *Attribute_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 310 | _Py_IDENTIFIER(attr); |
| 311 | _Py_IDENTIFIER(ctx); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 312 | static char *Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 313 | "value", |
| 314 | "attr", |
| 315 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 316 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 317 | static PyTypeObject *Subscript_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 318 | _Py_IDENTIFIER(slice); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 319 | static char *Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 320 | "value", |
| 321 | "slice", |
| 322 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 323 | }; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 324 | static PyTypeObject *Starred_type; |
| 325 | static char *Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 326 | "value", |
| 327 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 328 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 329 | static PyTypeObject *Name_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 330 | _Py_IDENTIFIER(id); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 331 | static char *Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 332 | "id", |
| 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 *List_type; |
| 336 | static char *List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 337 | "elts", |
| 338 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 339 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 340 | static PyTypeObject *Tuple_type; |
| 341 | static char *Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 342 | "elts", |
| 343 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 344 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 345 | static PyTypeObject *expr_context_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 346 | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
| 347 | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
| 348 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 349 | static PyTypeObject *Load_type; |
| 350 | static PyTypeObject *Store_type; |
| 351 | static PyTypeObject *Del_type; |
| 352 | static PyTypeObject *AugLoad_type; |
| 353 | static PyTypeObject *AugStore_type; |
| 354 | static PyTypeObject *Param_type; |
| 355 | static PyTypeObject *slice_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 356 | static PyObject* ast2obj_slice(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 357 | static PyTypeObject *Slice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 358 | _Py_IDENTIFIER(lower); |
| 359 | _Py_IDENTIFIER(upper); |
| 360 | _Py_IDENTIFIER(step); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 361 | static char *Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 362 | "lower", |
| 363 | "upper", |
| 364 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 365 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 366 | static PyTypeObject *ExtSlice_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 367 | _Py_IDENTIFIER(dims); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 368 | static char *ExtSlice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 369 | "dims", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 370 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 371 | static PyTypeObject *Index_type; |
| 372 | static char *Index_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 373 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 374 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 375 | static PyTypeObject *boolop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 376 | static PyObject *And_singleton, *Or_singleton; |
| 377 | static PyObject* ast2obj_boolop(boolop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 378 | static PyTypeObject *And_type; |
| 379 | static PyTypeObject *Or_type; |
| 380 | static PyTypeObject *operator_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 381 | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 382 | *MatMult_singleton, *Div_singleton, *Mod_singleton, *Pow_singleton, |
| 383 | *LShift_singleton, *RShift_singleton, *BitOr_singleton, *BitXor_singleton, |
| 384 | *BitAnd_singleton, *FloorDiv_singleton; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 385 | static PyObject* ast2obj_operator(operator_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 386 | static PyTypeObject *Add_type; |
| 387 | static PyTypeObject *Sub_type; |
| 388 | static PyTypeObject *Mult_type; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 389 | static PyTypeObject *MatMult_type; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 390 | static PyTypeObject *Div_type; |
| 391 | static PyTypeObject *Mod_type; |
| 392 | static PyTypeObject *Pow_type; |
| 393 | static PyTypeObject *LShift_type; |
| 394 | static PyTypeObject *RShift_type; |
| 395 | static PyTypeObject *BitOr_type; |
| 396 | static PyTypeObject *BitXor_type; |
| 397 | static PyTypeObject *BitAnd_type; |
| 398 | static PyTypeObject *FloorDiv_type; |
| 399 | static PyTypeObject *unaryop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 400 | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
| 401 | *USub_singleton; |
| 402 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 403 | static PyTypeObject *Invert_type; |
| 404 | static PyTypeObject *Not_type; |
| 405 | static PyTypeObject *UAdd_type; |
| 406 | static PyTypeObject *USub_type; |
| 407 | static PyTypeObject *cmpop_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 408 | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
| 409 | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
| 410 | *NotIn_singleton; |
| 411 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 412 | static PyTypeObject *Eq_type; |
| 413 | static PyTypeObject *NotEq_type; |
| 414 | static PyTypeObject *Lt_type; |
| 415 | static PyTypeObject *LtE_type; |
| 416 | static PyTypeObject *Gt_type; |
| 417 | static PyTypeObject *GtE_type; |
| 418 | static PyTypeObject *Is_type; |
| 419 | static PyTypeObject *IsNot_type; |
| 420 | static PyTypeObject *In_type; |
| 421 | static PyTypeObject *NotIn_type; |
| 422 | static PyTypeObject *comprehension_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 423 | static PyObject* ast2obj_comprehension(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 424 | _Py_IDENTIFIER(ifs); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 425 | static char *comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 426 | "target", |
| 427 | "iter", |
| 428 | "ifs", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 429 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 430 | static PyTypeObject *excepthandler_type; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 431 | static char *excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 432 | "lineno", |
| 433 | "col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 434 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 435 | static PyObject* ast2obj_excepthandler(void*); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 436 | static PyTypeObject *ExceptHandler_type; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 437 | _Py_IDENTIFIER(type); |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 438 | static char *ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 439 | "type", |
| 440 | "name", |
| 441 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 442 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 443 | static PyTypeObject *arguments_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 444 | static PyObject* ast2obj_arguments(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 445 | _Py_IDENTIFIER(vararg); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 446 | _Py_IDENTIFIER(kwonlyargs); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 447 | _Py_IDENTIFIER(kw_defaults); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 448 | _Py_IDENTIFIER(kwarg); |
| 449 | _Py_IDENTIFIER(defaults); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 450 | static char *arguments_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 451 | "args", |
| 452 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 453 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 454 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 455 | "kwarg", |
| 456 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 457 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 458 | static PyTypeObject *arg_type; |
| 459 | static PyObject* ast2obj_arg(void*); |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 460 | static char *arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 461 | "lineno", |
| 462 | "col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 463 | }; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 464 | _Py_IDENTIFIER(arg); |
| 465 | _Py_IDENTIFIER(annotation); |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 466 | static char *arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 467 | "arg", |
| 468 | "annotation", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 469 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 470 | static PyTypeObject *keyword_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 471 | static PyObject* ast2obj_keyword(void*); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 472 | static char *keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 473 | "arg", |
| 474 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 475 | }; |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 476 | static PyTypeObject *alias_type; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 477 | static PyObject* ast2obj_alias(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 478 | _Py_IDENTIFIER(asname); |
Neal Norwitz | 53d960c | 2006-02-28 22:47:29 +0000 | [diff] [blame] | 479 | static char *alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 480 | "name", |
| 481 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 482 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 483 | static PyTypeObject *withitem_type; |
| 484 | static PyObject* ast2obj_withitem(void*); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 485 | _Py_IDENTIFIER(context_expr); |
| 486 | _Py_IDENTIFIER(optional_vars); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 487 | static char *withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 488 | "context_expr", |
| 489 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 490 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 491 | |
| 492 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 493 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 494 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 495 | PyObject *dict; |
| 496 | } AST_object; |
| 497 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 498 | static void |
| 499 | ast_dealloc(AST_object *self) |
| 500 | { |
| 501 | Py_CLEAR(self->dict); |
Antoine Pitrou | 5075074 | 2012-07-08 12:43:32 +0200 | [diff] [blame] | 502 | Py_TYPE(self)->tp_free(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 503 | } |
| 504 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 505 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 506 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 507 | { |
| 508 | Py_VISIT(self->dict); |
| 509 | return 0; |
| 510 | } |
| 511 | |
| 512 | static void |
| 513 | ast_clear(AST_object *self) |
| 514 | { |
| 515 | Py_CLEAR(self->dict); |
| 516 | } |
| 517 | |
| 518 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 519 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 520 | { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 521 | _Py_IDENTIFIER(_fields); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 522 | Py_ssize_t i, numfields = 0; |
| 523 | int res = -1; |
| 524 | PyObject *key, *value, *fields; |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 525 | fields = _PyObject_GetAttrId((PyObject*)Py_TYPE(self), &PyId__fields); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 526 | if (!fields) |
| 527 | PyErr_Clear(); |
| 528 | if (fields) { |
| 529 | numfields = PySequence_Size(fields); |
| 530 | if (numfields == -1) |
| 531 | goto cleanup; |
| 532 | } |
| 533 | res = 0; /* if no error occurs, this stays 0 to the end */ |
| 534 | if (PyTuple_GET_SIZE(args) > 0) { |
| 535 | if (numfields != PyTuple_GET_SIZE(args)) { |
| 536 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s" |
Amaury Forgeot d'Arc | 245c70b | 2008-09-10 22:24:24 +0000 | [diff] [blame] | 537 | "%zd positional argument%s", |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 538 | Py_TYPE(self)->tp_name, |
| 539 | numfields == 0 ? "" : "either 0 or ", |
| 540 | numfields, numfields == 1 ? "" : "s"); |
| 541 | res = -1; |
| 542 | goto cleanup; |
| 543 | } |
| 544 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 545 | /* cannot be reached when fields is NULL */ |
| 546 | PyObject *name = PySequence_GetItem(fields, i); |
| 547 | if (!name) { |
| 548 | res = -1; |
| 549 | goto cleanup; |
| 550 | } |
| 551 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 552 | Py_DECREF(name); |
| 553 | if (res < 0) |
| 554 | goto cleanup; |
| 555 | } |
| 556 | } |
| 557 | if (kw) { |
| 558 | i = 0; /* needed by PyDict_Next */ |
| 559 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 560 | res = PyObject_SetAttr(self, key, value); |
| 561 | if (res < 0) |
| 562 | goto cleanup; |
| 563 | } |
| 564 | } |
| 565 | cleanup: |
| 566 | Py_XDECREF(fields); |
| 567 | return res; |
| 568 | } |
| 569 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 570 | /* Pickling support */ |
| 571 | static PyObject * |
| 572 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 573 | { |
| 574 | PyObject *res; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 575 | _Py_IDENTIFIER(__dict__); |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 576 | PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 577 | if (dict == NULL) { |
| 578 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
| 579 | PyErr_Clear(); |
| 580 | else |
| 581 | return NULL; |
| 582 | } |
| 583 | if (dict) { |
| 584 | res = Py_BuildValue("O()O", Py_TYPE(self), dict); |
| 585 | Py_DECREF(dict); |
| 586 | return res; |
| 587 | } |
| 588 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 589 | } |
| 590 | |
| 591 | static PyMethodDef ast_type_methods[] = { |
| 592 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 593 | {NULL} |
| 594 | }; |
| 595 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 596 | static PyGetSetDef ast_type_getsets[] = { |
| 597 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 598 | {NULL} |
| 599 | }; |
| 600 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 601 | static PyTypeObject AST_type = { |
| 602 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 603 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 604 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 605 | 0, |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 606 | (destructor)ast_dealloc, /* tp_dealloc */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 607 | 0, /* tp_print */ |
| 608 | 0, /* tp_getattr */ |
| 609 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 610 | 0, /* tp_reserved */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 611 | 0, /* tp_repr */ |
| 612 | 0, /* tp_as_number */ |
| 613 | 0, /* tp_as_sequence */ |
| 614 | 0, /* tp_as_mapping */ |
| 615 | 0, /* tp_hash */ |
| 616 | 0, /* tp_call */ |
| 617 | 0, /* tp_str */ |
| 618 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 619 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 620 | 0, /* tp_as_buffer */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 621 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 622 | 0, /* tp_doc */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 623 | (traverseproc)ast_traverse, /* tp_traverse */ |
| 624 | (inquiry)ast_clear, /* tp_clear */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 625 | 0, /* tp_richcompare */ |
| 626 | 0, /* tp_weaklistoffset */ |
| 627 | 0, /* tp_iter */ |
| 628 | 0, /* tp_iternext */ |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 629 | ast_type_methods, /* tp_methods */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 630 | 0, /* tp_members */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 631 | ast_type_getsets, /* tp_getset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 632 | 0, /* tp_base */ |
| 633 | 0, /* tp_dict */ |
| 634 | 0, /* tp_descr_get */ |
| 635 | 0, /* tp_descr_set */ |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 636 | offsetof(AST_object, dict),/* tp_dictoffset */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 637 | (initproc)ast_type_init, /* tp_init */ |
| 638 | PyType_GenericAlloc, /* tp_alloc */ |
| 639 | PyType_GenericNew, /* tp_new */ |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 640 | PyObject_GC_Del, /* tp_free */ |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 641 | }; |
| 642 | |
| 643 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 644 | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 645 | { |
| 646 | PyObject *fnames, *result; |
| 647 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 648 | fnames = PyTuple_New(num_fields); |
| 649 | if (!fnames) return NULL; |
| 650 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 651 | PyObject *field = PyUnicode_FromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 652 | if (!field) { |
| 653 | Py_DECREF(fnames); |
| 654 | return NULL; |
| 655 | } |
| 656 | PyTuple_SET_ITEM(fnames, i, field); |
| 657 | } |
Victor Stinner | 7eeb5b5 | 2010-06-07 19:57:46 +0000 | [diff] [blame] | 658 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 659 | type, base, "_fields", fnames, "__module__", "_ast"); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 660 | Py_DECREF(fnames); |
| 661 | return (PyTypeObject*)result; |
| 662 | } |
| 663 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 664 | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 665 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 666 | int i, result; |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 667 | _Py_IDENTIFIER(_attributes); |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 668 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 669 | if (!l) |
| 670 | return 0; |
| 671 | for (i = 0; i < num_fields; i++) { |
Neal Norwitz | e4dc324 | 2007-08-25 01:33:49 +0000 | [diff] [blame] | 672 | s = PyUnicode_FromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 673 | if (!s) { |
| 674 | Py_DECREF(l); |
| 675 | return 0; |
| 676 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 677 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 678 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 679 | result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 680 | Py_DECREF(l); |
| 681 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 682 | } |
| 683 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 684 | /* Conversion AST -> Python */ |
| 685 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 686 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 687 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 688 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 689 | PyObject *result = PyList_New(n); |
| 690 | PyObject *value; |
| 691 | if (!result) |
| 692 | return NULL; |
| 693 | for (i = 0; i < n; i++) { |
| 694 | value = func(asdl_seq_GET(seq, i)); |
| 695 | if (!value) { |
| 696 | Py_DECREF(result); |
| 697 | return NULL; |
| 698 | } |
| 699 | PyList_SET_ITEM(result, i, value); |
| 700 | } |
| 701 | return result; |
| 702 | } |
| 703 | |
| 704 | static PyObject* ast2obj_object(void *o) |
| 705 | { |
| 706 | if (!o) |
| 707 | o = Py_None; |
| 708 | Py_INCREF((PyObject*)o); |
| 709 | return (PyObject*)o; |
| 710 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 711 | #define ast2obj_singleton ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 712 | #define ast2obj_identifier ast2obj_object |
| 713 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 714 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 715 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 716 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 717 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 718 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 719 | } |
| 720 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 721 | /* Conversion Python -> AST */ |
| 722 | |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 723 | static int obj2ast_singleton(PyObject *obj, PyObject** out, PyArena* arena) |
| 724 | { |
| 725 | if (obj != Py_None && obj != Py_True && obj != Py_False) { |
| 726 | PyErr_SetString(PyExc_ValueError, |
| 727 | "AST singleton must be True, False, or None"); |
| 728 | return 1; |
| 729 | } |
| 730 | *out = obj; |
| 731 | return 0; |
| 732 | } |
| 733 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 734 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 735 | { |
| 736 | if (obj == Py_None) |
| 737 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 738 | if (obj) { |
| 739 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 740 | *out = NULL; |
| 741 | return -1; |
| 742 | } |
| 743 | Py_INCREF(obj); |
| 744 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 745 | *out = obj; |
| 746 | return 0; |
| 747 | } |
| 748 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 749 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 750 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 751 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 752 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 753 | return 1; |
| 754 | } |
| 755 | return obj2ast_object(obj, out, arena); |
| 756 | } |
| 757 | |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 758 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 759 | { |
Benjamin Peterson | 0224d4e | 2011-08-31 22:13:03 -0400 | [diff] [blame] | 760 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 761 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 762 | return 1; |
| 763 | } |
| 764 | return obj2ast_object(obj, out, arena); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 765 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 766 | |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 767 | static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena) |
| 768 | { |
| 769 | if (!PyBytes_CheckExact(obj)) { |
| 770 | PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes"); |
| 771 | return 1; |
| 772 | } |
| 773 | return obj2ast_object(obj, out, arena); |
| 774 | } |
| 775 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 776 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 777 | { |
| 778 | int i; |
| 779 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 780 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 781 | return 1; |
| 782 | } |
| 783 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 784 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 785 | if (i == -1 && PyErr_Occurred()) |
| 786 | return 1; |
| 787 | *out = i; |
| 788 | return 0; |
| 789 | } |
| 790 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 791 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 792 | { |
| 793 | PyObject *empty_tuple, *d; |
| 794 | if (PyType_Ready(&AST_type) < 0) |
| 795 | return -1; |
| 796 | d = AST_type.tp_dict; |
| 797 | empty_tuple = PyTuple_New(0); |
| 798 | if (!empty_tuple || |
| 799 | PyDict_SetItemString(d, "_fields", empty_tuple) < 0 || |
| 800 | PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) { |
| 801 | Py_XDECREF(empty_tuple); |
| 802 | return -1; |
| 803 | } |
| 804 | Py_DECREF(empty_tuple); |
| 805 | return 0; |
| 806 | } |
| 807 | |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 808 | static int exists_not_none(PyObject *obj, _Py_Identifier *id) |
| 809 | { |
Benjamin Peterson | 3a61943 | 2013-03-18 23:40:53 -0700 | [diff] [blame] | 810 | int isnone; |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 811 | PyObject *attr = _PyObject_GetAttrId(obj, id); |
| 812 | if (!attr) { |
| 813 | PyErr_Clear(); |
| 814 | return 0; |
| 815 | } |
Benjamin Peterson | 3a61943 | 2013-03-18 23:40:53 -0700 | [diff] [blame] | 816 | isnone = attr == Py_None; |
Benjamin Peterson | b72406b | 2013-03-18 23:24:41 -0700 | [diff] [blame] | 817 | Py_DECREF(attr); |
| 818 | return !isnone; |
| 819 | } |
| 820 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 821 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 822 | static int init_types(void) |
| 823 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 824 | static int initialized; |
| 825 | if (initialized) return 1; |
| 826 | if (add_ast_fields() < 0) return 0; |
| 827 | mod_type = make_type("mod", &AST_type, NULL, 0); |
| 828 | if (!mod_type) return 0; |
| 829 | if (!add_attributes(mod_type, NULL, 0)) return 0; |
| 830 | Module_type = make_type("Module", mod_type, Module_fields, 1); |
| 831 | if (!Module_type) return 0; |
| 832 | Interactive_type = make_type("Interactive", mod_type, Interactive_fields, |
| 833 | 1); |
| 834 | if (!Interactive_type) return 0; |
| 835 | Expression_type = make_type("Expression", mod_type, Expression_fields, 1); |
| 836 | if (!Expression_type) return 0; |
| 837 | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
| 838 | if (!Suite_type) return 0; |
| 839 | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
| 840 | if (!stmt_type) return 0; |
| 841 | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
| 842 | FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields, |
| 843 | 5); |
| 844 | if (!FunctionDef_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 845 | AsyncFunctionDef_type = make_type("AsyncFunctionDef", stmt_type, |
| 846 | AsyncFunctionDef_fields, 5); |
| 847 | if (!AsyncFunctionDef_type) return 0; |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 848 | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 5); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 849 | if (!ClassDef_type) return 0; |
| 850 | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
| 851 | if (!Return_type) return 0; |
| 852 | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
| 853 | if (!Delete_type) return 0; |
| 854 | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
| 855 | if (!Assign_type) return 0; |
| 856 | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
| 857 | if (!AugAssign_type) return 0; |
| 858 | For_type = make_type("For", stmt_type, For_fields, 4); |
| 859 | if (!For_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 860 | AsyncFor_type = make_type("AsyncFor", stmt_type, AsyncFor_fields, 4); |
| 861 | if (!AsyncFor_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 862 | While_type = make_type("While", stmt_type, While_fields, 3); |
| 863 | if (!While_type) return 0; |
| 864 | If_type = make_type("If", stmt_type, If_fields, 3); |
| 865 | if (!If_type) return 0; |
| 866 | With_type = make_type("With", stmt_type, With_fields, 2); |
| 867 | if (!With_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 868 | AsyncWith_type = make_type("AsyncWith", stmt_type, AsyncWith_fields, 2); |
| 869 | if (!AsyncWith_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 870 | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
| 871 | if (!Raise_type) return 0; |
| 872 | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
| 873 | if (!Try_type) return 0; |
| 874 | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
| 875 | if (!Assert_type) return 0; |
| 876 | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
| 877 | if (!Import_type) return 0; |
| 878 | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, 3); |
| 879 | if (!ImportFrom_type) return 0; |
| 880 | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
| 881 | if (!Global_type) return 0; |
| 882 | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
| 883 | if (!Nonlocal_type) return 0; |
| 884 | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
| 885 | if (!Expr_type) return 0; |
| 886 | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
| 887 | if (!Pass_type) return 0; |
| 888 | Break_type = make_type("Break", stmt_type, NULL, 0); |
| 889 | if (!Break_type) return 0; |
| 890 | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
| 891 | if (!Continue_type) return 0; |
| 892 | expr_type = make_type("expr", &AST_type, NULL, 0); |
| 893 | if (!expr_type) return 0; |
| 894 | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
| 895 | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
| 896 | if (!BoolOp_type) return 0; |
| 897 | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
| 898 | if (!BinOp_type) return 0; |
| 899 | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
| 900 | if (!UnaryOp_type) return 0; |
| 901 | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
| 902 | if (!Lambda_type) return 0; |
| 903 | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
| 904 | if (!IfExp_type) return 0; |
| 905 | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
| 906 | if (!Dict_type) return 0; |
| 907 | Set_type = make_type("Set", expr_type, Set_fields, 1); |
| 908 | if (!Set_type) return 0; |
| 909 | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
| 910 | if (!ListComp_type) return 0; |
| 911 | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
| 912 | if (!SetComp_type) return 0; |
| 913 | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 914 | if (!DictComp_type) return 0; |
| 915 | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 916 | GeneratorExp_fields, 2); |
| 917 | if (!GeneratorExp_type) return 0; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 918 | Await_type = make_type("Await", expr_type, Await_fields, 1); |
| 919 | if (!Await_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 920 | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
| 921 | if (!Yield_type) return 0; |
| 922 | YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); |
| 923 | if (!YieldFrom_type) return 0; |
| 924 | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
| 925 | if (!Compare_type) return 0; |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 926 | Call_type = make_type("Call", expr_type, Call_fields, 3); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 927 | if (!Call_type) return 0; |
| 928 | Num_type = make_type("Num", expr_type, Num_fields, 1); |
| 929 | if (!Num_type) return 0; |
| 930 | Str_type = make_type("Str", expr_type, Str_fields, 1); |
| 931 | if (!Str_type) return 0; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 932 | FormattedValue_type = make_type("FormattedValue", expr_type, |
| 933 | FormattedValue_fields, 3); |
| 934 | if (!FormattedValue_type) return 0; |
| 935 | JoinedStr_type = make_type("JoinedStr", expr_type, JoinedStr_fields, 1); |
| 936 | if (!JoinedStr_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 937 | Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); |
| 938 | if (!Bytes_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 939 | NameConstant_type = make_type("NameConstant", expr_type, |
| 940 | NameConstant_fields, 1); |
| 941 | if (!NameConstant_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 942 | Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); |
| 943 | if (!Ellipsis_type) return 0; |
| 944 | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
| 945 | if (!Attribute_type) return 0; |
| 946 | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
| 947 | if (!Subscript_type) return 0; |
| 948 | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
| 949 | if (!Starred_type) return 0; |
| 950 | Name_type = make_type("Name", expr_type, Name_fields, 2); |
| 951 | if (!Name_type) return 0; |
| 952 | List_type = make_type("List", expr_type, List_fields, 2); |
| 953 | if (!List_type) return 0; |
| 954 | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
| 955 | if (!Tuple_type) return 0; |
| 956 | expr_context_type = make_type("expr_context", &AST_type, NULL, 0); |
| 957 | if (!expr_context_type) return 0; |
| 958 | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
| 959 | Load_type = make_type("Load", expr_context_type, NULL, 0); |
| 960 | if (!Load_type) return 0; |
| 961 | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
| 962 | if (!Load_singleton) return 0; |
| 963 | Store_type = make_type("Store", expr_context_type, NULL, 0); |
| 964 | if (!Store_type) return 0; |
| 965 | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
| 966 | if (!Store_singleton) return 0; |
| 967 | Del_type = make_type("Del", expr_context_type, NULL, 0); |
| 968 | if (!Del_type) return 0; |
| 969 | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
| 970 | if (!Del_singleton) return 0; |
| 971 | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
| 972 | if (!AugLoad_type) return 0; |
| 973 | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
| 974 | if (!AugLoad_singleton) return 0; |
| 975 | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
| 976 | if (!AugStore_type) return 0; |
| 977 | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
| 978 | if (!AugStore_singleton) return 0; |
| 979 | Param_type = make_type("Param", expr_context_type, NULL, 0); |
| 980 | if (!Param_type) return 0; |
| 981 | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
| 982 | if (!Param_singleton) return 0; |
| 983 | slice_type = make_type("slice", &AST_type, NULL, 0); |
| 984 | if (!slice_type) return 0; |
| 985 | if (!add_attributes(slice_type, NULL, 0)) return 0; |
| 986 | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
| 987 | if (!Slice_type) return 0; |
| 988 | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
| 989 | if (!ExtSlice_type) return 0; |
| 990 | Index_type = make_type("Index", slice_type, Index_fields, 1); |
| 991 | if (!Index_type) return 0; |
| 992 | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
| 993 | if (!boolop_type) return 0; |
| 994 | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
| 995 | And_type = make_type("And", boolop_type, NULL, 0); |
| 996 | if (!And_type) return 0; |
| 997 | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
| 998 | if (!And_singleton) return 0; |
| 999 | Or_type = make_type("Or", boolop_type, NULL, 0); |
| 1000 | if (!Or_type) return 0; |
| 1001 | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
| 1002 | if (!Or_singleton) return 0; |
| 1003 | operator_type = make_type("operator", &AST_type, NULL, 0); |
| 1004 | if (!operator_type) return 0; |
| 1005 | if (!add_attributes(operator_type, NULL, 0)) return 0; |
| 1006 | Add_type = make_type("Add", operator_type, NULL, 0); |
| 1007 | if (!Add_type) return 0; |
| 1008 | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
| 1009 | if (!Add_singleton) return 0; |
| 1010 | Sub_type = make_type("Sub", operator_type, NULL, 0); |
| 1011 | if (!Sub_type) return 0; |
| 1012 | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
| 1013 | if (!Sub_singleton) return 0; |
| 1014 | Mult_type = make_type("Mult", operator_type, NULL, 0); |
| 1015 | if (!Mult_type) return 0; |
| 1016 | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
| 1017 | if (!Mult_singleton) return 0; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 1018 | MatMult_type = make_type("MatMult", operator_type, NULL, 0); |
| 1019 | if (!MatMult_type) return 0; |
| 1020 | MatMult_singleton = PyType_GenericNew(MatMult_type, NULL, NULL); |
| 1021 | if (!MatMult_singleton) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1022 | Div_type = make_type("Div", operator_type, NULL, 0); |
| 1023 | if (!Div_type) return 0; |
| 1024 | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
| 1025 | if (!Div_singleton) return 0; |
| 1026 | Mod_type = make_type("Mod", operator_type, NULL, 0); |
| 1027 | if (!Mod_type) return 0; |
| 1028 | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
| 1029 | if (!Mod_singleton) return 0; |
| 1030 | Pow_type = make_type("Pow", operator_type, NULL, 0); |
| 1031 | if (!Pow_type) return 0; |
| 1032 | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
| 1033 | if (!Pow_singleton) return 0; |
| 1034 | LShift_type = make_type("LShift", operator_type, NULL, 0); |
| 1035 | if (!LShift_type) return 0; |
| 1036 | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
| 1037 | if (!LShift_singleton) return 0; |
| 1038 | RShift_type = make_type("RShift", operator_type, NULL, 0); |
| 1039 | if (!RShift_type) return 0; |
| 1040 | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
| 1041 | if (!RShift_singleton) return 0; |
| 1042 | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
| 1043 | if (!BitOr_type) return 0; |
| 1044 | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
| 1045 | if (!BitOr_singleton) return 0; |
| 1046 | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
| 1047 | if (!BitXor_type) return 0; |
| 1048 | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
| 1049 | if (!BitXor_singleton) return 0; |
| 1050 | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
| 1051 | if (!BitAnd_type) return 0; |
| 1052 | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
| 1053 | if (!BitAnd_singleton) return 0; |
| 1054 | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
| 1055 | if (!FloorDiv_type) return 0; |
| 1056 | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
| 1057 | if (!FloorDiv_singleton) return 0; |
| 1058 | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
| 1059 | if (!unaryop_type) return 0; |
| 1060 | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
| 1061 | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
| 1062 | if (!Invert_type) return 0; |
| 1063 | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
| 1064 | if (!Invert_singleton) return 0; |
| 1065 | Not_type = make_type("Not", unaryop_type, NULL, 0); |
| 1066 | if (!Not_type) return 0; |
| 1067 | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
| 1068 | if (!Not_singleton) return 0; |
| 1069 | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
| 1070 | if (!UAdd_type) return 0; |
| 1071 | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
| 1072 | if (!UAdd_singleton) return 0; |
| 1073 | USub_type = make_type("USub", unaryop_type, NULL, 0); |
| 1074 | if (!USub_type) return 0; |
| 1075 | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
| 1076 | if (!USub_singleton) return 0; |
| 1077 | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
| 1078 | if (!cmpop_type) return 0; |
| 1079 | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
| 1080 | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
| 1081 | if (!Eq_type) return 0; |
| 1082 | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
| 1083 | if (!Eq_singleton) return 0; |
| 1084 | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
| 1085 | if (!NotEq_type) return 0; |
| 1086 | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
| 1087 | if (!NotEq_singleton) return 0; |
| 1088 | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
| 1089 | if (!Lt_type) return 0; |
| 1090 | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
| 1091 | if (!Lt_singleton) return 0; |
| 1092 | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
| 1093 | if (!LtE_type) return 0; |
| 1094 | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
| 1095 | if (!LtE_singleton) return 0; |
| 1096 | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
| 1097 | if (!Gt_type) return 0; |
| 1098 | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
| 1099 | if (!Gt_singleton) return 0; |
| 1100 | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
| 1101 | if (!GtE_type) return 0; |
| 1102 | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
| 1103 | if (!GtE_singleton) return 0; |
| 1104 | Is_type = make_type("Is", cmpop_type, NULL, 0); |
| 1105 | if (!Is_type) return 0; |
| 1106 | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
| 1107 | if (!Is_singleton) return 0; |
| 1108 | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
| 1109 | if (!IsNot_type) return 0; |
| 1110 | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
| 1111 | if (!IsNot_singleton) return 0; |
| 1112 | In_type = make_type("In", cmpop_type, NULL, 0); |
| 1113 | if (!In_type) return 0; |
| 1114 | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
| 1115 | if (!In_singleton) return 0; |
| 1116 | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
| 1117 | if (!NotIn_type) return 0; |
| 1118 | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
| 1119 | if (!NotIn_singleton) return 0; |
| 1120 | comprehension_type = make_type("comprehension", &AST_type, |
| 1121 | comprehension_fields, 3); |
| 1122 | if (!comprehension_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1123 | if (!add_attributes(comprehension_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1124 | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
| 1125 | if (!excepthandler_type) return 0; |
| 1126 | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
| 1127 | return 0; |
| 1128 | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
| 1129 | ExceptHandler_fields, 3); |
| 1130 | if (!ExceptHandler_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1131 | arguments_type = make_type("arguments", &AST_type, arguments_fields, 6); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1132 | if (!arguments_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1133 | if (!add_attributes(arguments_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1134 | arg_type = make_type("arg", &AST_type, arg_fields, 2); |
| 1135 | if (!arg_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1136 | if (!add_attributes(arg_type, arg_attributes, 2)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1137 | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
| 1138 | if (!keyword_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1139 | if (!add_attributes(keyword_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1140 | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
| 1141 | if (!alias_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1142 | if (!add_attributes(alias_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1143 | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
| 1144 | if (!withitem_type) return 0; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1145 | if (!add_attributes(withitem_type, NULL, 0)) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1146 | initialized = 1; |
| 1147 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1148 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1149 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1150 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1151 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1152 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1153 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1154 | arena); |
| 1155 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1156 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1157 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1158 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1159 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1160 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1161 | arena); |
| 1162 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1163 | arena); |
| 1164 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1165 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1166 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1167 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1168 | 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] | 1169 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1170 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1171 | Module(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1172 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1173 | mod_ty p; |
| 1174 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1175 | if (!p) |
| 1176 | return NULL; |
| 1177 | p->kind = Module_kind; |
| 1178 | p->v.Module.body = body; |
| 1179 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1183 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1184 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1185 | mod_ty p; |
| 1186 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1187 | if (!p) |
| 1188 | return NULL; |
| 1189 | p->kind = Interactive_kind; |
| 1190 | p->v.Interactive.body = body; |
| 1191 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1195 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1196 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1197 | mod_ty p; |
| 1198 | if (!body) { |
| 1199 | PyErr_SetString(PyExc_ValueError, |
| 1200 | "field body is required for Expression"); |
| 1201 | return NULL; |
| 1202 | } |
| 1203 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1204 | if (!p) |
| 1205 | return NULL; |
| 1206 | p->kind = Expression_kind; |
| 1207 | p->v.Expression.body = body; |
| 1208 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1212 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1213 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1214 | mod_ty p; |
| 1215 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1216 | if (!p) |
| 1217 | return NULL; |
| 1218 | p->kind = Suite_kind; |
| 1219 | p->v.Suite.body = body; |
| 1220 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | stmt_ty |
| 1224 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1225 | decorator_list, expr_ty returns, int lineno, int col_offset, |
| 1226 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1227 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1228 | stmt_ty p; |
| 1229 | if (!name) { |
| 1230 | PyErr_SetString(PyExc_ValueError, |
| 1231 | "field name is required for FunctionDef"); |
| 1232 | return NULL; |
| 1233 | } |
| 1234 | if (!args) { |
| 1235 | PyErr_SetString(PyExc_ValueError, |
| 1236 | "field args is required for FunctionDef"); |
| 1237 | return NULL; |
| 1238 | } |
| 1239 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1240 | if (!p) |
| 1241 | return NULL; |
| 1242 | p->kind = FunctionDef_kind; |
| 1243 | p->v.FunctionDef.name = name; |
| 1244 | p->v.FunctionDef.args = args; |
| 1245 | p->v.FunctionDef.body = body; |
| 1246 | p->v.FunctionDef.decorator_list = decorator_list; |
| 1247 | p->v.FunctionDef.returns = returns; |
| 1248 | p->lineno = lineno; |
| 1249 | p->col_offset = col_offset; |
| 1250 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1254 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
| 1255 | * decorator_list, expr_ty returns, int lineno, int col_offset, |
| 1256 | PyArena *arena) |
| 1257 | { |
| 1258 | stmt_ty p; |
| 1259 | if (!name) { |
| 1260 | PyErr_SetString(PyExc_ValueError, |
| 1261 | "field name is required for AsyncFunctionDef"); |
| 1262 | return NULL; |
| 1263 | } |
| 1264 | if (!args) { |
| 1265 | PyErr_SetString(PyExc_ValueError, |
| 1266 | "field args is required for AsyncFunctionDef"); |
| 1267 | return NULL; |
| 1268 | } |
| 1269 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1270 | if (!p) |
| 1271 | return NULL; |
| 1272 | p->kind = AsyncFunctionDef_kind; |
| 1273 | p->v.AsyncFunctionDef.name = name; |
| 1274 | p->v.AsyncFunctionDef.args = args; |
| 1275 | p->v.AsyncFunctionDef.body = body; |
| 1276 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 1277 | p->v.AsyncFunctionDef.returns = returns; |
| 1278 | p->lineno = lineno; |
| 1279 | p->col_offset = col_offset; |
| 1280 | return p; |
| 1281 | } |
| 1282 | |
| 1283 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 1284 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
| 1285 | body, asdl_seq * decorator_list, int lineno, int col_offset, PyArena |
| 1286 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1287 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1288 | stmt_ty p; |
| 1289 | if (!name) { |
| 1290 | PyErr_SetString(PyExc_ValueError, |
| 1291 | "field name is required for ClassDef"); |
| 1292 | return NULL; |
| 1293 | } |
| 1294 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1295 | if (!p) |
| 1296 | return NULL; |
| 1297 | p->kind = ClassDef_kind; |
| 1298 | p->v.ClassDef.name = name; |
| 1299 | p->v.ClassDef.bases = bases; |
| 1300 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1301 | p->v.ClassDef.body = body; |
| 1302 | p->v.ClassDef.decorator_list = decorator_list; |
| 1303 | p->lineno = lineno; |
| 1304 | p->col_offset = col_offset; |
| 1305 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1309 | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1310 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1311 | stmt_ty p; |
| 1312 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1313 | if (!p) |
| 1314 | return NULL; |
| 1315 | p->kind = Return_kind; |
| 1316 | p->v.Return.value = value; |
| 1317 | p->lineno = lineno; |
| 1318 | p->col_offset = col_offset; |
| 1319 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1323 | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1324 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1325 | stmt_ty p; |
| 1326 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1327 | if (!p) |
| 1328 | return NULL; |
| 1329 | p->kind = Delete_kind; |
| 1330 | p->v.Delete.targets = targets; |
| 1331 | p->lineno = lineno; |
| 1332 | p->col_offset = col_offset; |
| 1333 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1337 | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
| 1338 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1339 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1340 | stmt_ty p; |
| 1341 | if (!value) { |
| 1342 | PyErr_SetString(PyExc_ValueError, |
| 1343 | "field value is required for Assign"); |
| 1344 | return NULL; |
| 1345 | } |
| 1346 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1347 | if (!p) |
| 1348 | return NULL; |
| 1349 | p->kind = Assign_kind; |
| 1350 | p->v.Assign.targets = targets; |
| 1351 | p->v.Assign.value = value; |
| 1352 | p->lineno = lineno; |
| 1353 | p->col_offset = col_offset; |
| 1354 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1358 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
| 1359 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1360 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1361 | stmt_ty p; |
| 1362 | if (!target) { |
| 1363 | PyErr_SetString(PyExc_ValueError, |
| 1364 | "field target is required for AugAssign"); |
| 1365 | return NULL; |
| 1366 | } |
| 1367 | if (!op) { |
| 1368 | PyErr_SetString(PyExc_ValueError, |
| 1369 | "field op is required for AugAssign"); |
| 1370 | return NULL; |
| 1371 | } |
| 1372 | if (!value) { |
| 1373 | PyErr_SetString(PyExc_ValueError, |
| 1374 | "field value is required for AugAssign"); |
| 1375 | return NULL; |
| 1376 | } |
| 1377 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1378 | if (!p) |
| 1379 | return NULL; |
| 1380 | p->kind = AugAssign_kind; |
| 1381 | p->v.AugAssign.target = target; |
| 1382 | p->v.AugAssign.op = op; |
| 1383 | p->v.AugAssign.value = value; |
| 1384 | p->lineno = lineno; |
| 1385 | p->col_offset = col_offset; |
| 1386 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | stmt_ty |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1390 | 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] | 1391 | lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1392 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1393 | stmt_ty p; |
| 1394 | if (!target) { |
| 1395 | PyErr_SetString(PyExc_ValueError, |
| 1396 | "field target is required for For"); |
| 1397 | return NULL; |
| 1398 | } |
| 1399 | if (!iter) { |
| 1400 | PyErr_SetString(PyExc_ValueError, |
| 1401 | "field iter is required for For"); |
| 1402 | return NULL; |
| 1403 | } |
| 1404 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1405 | if (!p) |
| 1406 | return NULL; |
| 1407 | p->kind = For_kind; |
| 1408 | p->v.For.target = target; |
| 1409 | p->v.For.iter = iter; |
| 1410 | p->v.For.body = body; |
| 1411 | p->v.For.orelse = orelse; |
| 1412 | p->lineno = lineno; |
| 1413 | p->col_offset = col_offset; |
| 1414 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1418 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int |
| 1419 | lineno, int col_offset, PyArena *arena) |
| 1420 | { |
| 1421 | stmt_ty p; |
| 1422 | if (!target) { |
| 1423 | PyErr_SetString(PyExc_ValueError, |
| 1424 | "field target is required for AsyncFor"); |
| 1425 | return NULL; |
| 1426 | } |
| 1427 | if (!iter) { |
| 1428 | PyErr_SetString(PyExc_ValueError, |
| 1429 | "field iter is required for AsyncFor"); |
| 1430 | return NULL; |
| 1431 | } |
| 1432 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1433 | if (!p) |
| 1434 | return NULL; |
| 1435 | p->kind = AsyncFor_kind; |
| 1436 | p->v.AsyncFor.target = target; |
| 1437 | p->v.AsyncFor.iter = iter; |
| 1438 | p->v.AsyncFor.body = body; |
| 1439 | p->v.AsyncFor.orelse = orelse; |
| 1440 | p->lineno = lineno; |
| 1441 | p->col_offset = col_offset; |
| 1442 | return p; |
| 1443 | } |
| 1444 | |
| 1445 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1446 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1447 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1448 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1449 | stmt_ty p; |
| 1450 | if (!test) { |
| 1451 | PyErr_SetString(PyExc_ValueError, |
| 1452 | "field test is required for While"); |
| 1453 | return NULL; |
| 1454 | } |
| 1455 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1456 | if (!p) |
| 1457 | return NULL; |
| 1458 | p->kind = While_kind; |
| 1459 | p->v.While.test = test; |
| 1460 | p->v.While.body = body; |
| 1461 | p->v.While.orelse = orelse; |
| 1462 | p->lineno = lineno; |
| 1463 | p->col_offset = col_offset; |
| 1464 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1468 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
| 1469 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1470 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1471 | stmt_ty p; |
| 1472 | if (!test) { |
| 1473 | PyErr_SetString(PyExc_ValueError, |
| 1474 | "field test is required for If"); |
| 1475 | return NULL; |
| 1476 | } |
| 1477 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1478 | if (!p) |
| 1479 | return NULL; |
| 1480 | p->kind = If_kind; |
| 1481 | p->v.If.test = test; |
| 1482 | p->v.If.body = body; |
| 1483 | p->v.If.orelse = orelse; |
| 1484 | p->lineno = lineno; |
| 1485 | p->col_offset = col_offset; |
| 1486 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | stmt_ty |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1490 | With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena |
| 1491 | *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1492 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1493 | stmt_ty p; |
| 1494 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1495 | if (!p) |
| 1496 | return NULL; |
| 1497 | p->kind = With_kind; |
| 1498 | p->v.With.items = items; |
| 1499 | p->v.With.body = body; |
| 1500 | p->lineno = lineno; |
| 1501 | p->col_offset = col_offset; |
| 1502 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1506 | AsyncWith(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, |
| 1507 | PyArena *arena) |
| 1508 | { |
| 1509 | stmt_ty p; |
| 1510 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1511 | if (!p) |
| 1512 | return NULL; |
| 1513 | p->kind = AsyncWith_kind; |
| 1514 | p->v.AsyncWith.items = items; |
| 1515 | p->v.AsyncWith.body = body; |
| 1516 | p->lineno = lineno; |
| 1517 | p->col_offset = col_offset; |
| 1518 | return p; |
| 1519 | } |
| 1520 | |
| 1521 | stmt_ty |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 1522 | 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] | 1523 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1524 | stmt_ty p; |
| 1525 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1526 | if (!p) |
| 1527 | return NULL; |
| 1528 | p->kind = Raise_kind; |
| 1529 | p->v.Raise.exc = exc; |
| 1530 | p->v.Raise.cause = cause; |
| 1531 | p->lineno = lineno; |
| 1532 | p->col_offset = col_offset; |
| 1533 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 1537 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
| 1538 | finalbody, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1539 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1540 | stmt_ty p; |
| 1541 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1542 | if (!p) |
| 1543 | return NULL; |
| 1544 | p->kind = Try_kind; |
| 1545 | p->v.Try.body = body; |
| 1546 | p->v.Try.handlers = handlers; |
| 1547 | p->v.Try.orelse = orelse; |
| 1548 | p->v.Try.finalbody = finalbody; |
| 1549 | p->lineno = lineno; |
| 1550 | p->col_offset = col_offset; |
| 1551 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1555 | 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] | 1556 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1557 | stmt_ty p; |
| 1558 | if (!test) { |
| 1559 | PyErr_SetString(PyExc_ValueError, |
| 1560 | "field test is required for Assert"); |
| 1561 | return NULL; |
| 1562 | } |
| 1563 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1564 | if (!p) |
| 1565 | return NULL; |
| 1566 | p->kind = Assert_kind; |
| 1567 | p->v.Assert.test = test; |
| 1568 | p->v.Assert.msg = msg; |
| 1569 | p->lineno = lineno; |
| 1570 | p->col_offset = col_offset; |
| 1571 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1575 | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1576 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1577 | stmt_ty p; |
| 1578 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1579 | if (!p) |
| 1580 | return NULL; |
| 1581 | p->kind = Import_kind; |
| 1582 | p->v.Import.names = names; |
| 1583 | p->lineno = lineno; |
| 1584 | p->col_offset = col_offset; |
| 1585 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1589 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
| 1590 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1591 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1592 | stmt_ty p; |
| 1593 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1594 | if (!p) |
| 1595 | return NULL; |
| 1596 | p->kind = ImportFrom_kind; |
| 1597 | p->v.ImportFrom.module = module; |
| 1598 | p->v.ImportFrom.names = names; |
| 1599 | p->v.ImportFrom.level = level; |
| 1600 | p->lineno = lineno; |
| 1601 | p->col_offset = col_offset; |
| 1602 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1606 | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1607 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1608 | stmt_ty p; |
| 1609 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1610 | if (!p) |
| 1611 | return NULL; |
| 1612 | p->kind = Global_kind; |
| 1613 | p->v.Global.names = names; |
| 1614 | p->lineno = lineno; |
| 1615 | p->col_offset = col_offset; |
| 1616 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | stmt_ty |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1620 | Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 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 = Nonlocal_kind; |
| 1627 | p->v.Nonlocal.names = names; |
| 1628 | p->lineno = lineno; |
| 1629 | p->col_offset = col_offset; |
| 1630 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 1631 | } |
| 1632 | |
| 1633 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1634 | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1635 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1636 | stmt_ty p; |
| 1637 | if (!value) { |
| 1638 | PyErr_SetString(PyExc_ValueError, |
| 1639 | "field value is required for Expr"); |
| 1640 | return NULL; |
| 1641 | } |
| 1642 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1643 | if (!p) |
| 1644 | return NULL; |
| 1645 | p->kind = Expr_kind; |
| 1646 | p->v.Expr.value = value; |
| 1647 | p->lineno = lineno; |
| 1648 | p->col_offset = col_offset; |
| 1649 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1653 | Pass(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1654 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1655 | stmt_ty p; |
| 1656 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1657 | if (!p) |
| 1658 | return NULL; |
| 1659 | p->kind = Pass_kind; |
| 1660 | p->lineno = lineno; |
| 1661 | p->col_offset = col_offset; |
| 1662 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1666 | Break(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1667 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1668 | stmt_ty p; |
| 1669 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1670 | if (!p) |
| 1671 | return NULL; |
| 1672 | p->kind = Break_kind; |
| 1673 | p->lineno = lineno; |
| 1674 | p->col_offset = col_offset; |
| 1675 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1679 | Continue(int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1680 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1681 | stmt_ty p; |
| 1682 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1683 | if (!p) |
| 1684 | return NULL; |
| 1685 | p->kind = Continue_kind; |
| 1686 | p->lineno = lineno; |
| 1687 | p->col_offset = col_offset; |
| 1688 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1692 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1693 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1694 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1695 | expr_ty p; |
| 1696 | if (!op) { |
| 1697 | PyErr_SetString(PyExc_ValueError, |
| 1698 | "field op is required for BoolOp"); |
| 1699 | return NULL; |
| 1700 | } |
| 1701 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1702 | if (!p) |
| 1703 | return NULL; |
| 1704 | p->kind = BoolOp_kind; |
| 1705 | p->v.BoolOp.op = op; |
| 1706 | p->v.BoolOp.values = values; |
| 1707 | p->lineno = lineno; |
| 1708 | p->col_offset = col_offset; |
| 1709 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1713 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
| 1714 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1715 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1716 | expr_ty p; |
| 1717 | if (!left) { |
| 1718 | PyErr_SetString(PyExc_ValueError, |
| 1719 | "field left is required for BinOp"); |
| 1720 | return NULL; |
| 1721 | } |
| 1722 | if (!op) { |
| 1723 | PyErr_SetString(PyExc_ValueError, |
| 1724 | "field op is required for BinOp"); |
| 1725 | return NULL; |
| 1726 | } |
| 1727 | if (!right) { |
| 1728 | PyErr_SetString(PyExc_ValueError, |
| 1729 | "field right is required for BinOp"); |
| 1730 | return NULL; |
| 1731 | } |
| 1732 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1733 | if (!p) |
| 1734 | return NULL; |
| 1735 | p->kind = BinOp_kind; |
| 1736 | p->v.BinOp.left = left; |
| 1737 | p->v.BinOp.op = op; |
| 1738 | p->v.BinOp.right = right; |
| 1739 | p->lineno = lineno; |
| 1740 | p->col_offset = col_offset; |
| 1741 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1745 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
| 1746 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1747 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1748 | expr_ty p; |
| 1749 | if (!op) { |
| 1750 | PyErr_SetString(PyExc_ValueError, |
| 1751 | "field op is required for UnaryOp"); |
| 1752 | return NULL; |
| 1753 | } |
| 1754 | if (!operand) { |
| 1755 | PyErr_SetString(PyExc_ValueError, |
| 1756 | "field operand is required for UnaryOp"); |
| 1757 | return NULL; |
| 1758 | } |
| 1759 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1760 | if (!p) |
| 1761 | return NULL; |
| 1762 | p->kind = UnaryOp_kind; |
| 1763 | p->v.UnaryOp.op = op; |
| 1764 | p->v.UnaryOp.operand = operand; |
| 1765 | p->lineno = lineno; |
| 1766 | p->col_offset = col_offset; |
| 1767 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1771 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
| 1772 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1773 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1774 | expr_ty p; |
| 1775 | if (!args) { |
| 1776 | PyErr_SetString(PyExc_ValueError, |
| 1777 | "field args is required for Lambda"); |
| 1778 | return NULL; |
| 1779 | } |
| 1780 | if (!body) { |
| 1781 | PyErr_SetString(PyExc_ValueError, |
| 1782 | "field body is required for Lambda"); |
| 1783 | return NULL; |
| 1784 | } |
| 1785 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1786 | if (!p) |
| 1787 | return NULL; |
| 1788 | p->kind = Lambda_kind; |
| 1789 | p->v.Lambda.args = args; |
| 1790 | p->v.Lambda.body = body; |
| 1791 | p->lineno = lineno; |
| 1792 | p->col_offset = col_offset; |
| 1793 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1797 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
| 1798 | PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1799 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1800 | expr_ty p; |
| 1801 | if (!test) { |
| 1802 | PyErr_SetString(PyExc_ValueError, |
| 1803 | "field test is required for IfExp"); |
| 1804 | return NULL; |
| 1805 | } |
| 1806 | if (!body) { |
| 1807 | PyErr_SetString(PyExc_ValueError, |
| 1808 | "field body is required for IfExp"); |
| 1809 | return NULL; |
| 1810 | } |
| 1811 | if (!orelse) { |
| 1812 | PyErr_SetString(PyExc_ValueError, |
| 1813 | "field orelse is required for IfExp"); |
| 1814 | return NULL; |
| 1815 | } |
| 1816 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1817 | if (!p) |
| 1818 | return NULL; |
| 1819 | p->kind = IfExp_kind; |
| 1820 | p->v.IfExp.test = test; |
| 1821 | p->v.IfExp.body = body; |
| 1822 | p->v.IfExp.orelse = orelse; |
| 1823 | p->lineno = lineno; |
| 1824 | p->col_offset = col_offset; |
| 1825 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1829 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
| 1830 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1831 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1832 | expr_ty p; |
| 1833 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1834 | if (!p) |
| 1835 | return NULL; |
| 1836 | p->kind = Dict_kind; |
| 1837 | p->v.Dict.keys = keys; |
| 1838 | p->v.Dict.values = values; |
| 1839 | p->lineno = lineno; |
| 1840 | p->col_offset = col_offset; |
| 1841 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | expr_ty |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1845 | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
| 1846 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1847 | expr_ty p; |
| 1848 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1849 | if (!p) |
| 1850 | return NULL; |
| 1851 | p->kind = Set_kind; |
| 1852 | p->v.Set.elts = elts; |
| 1853 | p->lineno = lineno; |
| 1854 | p->col_offset = col_offset; |
| 1855 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1859 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1860 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1861 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1862 | expr_ty p; |
| 1863 | if (!elt) { |
| 1864 | PyErr_SetString(PyExc_ValueError, |
| 1865 | "field elt is required for ListComp"); |
| 1866 | return NULL; |
| 1867 | } |
| 1868 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1869 | if (!p) |
| 1870 | return NULL; |
| 1871 | p->kind = ListComp_kind; |
| 1872 | p->v.ListComp.elt = elt; |
| 1873 | p->v.ListComp.generators = generators; |
| 1874 | p->lineno = lineno; |
| 1875 | p->col_offset = col_offset; |
| 1876 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1877 | } |
| 1878 | |
| 1879 | expr_ty |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1880 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
| 1881 | *arena) |
| 1882 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1883 | expr_ty p; |
| 1884 | if (!elt) { |
| 1885 | PyErr_SetString(PyExc_ValueError, |
| 1886 | "field elt is required for SetComp"); |
| 1887 | return NULL; |
| 1888 | } |
| 1889 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1890 | if (!p) |
| 1891 | return NULL; |
| 1892 | p->kind = SetComp_kind; |
| 1893 | p->v.SetComp.elt = elt; |
| 1894 | p->v.SetComp.generators = generators; |
| 1895 | p->lineno = lineno; |
| 1896 | p->col_offset = col_offset; |
| 1897 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1901 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
| 1902 | col_offset, PyArena *arena) |
| 1903 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1904 | expr_ty p; |
| 1905 | if (!key) { |
| 1906 | PyErr_SetString(PyExc_ValueError, |
| 1907 | "field key is required for DictComp"); |
| 1908 | return NULL; |
| 1909 | } |
| 1910 | if (!value) { |
| 1911 | PyErr_SetString(PyExc_ValueError, |
| 1912 | "field value is required for DictComp"); |
| 1913 | return NULL; |
| 1914 | } |
| 1915 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1916 | if (!p) |
| 1917 | return NULL; |
| 1918 | p->kind = DictComp_kind; |
| 1919 | p->v.DictComp.key = key; |
| 1920 | p->v.DictComp.value = value; |
| 1921 | p->v.DictComp.generators = generators; |
| 1922 | p->lineno = lineno; |
| 1923 | p->col_offset = col_offset; |
| 1924 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 1925 | } |
| 1926 | |
| 1927 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 1928 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1929 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1930 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1931 | expr_ty p; |
| 1932 | if (!elt) { |
| 1933 | PyErr_SetString(PyExc_ValueError, |
| 1934 | "field elt is required for GeneratorExp"); |
| 1935 | return NULL; |
| 1936 | } |
| 1937 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1938 | if (!p) |
| 1939 | return NULL; |
| 1940 | p->kind = GeneratorExp_kind; |
| 1941 | p->v.GeneratorExp.elt = elt; |
| 1942 | p->v.GeneratorExp.generators = generators; |
| 1943 | p->lineno = lineno; |
| 1944 | p->col_offset = col_offset; |
| 1945 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | expr_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1949 | Await(expr_ty value, int lineno, int col_offset, PyArena *arena) |
| 1950 | { |
| 1951 | expr_ty p; |
| 1952 | if (!value) { |
| 1953 | PyErr_SetString(PyExc_ValueError, |
| 1954 | "field value is required for Await"); |
| 1955 | return NULL; |
| 1956 | } |
| 1957 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1958 | if (!p) |
| 1959 | return NULL; |
| 1960 | p->kind = Await_kind; |
| 1961 | p->v.Await.value = value; |
| 1962 | p->lineno = lineno; |
| 1963 | p->col_offset = col_offset; |
| 1964 | return p; |
| 1965 | } |
| 1966 | |
| 1967 | expr_ty |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 1968 | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1969 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1970 | expr_ty p; |
| 1971 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1972 | if (!p) |
| 1973 | return NULL; |
| 1974 | p->kind = Yield_kind; |
| 1975 | p->v.Yield.value = value; |
| 1976 | p->lineno = lineno; |
| 1977 | p->col_offset = col_offset; |
| 1978 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | expr_ty |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 1982 | YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena) |
| 1983 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1984 | expr_ty p; |
| 1985 | if (!value) { |
| 1986 | PyErr_SetString(PyExc_ValueError, |
| 1987 | "field value is required for YieldFrom"); |
| 1988 | return NULL; |
| 1989 | } |
| 1990 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1991 | if (!p) |
| 1992 | return NULL; |
| 1993 | p->kind = YieldFrom_kind; |
| 1994 | p->v.YieldFrom.value = value; |
| 1995 | p->lineno = lineno; |
| 1996 | p->col_offset = col_offset; |
| 1997 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2001 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
| 2002 | int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2003 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2004 | expr_ty p; |
| 2005 | if (!left) { |
| 2006 | PyErr_SetString(PyExc_ValueError, |
| 2007 | "field left is required for Compare"); |
| 2008 | return NULL; |
| 2009 | } |
| 2010 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2011 | if (!p) |
| 2012 | return NULL; |
| 2013 | p->kind = Compare_kind; |
| 2014 | p->v.Compare.left = left; |
| 2015 | p->v.Compare.ops = ops; |
| 2016 | p->v.Compare.comparators = comparators; |
| 2017 | p->lineno = lineno; |
| 2018 | p->col_offset = col_offset; |
| 2019 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2023 | Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int |
| 2024 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2025 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2026 | expr_ty p; |
| 2027 | if (!func) { |
| 2028 | PyErr_SetString(PyExc_ValueError, |
| 2029 | "field func is required for Call"); |
| 2030 | return NULL; |
| 2031 | } |
| 2032 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2033 | if (!p) |
| 2034 | return NULL; |
| 2035 | p->kind = Call_kind; |
| 2036 | p->v.Call.func = func; |
| 2037 | p->v.Call.args = args; |
| 2038 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2039 | p->lineno = lineno; |
| 2040 | p->col_offset = col_offset; |
| 2041 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2045 | Num(object n, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2046 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2047 | expr_ty p; |
| 2048 | if (!n) { |
| 2049 | PyErr_SetString(PyExc_ValueError, |
| 2050 | "field n is required for Num"); |
| 2051 | return NULL; |
| 2052 | } |
| 2053 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2054 | if (!p) |
| 2055 | return NULL; |
| 2056 | p->kind = Num_kind; |
| 2057 | p->v.Num.n = n; |
| 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 |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2064 | Str(string s, int lineno, int col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2065 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2066 | expr_ty p; |
| 2067 | if (!s) { |
| 2068 | PyErr_SetString(PyExc_ValueError, |
| 2069 | "field s is required for Str"); |
| 2070 | return NULL; |
| 2071 | } |
| 2072 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2073 | if (!p) |
| 2074 | return NULL; |
| 2075 | p->kind = Str_kind; |
| 2076 | p->v.Str.s = s; |
| 2077 | p->lineno = lineno; |
| 2078 | p->col_offset = col_offset; |
| 2079 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | expr_ty |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2083 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
| 2084 | int col_offset, PyArena *arena) |
| 2085 | { |
| 2086 | expr_ty p; |
| 2087 | if (!value) { |
| 2088 | PyErr_SetString(PyExc_ValueError, |
| 2089 | "field value is required for FormattedValue"); |
| 2090 | return NULL; |
| 2091 | } |
| 2092 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2093 | if (!p) |
| 2094 | return NULL; |
| 2095 | p->kind = FormattedValue_kind; |
| 2096 | p->v.FormattedValue.value = value; |
| 2097 | p->v.FormattedValue.conversion = conversion; |
| 2098 | p->v.FormattedValue.format_spec = format_spec; |
| 2099 | p->lineno = lineno; |
| 2100 | p->col_offset = col_offset; |
| 2101 | return p; |
| 2102 | } |
| 2103 | |
| 2104 | expr_ty |
| 2105 | JoinedStr(asdl_seq * values, int lineno, int col_offset, PyArena *arena) |
| 2106 | { |
| 2107 | expr_ty p; |
| 2108 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2109 | if (!p) |
| 2110 | return NULL; |
| 2111 | p->kind = JoinedStr_kind; |
| 2112 | p->v.JoinedStr.values = values; |
| 2113 | p->lineno = lineno; |
| 2114 | p->col_offset = col_offset; |
| 2115 | return p; |
| 2116 | } |
| 2117 | |
| 2118 | expr_ty |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 2119 | Bytes(bytes s, int lineno, int col_offset, PyArena *arena) |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2120 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2121 | expr_ty p; |
| 2122 | if (!s) { |
| 2123 | PyErr_SetString(PyExc_ValueError, |
| 2124 | "field s is required for Bytes"); |
| 2125 | return NULL; |
| 2126 | } |
| 2127 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2128 | if (!p) |
| 2129 | return NULL; |
| 2130 | p->kind = Bytes_kind; |
| 2131 | p->v.Bytes.s = s; |
| 2132 | p->lineno = lineno; |
| 2133 | p->col_offset = col_offset; |
| 2134 | return p; |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | expr_ty |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 2138 | NameConstant(singleton value, int lineno, int col_offset, PyArena *arena) |
| 2139 | { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 2140 | expr_ty p; |
| 2141 | if (!value) { |
| 2142 | PyErr_SetString(PyExc_ValueError, |
| 2143 | "field value is required for NameConstant"); |
| 2144 | return NULL; |
| 2145 | } |
| 2146 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2147 | if (!p) |
| 2148 | return NULL; |
| 2149 | p->kind = NameConstant_kind; |
| 2150 | p->v.NameConstant.value = value; |
| 2151 | p->lineno = lineno; |
| 2152 | p->col_offset = col_offset; |
| 2153 | return p; |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | expr_ty |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 2157 | Ellipsis(int lineno, int col_offset, PyArena *arena) |
| 2158 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2159 | expr_ty p; |
| 2160 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2161 | if (!p) |
| 2162 | return NULL; |
| 2163 | p->kind = Ellipsis_kind; |
| 2164 | p->lineno = lineno; |
| 2165 | p->col_offset = col_offset; |
| 2166 | return p; |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 2167 | } |
| 2168 | |
| 2169 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2170 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
| 2171 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2172 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2173 | expr_ty p; |
| 2174 | if (!value) { |
| 2175 | PyErr_SetString(PyExc_ValueError, |
| 2176 | "field value is required for Attribute"); |
| 2177 | return NULL; |
| 2178 | } |
| 2179 | if (!attr) { |
| 2180 | PyErr_SetString(PyExc_ValueError, |
| 2181 | "field attr is required for Attribute"); |
| 2182 | return NULL; |
| 2183 | } |
| 2184 | if (!ctx) { |
| 2185 | PyErr_SetString(PyExc_ValueError, |
| 2186 | "field ctx is required for Attribute"); |
| 2187 | return NULL; |
| 2188 | } |
| 2189 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2190 | if (!p) |
| 2191 | return NULL; |
| 2192 | p->kind = Attribute_kind; |
| 2193 | p->v.Attribute.value = value; |
| 2194 | p->v.Attribute.attr = attr; |
| 2195 | p->v.Attribute.ctx = ctx; |
| 2196 | p->lineno = lineno; |
| 2197 | p->col_offset = col_offset; |
| 2198 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2202 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
| 2203 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2204 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2205 | expr_ty p; |
| 2206 | if (!value) { |
| 2207 | PyErr_SetString(PyExc_ValueError, |
| 2208 | "field value is required for Subscript"); |
| 2209 | return NULL; |
| 2210 | } |
| 2211 | if (!slice) { |
| 2212 | PyErr_SetString(PyExc_ValueError, |
| 2213 | "field slice is required for Subscript"); |
| 2214 | return NULL; |
| 2215 | } |
| 2216 | if (!ctx) { |
| 2217 | PyErr_SetString(PyExc_ValueError, |
| 2218 | "field ctx is required for Subscript"); |
| 2219 | return NULL; |
| 2220 | } |
| 2221 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2222 | if (!p) |
| 2223 | return NULL; |
| 2224 | p->kind = Subscript_kind; |
| 2225 | p->v.Subscript.value = value; |
| 2226 | p->v.Subscript.slice = slice; |
| 2227 | p->v.Subscript.ctx = ctx; |
| 2228 | p->lineno = lineno; |
| 2229 | p->col_offset = col_offset; |
| 2230 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2231 | } |
| 2232 | |
| 2233 | expr_ty |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2234 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2235 | *arena) |
| 2236 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2237 | expr_ty p; |
| 2238 | if (!value) { |
| 2239 | PyErr_SetString(PyExc_ValueError, |
| 2240 | "field value is required for Starred"); |
| 2241 | return NULL; |
| 2242 | } |
| 2243 | if (!ctx) { |
| 2244 | PyErr_SetString(PyExc_ValueError, |
| 2245 | "field ctx is required for Starred"); |
| 2246 | return NULL; |
| 2247 | } |
| 2248 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2249 | if (!p) |
| 2250 | return NULL; |
| 2251 | p->kind = Starred_kind; |
| 2252 | p->v.Starred.value = value; |
| 2253 | p->v.Starred.ctx = ctx; |
| 2254 | p->lineno = lineno; |
| 2255 | p->col_offset = col_offset; |
| 2256 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2260 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2261 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2262 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2263 | expr_ty p; |
| 2264 | if (!id) { |
| 2265 | PyErr_SetString(PyExc_ValueError, |
| 2266 | "field id is required for Name"); |
| 2267 | return NULL; |
| 2268 | } |
| 2269 | if (!ctx) { |
| 2270 | PyErr_SetString(PyExc_ValueError, |
| 2271 | "field ctx is required for Name"); |
| 2272 | return NULL; |
| 2273 | } |
| 2274 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2275 | if (!p) |
| 2276 | return NULL; |
| 2277 | p->kind = Name_kind; |
| 2278 | p->v.Name.id = id; |
| 2279 | p->v.Name.ctx = ctx; |
| 2280 | p->lineno = lineno; |
| 2281 | p->col_offset = col_offset; |
| 2282 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2286 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2287 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2288 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2289 | expr_ty p; |
| 2290 | if (!ctx) { |
| 2291 | PyErr_SetString(PyExc_ValueError, |
| 2292 | "field ctx is required for List"); |
| 2293 | return NULL; |
| 2294 | } |
| 2295 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2296 | if (!p) |
| 2297 | return NULL; |
| 2298 | p->kind = List_kind; |
| 2299 | p->v.List.elts = elts; |
| 2300 | p->v.List.ctx = ctx; |
| 2301 | p->lineno = lineno; |
| 2302 | p->col_offset = col_offset; |
| 2303 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2307 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
| 2308 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2309 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2310 | expr_ty p; |
| 2311 | if (!ctx) { |
| 2312 | PyErr_SetString(PyExc_ValueError, |
| 2313 | "field ctx is required for Tuple"); |
| 2314 | return NULL; |
| 2315 | } |
| 2316 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2317 | if (!p) |
| 2318 | return NULL; |
| 2319 | p->kind = Tuple_kind; |
| 2320 | p->v.Tuple.elts = elts; |
| 2321 | p->v.Tuple.ctx = ctx; |
| 2322 | p->lineno = lineno; |
| 2323 | p->col_offset = col_offset; |
| 2324 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2328 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2329 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2330 | slice_ty p; |
| 2331 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2332 | if (!p) |
| 2333 | return NULL; |
| 2334 | p->kind = Slice_kind; |
| 2335 | p->v.Slice.lower = lower; |
| 2336 | p->v.Slice.upper = upper; |
| 2337 | p->v.Slice.step = step; |
| 2338 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2339 | } |
| 2340 | |
| 2341 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2342 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2343 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2344 | slice_ty p; |
| 2345 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2346 | if (!p) |
| 2347 | return NULL; |
| 2348 | p->kind = ExtSlice_kind; |
| 2349 | p->v.ExtSlice.dims = dims; |
| 2350 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2354 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2355 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2356 | slice_ty p; |
| 2357 | if (!value) { |
| 2358 | PyErr_SetString(PyExc_ValueError, |
| 2359 | "field value is required for Index"); |
| 2360 | return NULL; |
| 2361 | } |
| 2362 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2363 | if (!p) |
| 2364 | return NULL; |
| 2365 | p->kind = Index_kind; |
| 2366 | p->v.Index.value = value; |
| 2367 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | comprehension_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2371 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2372 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2373 | comprehension_ty p; |
| 2374 | if (!target) { |
| 2375 | PyErr_SetString(PyExc_ValueError, |
| 2376 | "field target is required for comprehension"); |
| 2377 | return NULL; |
| 2378 | } |
| 2379 | if (!iter) { |
| 2380 | PyErr_SetString(PyExc_ValueError, |
| 2381 | "field iter is required for comprehension"); |
| 2382 | return NULL; |
| 2383 | } |
| 2384 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2385 | if (!p) |
| 2386 | return NULL; |
| 2387 | p->target = target; |
| 2388 | p->iter = iter; |
| 2389 | p->ifs = ifs; |
| 2390 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 2394 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2395 | col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2396 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2397 | excepthandler_ty p; |
| 2398 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2399 | if (!p) |
| 2400 | return NULL; |
| 2401 | p->kind = ExceptHandler_kind; |
| 2402 | p->v.ExceptHandler.type = type; |
| 2403 | p->v.ExceptHandler.name = name; |
| 2404 | p->v.ExceptHandler.body = body; |
| 2405 | p->lineno = lineno; |
| 2406 | p->col_offset = col_offset; |
| 2407 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | arguments_ty |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 2411 | arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq * |
| 2412 | kw_defaults, arg_ty kwarg, asdl_seq * defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2413 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2414 | arguments_ty p; |
| 2415 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2416 | if (!p) |
| 2417 | return NULL; |
| 2418 | p->args = args; |
| 2419 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2420 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2421 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 2422 | p->kwarg = kwarg; |
| 2423 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2424 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2427 | arg_ty |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame^] | 2428 | arg(identifier arg, expr_ty annotation, int lineno, int col_offset, PyArena |
| 2429 | *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2430 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2431 | arg_ty p; |
| 2432 | if (!arg) { |
| 2433 | PyErr_SetString(PyExc_ValueError, |
| 2434 | "field arg is required for arg"); |
| 2435 | return NULL; |
| 2436 | } |
| 2437 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2438 | if (!p) |
| 2439 | return NULL; |
| 2440 | p->arg = arg; |
| 2441 | p->annotation = annotation; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame^] | 2442 | p->lineno = lineno; |
| 2443 | p->col_offset = col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2444 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2445 | } |
| 2446 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2447 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2448 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2449 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2450 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2451 | if (!value) { |
| 2452 | PyErr_SetString(PyExc_ValueError, |
| 2453 | "field value is required for keyword"); |
| 2454 | return NULL; |
| 2455 | } |
| 2456 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2457 | if (!p) |
| 2458 | return NULL; |
| 2459 | p->arg = arg; |
| 2460 | p->value = value; |
| 2461 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2465 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2466 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2467 | alias_ty p; |
| 2468 | if (!name) { |
| 2469 | PyErr_SetString(PyExc_ValueError, |
| 2470 | "field name is required for alias"); |
| 2471 | return NULL; |
| 2472 | } |
| 2473 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2474 | if (!p) |
| 2475 | return NULL; |
| 2476 | p->name = name; |
| 2477 | p->asname = asname; |
| 2478 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2479 | } |
| 2480 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2481 | withitem_ty |
| 2482 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2483 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2484 | withitem_ty p; |
| 2485 | if (!context_expr) { |
| 2486 | PyErr_SetString(PyExc_ValueError, |
| 2487 | "field context_expr is required for withitem"); |
| 2488 | return NULL; |
| 2489 | } |
| 2490 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2491 | if (!p) |
| 2492 | return NULL; |
| 2493 | p->context_expr = context_expr; |
| 2494 | p->optional_vars = optional_vars; |
| 2495 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2496 | } |
| 2497 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2498 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2499 | PyObject* |
| 2500 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2501 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2502 | mod_ty o = (mod_ty)_o; |
| 2503 | PyObject *result = NULL, *value = NULL; |
| 2504 | if (!o) { |
| 2505 | Py_INCREF(Py_None); |
| 2506 | return Py_None; |
| 2507 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2508 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2509 | switch (o->kind) { |
| 2510 | case Module_kind: |
| 2511 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2512 | if (!result) goto failed; |
| 2513 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2514 | if (!value) goto failed; |
| 2515 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2516 | goto failed; |
| 2517 | Py_DECREF(value); |
| 2518 | break; |
| 2519 | case Interactive_kind: |
| 2520 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2521 | if (!result) goto failed; |
| 2522 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2523 | if (!value) goto failed; |
| 2524 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2525 | goto failed; |
| 2526 | Py_DECREF(value); |
| 2527 | break; |
| 2528 | case Expression_kind: |
| 2529 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2530 | if (!result) goto failed; |
| 2531 | value = ast2obj_expr(o->v.Expression.body); |
| 2532 | if (!value) goto failed; |
| 2533 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2534 | goto failed; |
| 2535 | Py_DECREF(value); |
| 2536 | break; |
| 2537 | case Suite_kind: |
| 2538 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2539 | if (!result) goto failed; |
| 2540 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2541 | if (!value) goto failed; |
| 2542 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2543 | goto failed; |
| 2544 | Py_DECREF(value); |
| 2545 | break; |
| 2546 | } |
| 2547 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2548 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2549 | Py_XDECREF(value); |
| 2550 | Py_XDECREF(result); |
| 2551 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2552 | } |
| 2553 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2554 | PyObject* |
| 2555 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2556 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2557 | stmt_ty o = (stmt_ty)_o; |
| 2558 | PyObject *result = NULL, *value = NULL; |
| 2559 | if (!o) { |
| 2560 | Py_INCREF(Py_None); |
| 2561 | return Py_None; |
| 2562 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2563 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2564 | switch (o->kind) { |
| 2565 | case FunctionDef_kind: |
| 2566 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2567 | if (!result) goto failed; |
| 2568 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2569 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2570 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2571 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2572 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2573 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2574 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2575 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2576 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2577 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2578 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2579 | if (!value) goto failed; |
| 2580 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2581 | goto failed; |
| 2582 | Py_DECREF(value); |
| 2583 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 2584 | if (!value) goto failed; |
| 2585 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2586 | goto failed; |
| 2587 | Py_DECREF(value); |
| 2588 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2589 | if (!value) goto failed; |
| 2590 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2591 | goto failed; |
| 2592 | Py_DECREF(value); |
| 2593 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2594 | case AsyncFunctionDef_kind: |
| 2595 | result = PyType_GenericNew(AsyncFunctionDef_type, NULL, NULL); |
| 2596 | if (!result) goto failed; |
| 2597 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 2598 | if (!value) goto failed; |
| 2599 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2600 | goto failed; |
| 2601 | Py_DECREF(value); |
| 2602 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 2603 | if (!value) goto failed; |
| 2604 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2605 | goto failed; |
| 2606 | Py_DECREF(value); |
| 2607 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 2608 | if (!value) goto failed; |
| 2609 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2610 | goto failed; |
| 2611 | Py_DECREF(value); |
| 2612 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 2613 | ast2obj_expr); |
| 2614 | if (!value) goto failed; |
| 2615 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2616 | goto failed; |
| 2617 | Py_DECREF(value); |
| 2618 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 2619 | if (!value) goto failed; |
| 2620 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2621 | goto failed; |
| 2622 | Py_DECREF(value); |
| 2623 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2624 | case ClassDef_kind: |
| 2625 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2626 | if (!result) goto failed; |
| 2627 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2628 | if (!value) goto failed; |
| 2629 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2630 | goto failed; |
| 2631 | Py_DECREF(value); |
| 2632 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2633 | if (!value) goto failed; |
| 2634 | if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) |
| 2635 | goto failed; |
| 2636 | Py_DECREF(value); |
| 2637 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2638 | if (!value) goto failed; |
| 2639 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 2640 | goto failed; |
| 2641 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2642 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2643 | if (!value) goto failed; |
| 2644 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2645 | goto failed; |
| 2646 | Py_DECREF(value); |
| 2647 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 2648 | if (!value) goto failed; |
| 2649 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2650 | goto failed; |
| 2651 | Py_DECREF(value); |
| 2652 | break; |
| 2653 | case Return_kind: |
| 2654 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2655 | if (!result) goto failed; |
| 2656 | value = ast2obj_expr(o->v.Return.value); |
| 2657 | if (!value) goto failed; |
| 2658 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2659 | goto failed; |
| 2660 | Py_DECREF(value); |
| 2661 | break; |
| 2662 | case Delete_kind: |
| 2663 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2664 | if (!result) goto failed; |
| 2665 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2666 | if (!value) goto failed; |
| 2667 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2668 | goto failed; |
| 2669 | Py_DECREF(value); |
| 2670 | break; |
| 2671 | case Assign_kind: |
| 2672 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2673 | if (!result) goto failed; |
| 2674 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2675 | if (!value) goto failed; |
| 2676 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2677 | goto failed; |
| 2678 | Py_DECREF(value); |
| 2679 | value = ast2obj_expr(o->v.Assign.value); |
| 2680 | if (!value) goto failed; |
| 2681 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2682 | goto failed; |
| 2683 | Py_DECREF(value); |
| 2684 | break; |
| 2685 | case AugAssign_kind: |
| 2686 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2687 | if (!result) goto failed; |
| 2688 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2689 | if (!value) goto failed; |
| 2690 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2691 | goto failed; |
| 2692 | Py_DECREF(value); |
| 2693 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2694 | if (!value) goto failed; |
| 2695 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2696 | goto failed; |
| 2697 | Py_DECREF(value); |
| 2698 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2699 | if (!value) goto failed; |
| 2700 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2701 | goto failed; |
| 2702 | Py_DECREF(value); |
| 2703 | break; |
| 2704 | case For_kind: |
| 2705 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2706 | if (!result) goto failed; |
| 2707 | value = ast2obj_expr(o->v.For.target); |
| 2708 | if (!value) goto failed; |
| 2709 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2710 | goto failed; |
| 2711 | Py_DECREF(value); |
| 2712 | value = ast2obj_expr(o->v.For.iter); |
| 2713 | if (!value) goto failed; |
| 2714 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2715 | goto failed; |
| 2716 | Py_DECREF(value); |
| 2717 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2718 | if (!value) goto failed; |
| 2719 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2720 | goto failed; |
| 2721 | Py_DECREF(value); |
| 2722 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2723 | if (!value) goto failed; |
| 2724 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2725 | goto failed; |
| 2726 | Py_DECREF(value); |
| 2727 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2728 | case AsyncFor_kind: |
| 2729 | result = PyType_GenericNew(AsyncFor_type, NULL, NULL); |
| 2730 | if (!result) goto failed; |
| 2731 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 2732 | if (!value) goto failed; |
| 2733 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2734 | goto failed; |
| 2735 | Py_DECREF(value); |
| 2736 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 2737 | if (!value) goto failed; |
| 2738 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2739 | goto failed; |
| 2740 | Py_DECREF(value); |
| 2741 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 2742 | if (!value) goto failed; |
| 2743 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2744 | goto failed; |
| 2745 | Py_DECREF(value); |
| 2746 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 2747 | if (!value) goto failed; |
| 2748 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2749 | goto failed; |
| 2750 | Py_DECREF(value); |
| 2751 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2752 | case While_kind: |
| 2753 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2754 | if (!result) goto failed; |
| 2755 | value = ast2obj_expr(o->v.While.test); |
| 2756 | if (!value) goto failed; |
| 2757 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2758 | goto failed; |
| 2759 | Py_DECREF(value); |
| 2760 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2761 | if (!value) goto failed; |
| 2762 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2763 | goto failed; |
| 2764 | Py_DECREF(value); |
| 2765 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2766 | if (!value) goto failed; |
| 2767 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2768 | goto failed; |
| 2769 | Py_DECREF(value); |
| 2770 | break; |
| 2771 | case If_kind: |
| 2772 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2773 | if (!result) goto failed; |
| 2774 | value = ast2obj_expr(o->v.If.test); |
| 2775 | if (!value) goto failed; |
| 2776 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2777 | goto failed; |
| 2778 | Py_DECREF(value); |
| 2779 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2780 | if (!value) goto failed; |
| 2781 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2782 | goto failed; |
| 2783 | Py_DECREF(value); |
| 2784 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2785 | if (!value) goto failed; |
| 2786 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2787 | goto failed; |
| 2788 | Py_DECREF(value); |
| 2789 | break; |
| 2790 | case With_kind: |
| 2791 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2792 | if (!result) goto failed; |
| 2793 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 2794 | if (!value) goto failed; |
| 2795 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 2796 | goto failed; |
| 2797 | Py_DECREF(value); |
| 2798 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2799 | if (!value) goto failed; |
| 2800 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2801 | goto failed; |
| 2802 | Py_DECREF(value); |
| 2803 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2804 | case AsyncWith_kind: |
| 2805 | result = PyType_GenericNew(AsyncWith_type, NULL, NULL); |
| 2806 | if (!result) goto failed; |
| 2807 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 2808 | if (!value) goto failed; |
| 2809 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 2810 | goto failed; |
| 2811 | Py_DECREF(value); |
| 2812 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 2813 | if (!value) goto failed; |
| 2814 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2815 | goto failed; |
| 2816 | Py_DECREF(value); |
| 2817 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2818 | case Raise_kind: |
| 2819 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2820 | if (!result) goto failed; |
| 2821 | value = ast2obj_expr(o->v.Raise.exc); |
| 2822 | if (!value) goto failed; |
| 2823 | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
| 2824 | goto failed; |
| 2825 | Py_DECREF(value); |
| 2826 | value = ast2obj_expr(o->v.Raise.cause); |
| 2827 | if (!value) goto failed; |
| 2828 | if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) |
| 2829 | goto failed; |
| 2830 | Py_DECREF(value); |
| 2831 | break; |
| 2832 | case Try_kind: |
| 2833 | result = PyType_GenericNew(Try_type, NULL, NULL); |
| 2834 | if (!result) goto failed; |
| 2835 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 2836 | if (!value) goto failed; |
| 2837 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2838 | goto failed; |
| 2839 | Py_DECREF(value); |
| 2840 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 2841 | if (!value) goto failed; |
| 2842 | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
| 2843 | goto failed; |
| 2844 | Py_DECREF(value); |
| 2845 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 2846 | if (!value) goto failed; |
| 2847 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2848 | goto failed; |
| 2849 | Py_DECREF(value); |
| 2850 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 2851 | if (!value) goto failed; |
| 2852 | if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) |
| 2853 | goto failed; |
| 2854 | Py_DECREF(value); |
| 2855 | break; |
| 2856 | case Assert_kind: |
| 2857 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2858 | if (!result) goto failed; |
| 2859 | value = ast2obj_expr(o->v.Assert.test); |
| 2860 | if (!value) goto failed; |
| 2861 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2862 | goto failed; |
| 2863 | Py_DECREF(value); |
| 2864 | value = ast2obj_expr(o->v.Assert.msg); |
| 2865 | if (!value) goto failed; |
| 2866 | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
| 2867 | goto failed; |
| 2868 | Py_DECREF(value); |
| 2869 | break; |
| 2870 | case Import_kind: |
| 2871 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2872 | if (!result) goto failed; |
| 2873 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2874 | if (!value) goto failed; |
| 2875 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2876 | goto failed; |
| 2877 | Py_DECREF(value); |
| 2878 | break; |
| 2879 | case ImportFrom_kind: |
| 2880 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2881 | if (!result) goto failed; |
| 2882 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2883 | if (!value) goto failed; |
| 2884 | if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) |
| 2885 | goto failed; |
| 2886 | Py_DECREF(value); |
| 2887 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2888 | if (!value) goto failed; |
| 2889 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2890 | goto failed; |
| 2891 | Py_DECREF(value); |
| 2892 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2893 | if (!value) goto failed; |
| 2894 | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
| 2895 | goto failed; |
| 2896 | Py_DECREF(value); |
| 2897 | break; |
| 2898 | case Global_kind: |
| 2899 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2900 | if (!result) goto failed; |
| 2901 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2902 | if (!value) goto failed; |
| 2903 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2904 | goto failed; |
| 2905 | Py_DECREF(value); |
| 2906 | break; |
| 2907 | case Nonlocal_kind: |
| 2908 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 2909 | if (!result) goto failed; |
| 2910 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 2911 | if (!value) goto failed; |
| 2912 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2913 | goto failed; |
| 2914 | Py_DECREF(value); |
| 2915 | break; |
| 2916 | case Expr_kind: |
| 2917 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2918 | if (!result) goto failed; |
| 2919 | value = ast2obj_expr(o->v.Expr.value); |
| 2920 | if (!value) goto failed; |
| 2921 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2922 | goto failed; |
| 2923 | Py_DECREF(value); |
| 2924 | break; |
| 2925 | case Pass_kind: |
| 2926 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2927 | if (!result) goto failed; |
| 2928 | break; |
| 2929 | case Break_kind: |
| 2930 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2931 | if (!result) goto failed; |
| 2932 | break; |
| 2933 | case Continue_kind: |
| 2934 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2935 | if (!result) goto failed; |
| 2936 | break; |
| 2937 | } |
| 2938 | value = ast2obj_int(o->lineno); |
| 2939 | if (!value) goto failed; |
| 2940 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 2941 | goto failed; |
| 2942 | Py_DECREF(value); |
| 2943 | value = ast2obj_int(o->col_offset); |
| 2944 | if (!value) goto failed; |
| 2945 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 2946 | goto failed; |
| 2947 | Py_DECREF(value); |
| 2948 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2949 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2950 | Py_XDECREF(value); |
| 2951 | Py_XDECREF(result); |
| 2952 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2953 | } |
| 2954 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2955 | PyObject* |
| 2956 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2957 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2958 | expr_ty o = (expr_ty)_o; |
| 2959 | PyObject *result = NULL, *value = NULL; |
| 2960 | if (!o) { |
| 2961 | Py_INCREF(Py_None); |
| 2962 | return Py_None; |
| 2963 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2964 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2965 | switch (o->kind) { |
| 2966 | case BoolOp_kind: |
| 2967 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2968 | if (!result) goto failed; |
| 2969 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2970 | if (!value) goto failed; |
| 2971 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2972 | goto failed; |
| 2973 | Py_DECREF(value); |
| 2974 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2975 | if (!value) goto failed; |
| 2976 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 2977 | goto failed; |
| 2978 | Py_DECREF(value); |
| 2979 | break; |
| 2980 | case BinOp_kind: |
| 2981 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2982 | if (!result) goto failed; |
| 2983 | value = ast2obj_expr(o->v.BinOp.left); |
| 2984 | if (!value) goto failed; |
| 2985 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 2986 | goto failed; |
| 2987 | Py_DECREF(value); |
| 2988 | value = ast2obj_operator(o->v.BinOp.op); |
| 2989 | if (!value) goto failed; |
| 2990 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2991 | goto failed; |
| 2992 | Py_DECREF(value); |
| 2993 | value = ast2obj_expr(o->v.BinOp.right); |
| 2994 | if (!value) goto failed; |
| 2995 | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
| 2996 | goto failed; |
| 2997 | Py_DECREF(value); |
| 2998 | break; |
| 2999 | case UnaryOp_kind: |
| 3000 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 3001 | if (!result) goto failed; |
| 3002 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 3003 | if (!value) goto failed; |
| 3004 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3005 | goto failed; |
| 3006 | Py_DECREF(value); |
| 3007 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 3008 | if (!value) goto failed; |
| 3009 | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
| 3010 | goto failed; |
| 3011 | Py_DECREF(value); |
| 3012 | break; |
| 3013 | case Lambda_kind: |
| 3014 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 3015 | if (!result) goto failed; |
| 3016 | value = ast2obj_arguments(o->v.Lambda.args); |
| 3017 | if (!value) goto failed; |
| 3018 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3019 | goto failed; |
| 3020 | Py_DECREF(value); |
| 3021 | value = ast2obj_expr(o->v.Lambda.body); |
| 3022 | if (!value) goto failed; |
| 3023 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3024 | goto failed; |
| 3025 | Py_DECREF(value); |
| 3026 | break; |
| 3027 | case IfExp_kind: |
| 3028 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 3029 | if (!result) goto failed; |
| 3030 | value = ast2obj_expr(o->v.IfExp.test); |
| 3031 | if (!value) goto failed; |
| 3032 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3033 | goto failed; |
| 3034 | Py_DECREF(value); |
| 3035 | value = ast2obj_expr(o->v.IfExp.body); |
| 3036 | if (!value) goto failed; |
| 3037 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3038 | goto failed; |
| 3039 | Py_DECREF(value); |
| 3040 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 3041 | if (!value) goto failed; |
| 3042 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3043 | goto failed; |
| 3044 | Py_DECREF(value); |
| 3045 | break; |
| 3046 | case Dict_kind: |
| 3047 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 3048 | if (!result) goto failed; |
| 3049 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 3050 | if (!value) goto failed; |
| 3051 | if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) |
| 3052 | goto failed; |
| 3053 | Py_DECREF(value); |
| 3054 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 3055 | if (!value) goto failed; |
| 3056 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3057 | goto failed; |
| 3058 | Py_DECREF(value); |
| 3059 | break; |
| 3060 | case Set_kind: |
| 3061 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 3062 | if (!result) goto failed; |
| 3063 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 3064 | if (!value) goto failed; |
| 3065 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3066 | goto failed; |
| 3067 | Py_DECREF(value); |
| 3068 | break; |
| 3069 | case ListComp_kind: |
| 3070 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 3071 | if (!result) goto failed; |
| 3072 | value = ast2obj_expr(o->v.ListComp.elt); |
| 3073 | if (!value) goto failed; |
| 3074 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3075 | goto failed; |
| 3076 | Py_DECREF(value); |
| 3077 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 3078 | if (!value) goto failed; |
| 3079 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3080 | goto failed; |
| 3081 | Py_DECREF(value); |
| 3082 | break; |
| 3083 | case SetComp_kind: |
| 3084 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 3085 | if (!result) goto failed; |
| 3086 | value = ast2obj_expr(o->v.SetComp.elt); |
| 3087 | if (!value) goto failed; |
| 3088 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3089 | goto failed; |
| 3090 | Py_DECREF(value); |
| 3091 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 3092 | if (!value) goto failed; |
| 3093 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3094 | goto failed; |
| 3095 | Py_DECREF(value); |
| 3096 | break; |
| 3097 | case DictComp_kind: |
| 3098 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 3099 | if (!result) goto failed; |
| 3100 | value = ast2obj_expr(o->v.DictComp.key); |
| 3101 | if (!value) goto failed; |
| 3102 | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
| 3103 | goto failed; |
| 3104 | Py_DECREF(value); |
| 3105 | value = ast2obj_expr(o->v.DictComp.value); |
| 3106 | if (!value) goto failed; |
| 3107 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3108 | goto failed; |
| 3109 | Py_DECREF(value); |
| 3110 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 3111 | if (!value) goto failed; |
| 3112 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3113 | goto failed; |
| 3114 | Py_DECREF(value); |
| 3115 | break; |
| 3116 | case GeneratorExp_kind: |
| 3117 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 3118 | if (!result) goto failed; |
| 3119 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 3120 | if (!value) goto failed; |
| 3121 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3122 | goto failed; |
| 3123 | Py_DECREF(value); |
| 3124 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 3125 | ast2obj_comprehension); |
| 3126 | if (!value) goto failed; |
| 3127 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3128 | goto failed; |
| 3129 | Py_DECREF(value); |
| 3130 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3131 | case Await_kind: |
| 3132 | result = PyType_GenericNew(Await_type, NULL, NULL); |
| 3133 | if (!result) goto failed; |
| 3134 | value = ast2obj_expr(o->v.Await.value); |
| 3135 | if (!value) goto failed; |
| 3136 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3137 | goto failed; |
| 3138 | Py_DECREF(value); |
| 3139 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3140 | case Yield_kind: |
| 3141 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 3142 | if (!result) goto failed; |
| 3143 | value = ast2obj_expr(o->v.Yield.value); |
| 3144 | if (!value) goto failed; |
| 3145 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3146 | goto failed; |
| 3147 | Py_DECREF(value); |
| 3148 | break; |
| 3149 | case YieldFrom_kind: |
| 3150 | result = PyType_GenericNew(YieldFrom_type, NULL, NULL); |
| 3151 | if (!result) goto failed; |
| 3152 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 3153 | if (!value) goto failed; |
| 3154 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3155 | goto failed; |
| 3156 | Py_DECREF(value); |
| 3157 | break; |
| 3158 | case Compare_kind: |
| 3159 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 3160 | if (!result) goto failed; |
| 3161 | value = ast2obj_expr(o->v.Compare.left); |
| 3162 | if (!value) goto failed; |
| 3163 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3164 | goto failed; |
| 3165 | Py_DECREF(value); |
| 3166 | { |
| 3167 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 3168 | value = PyList_New(n); |
| 3169 | if (!value) goto failed; |
| 3170 | for(i = 0; i < n; i++) |
| 3171 | 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] | 3172 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3173 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3174 | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
| 3175 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3176 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3177 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3178 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3179 | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
| 3180 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3181 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3182 | break; |
| 3183 | case Call_kind: |
| 3184 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 3185 | if (!result) goto failed; |
| 3186 | value = ast2obj_expr(o->v.Call.func); |
| 3187 | if (!value) goto failed; |
| 3188 | if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) |
| 3189 | goto failed; |
| 3190 | Py_DECREF(value); |
| 3191 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 3192 | if (!value) goto failed; |
| 3193 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3194 | goto failed; |
| 3195 | Py_DECREF(value); |
| 3196 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 3197 | if (!value) goto failed; |
| 3198 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 3199 | goto failed; |
| 3200 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3201 | break; |
| 3202 | case Num_kind: |
| 3203 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 3204 | if (!result) goto failed; |
| 3205 | value = ast2obj_object(o->v.Num.n); |
| 3206 | if (!value) goto failed; |
| 3207 | if (_PyObject_SetAttrId(result, &PyId_n, value) == -1) |
| 3208 | goto failed; |
| 3209 | Py_DECREF(value); |
| 3210 | break; |
| 3211 | case Str_kind: |
| 3212 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 3213 | if (!result) goto failed; |
| 3214 | value = ast2obj_string(o->v.Str.s); |
| 3215 | if (!value) goto failed; |
| 3216 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
| 3217 | goto failed; |
| 3218 | Py_DECREF(value); |
| 3219 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3220 | case FormattedValue_kind: |
| 3221 | result = PyType_GenericNew(FormattedValue_type, NULL, NULL); |
| 3222 | if (!result) goto failed; |
| 3223 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 3224 | if (!value) goto failed; |
| 3225 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3226 | goto failed; |
| 3227 | Py_DECREF(value); |
| 3228 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 3229 | if (!value) goto failed; |
| 3230 | if (_PyObject_SetAttrId(result, &PyId_conversion, value) == -1) |
| 3231 | goto failed; |
| 3232 | Py_DECREF(value); |
| 3233 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 3234 | if (!value) goto failed; |
| 3235 | if (_PyObject_SetAttrId(result, &PyId_format_spec, value) == -1) |
| 3236 | goto failed; |
| 3237 | Py_DECREF(value); |
| 3238 | break; |
| 3239 | case JoinedStr_kind: |
| 3240 | result = PyType_GenericNew(JoinedStr_type, NULL, NULL); |
| 3241 | if (!result) goto failed; |
| 3242 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 3243 | if (!value) goto failed; |
| 3244 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3245 | goto failed; |
| 3246 | Py_DECREF(value); |
| 3247 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3248 | case Bytes_kind: |
| 3249 | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
| 3250 | if (!result) goto failed; |
| 3251 | value = ast2obj_bytes(o->v.Bytes.s); |
| 3252 | if (!value) goto failed; |
| 3253 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
| 3254 | goto failed; |
| 3255 | Py_DECREF(value); |
| 3256 | break; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3257 | case NameConstant_kind: |
| 3258 | result = PyType_GenericNew(NameConstant_type, NULL, NULL); |
| 3259 | if (!result) goto failed; |
| 3260 | value = ast2obj_singleton(o->v.NameConstant.value); |
| 3261 | if (!value) goto failed; |
| 3262 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3263 | goto failed; |
| 3264 | Py_DECREF(value); |
| 3265 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3266 | case Ellipsis_kind: |
| 3267 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 3268 | if (!result) goto failed; |
| 3269 | break; |
| 3270 | case Attribute_kind: |
| 3271 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 3272 | if (!result) goto failed; |
| 3273 | value = ast2obj_expr(o->v.Attribute.value); |
| 3274 | if (!value) goto failed; |
| 3275 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3276 | goto failed; |
| 3277 | Py_DECREF(value); |
| 3278 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 3279 | if (!value) goto failed; |
| 3280 | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
| 3281 | goto failed; |
| 3282 | Py_DECREF(value); |
| 3283 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 3284 | if (!value) goto failed; |
| 3285 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3286 | goto failed; |
| 3287 | Py_DECREF(value); |
| 3288 | break; |
| 3289 | case Subscript_kind: |
| 3290 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 3291 | if (!result) goto failed; |
| 3292 | value = ast2obj_expr(o->v.Subscript.value); |
| 3293 | if (!value) goto failed; |
| 3294 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3295 | goto failed; |
| 3296 | Py_DECREF(value); |
| 3297 | value = ast2obj_slice(o->v.Subscript.slice); |
| 3298 | if (!value) goto failed; |
| 3299 | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
| 3300 | goto failed; |
| 3301 | Py_DECREF(value); |
| 3302 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 3303 | if (!value) goto failed; |
| 3304 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3305 | goto failed; |
| 3306 | Py_DECREF(value); |
| 3307 | break; |
| 3308 | case Starred_kind: |
| 3309 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 3310 | if (!result) goto failed; |
| 3311 | value = ast2obj_expr(o->v.Starred.value); |
| 3312 | if (!value) goto failed; |
| 3313 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3314 | goto failed; |
| 3315 | Py_DECREF(value); |
| 3316 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 3317 | if (!value) goto failed; |
| 3318 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3319 | goto failed; |
| 3320 | Py_DECREF(value); |
| 3321 | break; |
| 3322 | case Name_kind: |
| 3323 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 3324 | if (!result) goto failed; |
| 3325 | value = ast2obj_identifier(o->v.Name.id); |
| 3326 | if (!value) goto failed; |
| 3327 | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
| 3328 | goto failed; |
| 3329 | Py_DECREF(value); |
| 3330 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 3331 | if (!value) goto failed; |
| 3332 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3333 | goto failed; |
| 3334 | Py_DECREF(value); |
| 3335 | break; |
| 3336 | case List_kind: |
| 3337 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 3338 | if (!result) goto failed; |
| 3339 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 3340 | if (!value) goto failed; |
| 3341 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3342 | goto failed; |
| 3343 | Py_DECREF(value); |
| 3344 | value = ast2obj_expr_context(o->v.List.ctx); |
| 3345 | if (!value) goto failed; |
| 3346 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3347 | goto failed; |
| 3348 | Py_DECREF(value); |
| 3349 | break; |
| 3350 | case Tuple_kind: |
| 3351 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 3352 | if (!result) goto failed; |
| 3353 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 3354 | if (!value) goto failed; |
| 3355 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3356 | goto failed; |
| 3357 | Py_DECREF(value); |
| 3358 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 3359 | if (!value) goto failed; |
| 3360 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3361 | goto failed; |
| 3362 | Py_DECREF(value); |
| 3363 | break; |
| 3364 | } |
| 3365 | value = ast2obj_int(o->lineno); |
| 3366 | if (!value) goto failed; |
| 3367 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3368 | goto failed; |
| 3369 | Py_DECREF(value); |
| 3370 | value = ast2obj_int(o->col_offset); |
| 3371 | if (!value) goto failed; |
| 3372 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3373 | goto failed; |
| 3374 | Py_DECREF(value); |
| 3375 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3376 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3377 | Py_XDECREF(value); |
| 3378 | Py_XDECREF(result); |
| 3379 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3380 | } |
| 3381 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3382 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3383 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3384 | switch(o) { |
| 3385 | case Load: |
| 3386 | Py_INCREF(Load_singleton); |
| 3387 | return Load_singleton; |
| 3388 | case Store: |
| 3389 | Py_INCREF(Store_singleton); |
| 3390 | return Store_singleton; |
| 3391 | case Del: |
| 3392 | Py_INCREF(Del_singleton); |
| 3393 | return Del_singleton; |
| 3394 | case AugLoad: |
| 3395 | Py_INCREF(AugLoad_singleton); |
| 3396 | return AugLoad_singleton; |
| 3397 | case AugStore: |
| 3398 | Py_INCREF(AugStore_singleton); |
| 3399 | return AugStore_singleton; |
| 3400 | case Param: |
| 3401 | Py_INCREF(Param_singleton); |
| 3402 | return Param_singleton; |
| 3403 | default: |
| 3404 | /* should never happen, but just in case ... */ |
| 3405 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 3406 | return NULL; |
| 3407 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3408 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3409 | PyObject* |
| 3410 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3411 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3412 | slice_ty o = (slice_ty)_o; |
| 3413 | PyObject *result = NULL, *value = NULL; |
| 3414 | if (!o) { |
| 3415 | Py_INCREF(Py_None); |
| 3416 | return Py_None; |
| 3417 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3418 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3419 | switch (o->kind) { |
| 3420 | case Slice_kind: |
| 3421 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 3422 | if (!result) goto failed; |
| 3423 | value = ast2obj_expr(o->v.Slice.lower); |
| 3424 | if (!value) goto failed; |
| 3425 | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
| 3426 | goto failed; |
| 3427 | Py_DECREF(value); |
| 3428 | value = ast2obj_expr(o->v.Slice.upper); |
| 3429 | if (!value) goto failed; |
| 3430 | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
| 3431 | goto failed; |
| 3432 | Py_DECREF(value); |
| 3433 | value = ast2obj_expr(o->v.Slice.step); |
| 3434 | if (!value) goto failed; |
| 3435 | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
| 3436 | goto failed; |
| 3437 | Py_DECREF(value); |
| 3438 | break; |
| 3439 | case ExtSlice_kind: |
| 3440 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3441 | if (!result) goto failed; |
| 3442 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3443 | if (!value) goto failed; |
| 3444 | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
| 3445 | goto failed; |
| 3446 | Py_DECREF(value); |
| 3447 | break; |
| 3448 | case Index_kind: |
| 3449 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3450 | if (!result) goto failed; |
| 3451 | value = ast2obj_expr(o->v.Index.value); |
| 3452 | if (!value) goto failed; |
| 3453 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3454 | goto failed; |
| 3455 | Py_DECREF(value); |
| 3456 | break; |
| 3457 | } |
| 3458 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3459 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3460 | Py_XDECREF(value); |
| 3461 | Py_XDECREF(result); |
| 3462 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3463 | } |
| 3464 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3465 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3466 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3467 | switch(o) { |
| 3468 | case And: |
| 3469 | Py_INCREF(And_singleton); |
| 3470 | return And_singleton; |
| 3471 | case Or: |
| 3472 | Py_INCREF(Or_singleton); |
| 3473 | return Or_singleton; |
| 3474 | default: |
| 3475 | /* should never happen, but just in case ... */ |
| 3476 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3477 | return NULL; |
| 3478 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3479 | } |
| 3480 | PyObject* ast2obj_operator(operator_ty o) |
| 3481 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3482 | switch(o) { |
| 3483 | case Add: |
| 3484 | Py_INCREF(Add_singleton); |
| 3485 | return Add_singleton; |
| 3486 | case Sub: |
| 3487 | Py_INCREF(Sub_singleton); |
| 3488 | return Sub_singleton; |
| 3489 | case Mult: |
| 3490 | Py_INCREF(Mult_singleton); |
| 3491 | return Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 3492 | case MatMult: |
| 3493 | Py_INCREF(MatMult_singleton); |
| 3494 | return MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3495 | case Div: |
| 3496 | Py_INCREF(Div_singleton); |
| 3497 | return Div_singleton; |
| 3498 | case Mod: |
| 3499 | Py_INCREF(Mod_singleton); |
| 3500 | return Mod_singleton; |
| 3501 | case Pow: |
| 3502 | Py_INCREF(Pow_singleton); |
| 3503 | return Pow_singleton; |
| 3504 | case LShift: |
| 3505 | Py_INCREF(LShift_singleton); |
| 3506 | return LShift_singleton; |
| 3507 | case RShift: |
| 3508 | Py_INCREF(RShift_singleton); |
| 3509 | return RShift_singleton; |
| 3510 | case BitOr: |
| 3511 | Py_INCREF(BitOr_singleton); |
| 3512 | return BitOr_singleton; |
| 3513 | case BitXor: |
| 3514 | Py_INCREF(BitXor_singleton); |
| 3515 | return BitXor_singleton; |
| 3516 | case BitAnd: |
| 3517 | Py_INCREF(BitAnd_singleton); |
| 3518 | return BitAnd_singleton; |
| 3519 | case FloorDiv: |
| 3520 | Py_INCREF(FloorDiv_singleton); |
| 3521 | return FloorDiv_singleton; |
| 3522 | default: |
| 3523 | /* should never happen, but just in case ... */ |
| 3524 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3525 | return NULL; |
| 3526 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3527 | } |
| 3528 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3529 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3530 | switch(o) { |
| 3531 | case Invert: |
| 3532 | Py_INCREF(Invert_singleton); |
| 3533 | return Invert_singleton; |
| 3534 | case Not: |
| 3535 | Py_INCREF(Not_singleton); |
| 3536 | return Not_singleton; |
| 3537 | case UAdd: |
| 3538 | Py_INCREF(UAdd_singleton); |
| 3539 | return UAdd_singleton; |
| 3540 | case USub: |
| 3541 | Py_INCREF(USub_singleton); |
| 3542 | return USub_singleton; |
| 3543 | default: |
| 3544 | /* should never happen, but just in case ... */ |
| 3545 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3546 | return NULL; |
| 3547 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3548 | } |
| 3549 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3550 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3551 | switch(o) { |
| 3552 | case Eq: |
| 3553 | Py_INCREF(Eq_singleton); |
| 3554 | return Eq_singleton; |
| 3555 | case NotEq: |
| 3556 | Py_INCREF(NotEq_singleton); |
| 3557 | return NotEq_singleton; |
| 3558 | case Lt: |
| 3559 | Py_INCREF(Lt_singleton); |
| 3560 | return Lt_singleton; |
| 3561 | case LtE: |
| 3562 | Py_INCREF(LtE_singleton); |
| 3563 | return LtE_singleton; |
| 3564 | case Gt: |
| 3565 | Py_INCREF(Gt_singleton); |
| 3566 | return Gt_singleton; |
| 3567 | case GtE: |
| 3568 | Py_INCREF(GtE_singleton); |
| 3569 | return GtE_singleton; |
| 3570 | case Is: |
| 3571 | Py_INCREF(Is_singleton); |
| 3572 | return Is_singleton; |
| 3573 | case IsNot: |
| 3574 | Py_INCREF(IsNot_singleton); |
| 3575 | return IsNot_singleton; |
| 3576 | case In: |
| 3577 | Py_INCREF(In_singleton); |
| 3578 | return In_singleton; |
| 3579 | case NotIn: |
| 3580 | Py_INCREF(NotIn_singleton); |
| 3581 | return NotIn_singleton; |
| 3582 | default: |
| 3583 | /* should never happen, but just in case ... */ |
| 3584 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3585 | return NULL; |
| 3586 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3587 | } |
| 3588 | PyObject* |
| 3589 | ast2obj_comprehension(void* _o) |
| 3590 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3591 | comprehension_ty o = (comprehension_ty)_o; |
| 3592 | PyObject *result = NULL, *value = NULL; |
| 3593 | if (!o) { |
| 3594 | Py_INCREF(Py_None); |
| 3595 | return Py_None; |
| 3596 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3597 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3598 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3599 | if (!result) return NULL; |
| 3600 | value = ast2obj_expr(o->target); |
| 3601 | if (!value) goto failed; |
| 3602 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 3603 | goto failed; |
| 3604 | Py_DECREF(value); |
| 3605 | value = ast2obj_expr(o->iter); |
| 3606 | if (!value) goto failed; |
| 3607 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 3608 | goto failed; |
| 3609 | Py_DECREF(value); |
| 3610 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3611 | if (!value) goto failed; |
| 3612 | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
| 3613 | goto failed; |
| 3614 | Py_DECREF(value); |
| 3615 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3616 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3617 | Py_XDECREF(value); |
| 3618 | Py_XDECREF(result); |
| 3619 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3620 | } |
| 3621 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3622 | PyObject* |
| 3623 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3624 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3625 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3626 | PyObject *result = NULL, *value = NULL; |
| 3627 | if (!o) { |
| 3628 | Py_INCREF(Py_None); |
| 3629 | return Py_None; |
| 3630 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3631 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3632 | switch (o->kind) { |
| 3633 | case ExceptHandler_kind: |
| 3634 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3635 | if (!result) goto failed; |
| 3636 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3637 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3638 | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
| 3639 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3640 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3641 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3642 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3643 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3644 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3645 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3646 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3647 | if (!value) goto failed; |
| 3648 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3649 | goto failed; |
| 3650 | Py_DECREF(value); |
| 3651 | break; |
| 3652 | } |
| 3653 | value = ast2obj_int(o->lineno); |
| 3654 | if (!value) goto failed; |
| 3655 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3656 | goto failed; |
| 3657 | Py_DECREF(value); |
| 3658 | value = ast2obj_int(o->col_offset); |
| 3659 | if (!value) goto failed; |
| 3660 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3661 | goto failed; |
| 3662 | Py_DECREF(value); |
| 3663 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3664 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3665 | Py_XDECREF(value); |
| 3666 | Py_XDECREF(result); |
| 3667 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3668 | } |
| 3669 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3670 | PyObject* |
| 3671 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3672 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3673 | arguments_ty o = (arguments_ty)_o; |
| 3674 | PyObject *result = NULL, *value = NULL; |
| 3675 | if (!o) { |
| 3676 | Py_INCREF(Py_None); |
| 3677 | return Py_None; |
| 3678 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3679 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3680 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3681 | if (!result) return NULL; |
| 3682 | value = ast2obj_list(o->args, ast2obj_arg); |
| 3683 | if (!value) goto failed; |
| 3684 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3685 | goto failed; |
| 3686 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3687 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3688 | if (!value) goto failed; |
| 3689 | if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) |
| 3690 | goto failed; |
| 3691 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3692 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 3693 | if (!value) goto failed; |
| 3694 | if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) |
| 3695 | goto failed; |
| 3696 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3697 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3698 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3699 | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3700 | goto failed; |
| 3701 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3702 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3703 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3704 | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3705 | goto failed; |
| 3706 | Py_DECREF(value); |
| 3707 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3708 | if (!value) goto failed; |
| 3709 | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
| 3710 | goto failed; |
| 3711 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3712 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3713 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3714 | Py_XDECREF(value); |
| 3715 | Py_XDECREF(result); |
| 3716 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3717 | } |
| 3718 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3719 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3720 | ast2obj_arg(void* _o) |
| 3721 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3722 | arg_ty o = (arg_ty)_o; |
| 3723 | PyObject *result = NULL, *value = NULL; |
| 3724 | if (!o) { |
| 3725 | Py_INCREF(Py_None); |
| 3726 | return Py_None; |
| 3727 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3728 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3729 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3730 | if (!result) return NULL; |
| 3731 | value = ast2obj_identifier(o->arg); |
| 3732 | if (!value) goto failed; |
| 3733 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 3734 | goto failed; |
| 3735 | Py_DECREF(value); |
| 3736 | value = ast2obj_expr(o->annotation); |
| 3737 | if (!value) goto failed; |
| 3738 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 3739 | goto failed; |
| 3740 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3741 | value = ast2obj_int(o->lineno); |
| 3742 | if (!value) goto failed; |
| 3743 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3744 | goto failed; |
| 3745 | Py_DECREF(value); |
| 3746 | value = ast2obj_int(o->col_offset); |
| 3747 | if (!value) goto failed; |
| 3748 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3749 | goto failed; |
| 3750 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3751 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3752 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3753 | Py_XDECREF(value); |
| 3754 | Py_XDECREF(result); |
| 3755 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3756 | } |
| 3757 | |
| 3758 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3759 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3760 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3761 | keyword_ty o = (keyword_ty)_o; |
| 3762 | PyObject *result = NULL, *value = NULL; |
| 3763 | if (!o) { |
| 3764 | Py_INCREF(Py_None); |
| 3765 | return Py_None; |
| 3766 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3767 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3768 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3769 | if (!result) return NULL; |
| 3770 | value = ast2obj_identifier(o->arg); |
| 3771 | if (!value) goto failed; |
| 3772 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 3773 | goto failed; |
| 3774 | Py_DECREF(value); |
| 3775 | value = ast2obj_expr(o->value); |
| 3776 | if (!value) goto failed; |
| 3777 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3778 | goto failed; |
| 3779 | Py_DECREF(value); |
| 3780 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3781 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3782 | Py_XDECREF(value); |
| 3783 | Py_XDECREF(result); |
| 3784 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3785 | } |
| 3786 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3787 | PyObject* |
| 3788 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3789 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3790 | alias_ty o = (alias_ty)_o; |
| 3791 | PyObject *result = NULL, *value = NULL; |
| 3792 | if (!o) { |
| 3793 | Py_INCREF(Py_None); |
| 3794 | return Py_None; |
| 3795 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3796 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3797 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3798 | if (!result) return NULL; |
| 3799 | value = ast2obj_identifier(o->name); |
| 3800 | if (!value) goto failed; |
| 3801 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3802 | goto failed; |
| 3803 | Py_DECREF(value); |
| 3804 | value = ast2obj_identifier(o->asname); |
| 3805 | if (!value) goto failed; |
| 3806 | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
| 3807 | goto failed; |
| 3808 | Py_DECREF(value); |
| 3809 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3810 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3811 | Py_XDECREF(value); |
| 3812 | Py_XDECREF(result); |
| 3813 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3814 | } |
| 3815 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3816 | PyObject* |
| 3817 | ast2obj_withitem(void* _o) |
| 3818 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3819 | withitem_ty o = (withitem_ty)_o; |
| 3820 | PyObject *result = NULL, *value = NULL; |
| 3821 | if (!o) { |
| 3822 | Py_INCREF(Py_None); |
| 3823 | return Py_None; |
| 3824 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3825 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3826 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 3827 | if (!result) return NULL; |
| 3828 | value = ast2obj_expr(o->context_expr); |
| 3829 | if (!value) goto failed; |
| 3830 | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
| 3831 | goto failed; |
| 3832 | Py_DECREF(value); |
| 3833 | value = ast2obj_expr(o->optional_vars); |
| 3834 | if (!value) goto failed; |
| 3835 | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
| 3836 | goto failed; |
| 3837 | Py_DECREF(value); |
| 3838 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3839 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3840 | Py_XDECREF(value); |
| 3841 | Py_XDECREF(result); |
| 3842 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3843 | } |
| 3844 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3845 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3846 | int |
| 3847 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3848 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3849 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3850 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3851 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3852 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3853 | if (obj == Py_None) { |
| 3854 | *out = NULL; |
| 3855 | return 0; |
| 3856 | } |
| 3857 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3858 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3859 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3860 | } |
| 3861 | if (isinstance) { |
| 3862 | asdl_seq* body; |
| 3863 | |
| 3864 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3865 | int res; |
| 3866 | Py_ssize_t len; |
| 3867 | Py_ssize_t i; |
| 3868 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 3869 | if (tmp == NULL) goto failed; |
| 3870 | if (!PyList_Check(tmp)) { |
| 3871 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3872 | goto failed; |
| 3873 | } |
| 3874 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3875 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3876 | if (body == NULL) goto failed; |
| 3877 | for (i = 0; i < len; i++) { |
| 3878 | stmt_ty value; |
| 3879 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3880 | if (res != 0) goto failed; |
| 3881 | asdl_seq_SET(body, i, value); |
| 3882 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3883 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3884 | } else { |
| 3885 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3886 | return 1; |
| 3887 | } |
| 3888 | *out = Module(body, arena); |
| 3889 | if (*out == NULL) goto failed; |
| 3890 | return 0; |
| 3891 | } |
| 3892 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 3893 | if (isinstance == -1) { |
| 3894 | return 1; |
| 3895 | } |
| 3896 | if (isinstance) { |
| 3897 | asdl_seq* body; |
| 3898 | |
| 3899 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3900 | int res; |
| 3901 | Py_ssize_t len; |
| 3902 | Py_ssize_t i; |
| 3903 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 3904 | if (tmp == NULL) goto failed; |
| 3905 | if (!PyList_Check(tmp)) { |
| 3906 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3907 | goto failed; |
| 3908 | } |
| 3909 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3910 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3911 | if (body == NULL) goto failed; |
| 3912 | for (i = 0; i < len; i++) { |
| 3913 | stmt_ty value; |
| 3914 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3915 | if (res != 0) goto failed; |
| 3916 | asdl_seq_SET(body, i, value); |
| 3917 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3918 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3919 | } else { |
| 3920 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3921 | return 1; |
| 3922 | } |
| 3923 | *out = Interactive(body, arena); |
| 3924 | if (*out == NULL) goto failed; |
| 3925 | return 0; |
| 3926 | } |
| 3927 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 3928 | if (isinstance == -1) { |
| 3929 | return 1; |
| 3930 | } |
| 3931 | if (isinstance) { |
| 3932 | expr_ty body; |
| 3933 | |
| 3934 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3935 | int res; |
| 3936 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 3937 | if (tmp == NULL) goto failed; |
| 3938 | res = obj2ast_expr(tmp, &body, arena); |
| 3939 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3940 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3941 | } else { |
| 3942 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3943 | return 1; |
| 3944 | } |
| 3945 | *out = Expression(body, arena); |
| 3946 | if (*out == NULL) goto failed; |
| 3947 | return 0; |
| 3948 | } |
| 3949 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 3950 | if (isinstance == -1) { |
| 3951 | return 1; |
| 3952 | } |
| 3953 | if (isinstance) { |
| 3954 | asdl_seq* body; |
| 3955 | |
| 3956 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3957 | int res; |
| 3958 | Py_ssize_t len; |
| 3959 | Py_ssize_t i; |
| 3960 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 3961 | if (tmp == NULL) goto failed; |
| 3962 | if (!PyList_Check(tmp)) { |
| 3963 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3964 | goto failed; |
| 3965 | } |
| 3966 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3967 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3968 | if (body == NULL) goto failed; |
| 3969 | for (i = 0; i < len; i++) { |
| 3970 | stmt_ty value; |
| 3971 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3972 | if (res != 0) goto failed; |
| 3973 | asdl_seq_SET(body, i, value); |
| 3974 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3975 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3976 | } else { |
| 3977 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 3978 | return 1; |
| 3979 | } |
| 3980 | *out = Suite(body, arena); |
| 3981 | if (*out == NULL) goto failed; |
| 3982 | return 0; |
| 3983 | } |
| 3984 | |
| 3985 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 3986 | failed: |
| 3987 | Py_XDECREF(tmp); |
| 3988 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3989 | } |
| 3990 | |
| 3991 | int |
| 3992 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3993 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3994 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3995 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3996 | PyObject *tmp = NULL; |
| 3997 | int lineno; |
| 3998 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3999 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4000 | if (obj == Py_None) { |
| 4001 | *out = NULL; |
| 4002 | return 0; |
| 4003 | } |
| 4004 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
| 4005 | int res; |
| 4006 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 4007 | if (tmp == NULL) goto failed; |
| 4008 | res = obj2ast_int(tmp, &lineno, arena); |
| 4009 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4010 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4011 | } else { |
| 4012 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4013 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4014 | } |
| 4015 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
| 4016 | int res; |
| 4017 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 4018 | if (tmp == NULL) goto failed; |
| 4019 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4020 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4021 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4022 | } else { |
| 4023 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 4024 | return 1; |
| 4025 | } |
| 4026 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 4027 | if (isinstance == -1) { |
| 4028 | return 1; |
| 4029 | } |
| 4030 | if (isinstance) { |
| 4031 | identifier name; |
| 4032 | arguments_ty args; |
| 4033 | asdl_seq* body; |
| 4034 | asdl_seq* decorator_list; |
| 4035 | expr_ty returns; |
| 4036 | |
| 4037 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
| 4038 | int res; |
| 4039 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 4040 | if (tmp == NULL) goto failed; |
| 4041 | res = obj2ast_identifier(tmp, &name, arena); |
| 4042 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4043 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4044 | } else { |
| 4045 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 4046 | return 1; |
| 4047 | } |
| 4048 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 4049 | int res; |
| 4050 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 4051 | if (tmp == NULL) goto failed; |
| 4052 | res = obj2ast_arguments(tmp, &args, arena); |
| 4053 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4054 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4055 | } else { |
| 4056 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 4057 | return 1; |
| 4058 | } |
| 4059 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4060 | int res; |
| 4061 | Py_ssize_t len; |
| 4062 | Py_ssize_t i; |
| 4063 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4064 | if (tmp == NULL) goto failed; |
| 4065 | if (!PyList_Check(tmp)) { |
| 4066 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4067 | goto failed; |
| 4068 | } |
| 4069 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4070 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4071 | if (body == NULL) goto failed; |
| 4072 | for (i = 0; i < len; i++) { |
| 4073 | stmt_ty value; |
| 4074 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4075 | if (res != 0) goto failed; |
| 4076 | asdl_seq_SET(body, i, value); |
| 4077 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4078 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4079 | } else { |
| 4080 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 4081 | return 1; |
| 4082 | } |
| 4083 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
| 4084 | int res; |
| 4085 | Py_ssize_t len; |
| 4086 | Py_ssize_t i; |
| 4087 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
| 4088 | if (tmp == NULL) goto failed; |
| 4089 | if (!PyList_Check(tmp)) { |
| 4090 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4091 | goto failed; |
| 4092 | } |
| 4093 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4094 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4095 | if (decorator_list == NULL) goto failed; |
| 4096 | for (i = 0; i < len; i++) { |
| 4097 | expr_ty value; |
| 4098 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4099 | if (res != 0) goto failed; |
| 4100 | asdl_seq_SET(decorator_list, i, value); |
| 4101 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4102 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4103 | } else { |
| 4104 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 4105 | return 1; |
| 4106 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4107 | if (exists_not_none(obj, &PyId_returns)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4108 | int res; |
| 4109 | tmp = _PyObject_GetAttrId(obj, &PyId_returns); |
| 4110 | if (tmp == NULL) goto failed; |
| 4111 | res = obj2ast_expr(tmp, &returns, arena); |
| 4112 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4113 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4114 | } else { |
| 4115 | returns = NULL; |
| 4116 | } |
| 4117 | *out = FunctionDef(name, args, body, decorator_list, returns, lineno, |
| 4118 | col_offset, arena); |
| 4119 | if (*out == NULL) goto failed; |
| 4120 | return 0; |
| 4121 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4122 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFunctionDef_type); |
| 4123 | if (isinstance == -1) { |
| 4124 | return 1; |
| 4125 | } |
| 4126 | if (isinstance) { |
| 4127 | identifier name; |
| 4128 | arguments_ty args; |
| 4129 | asdl_seq* body; |
| 4130 | asdl_seq* decorator_list; |
| 4131 | expr_ty returns; |
| 4132 | |
| 4133 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
| 4134 | int res; |
| 4135 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 4136 | if (tmp == NULL) goto failed; |
| 4137 | res = obj2ast_identifier(tmp, &name, arena); |
| 4138 | if (res != 0) goto failed; |
| 4139 | Py_CLEAR(tmp); |
| 4140 | } else { |
| 4141 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 4142 | return 1; |
| 4143 | } |
| 4144 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 4145 | int res; |
| 4146 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 4147 | if (tmp == NULL) goto failed; |
| 4148 | res = obj2ast_arguments(tmp, &args, arena); |
| 4149 | if (res != 0) goto failed; |
| 4150 | Py_CLEAR(tmp); |
| 4151 | } else { |
| 4152 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 4153 | return 1; |
| 4154 | } |
| 4155 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4156 | int res; |
| 4157 | Py_ssize_t len; |
| 4158 | Py_ssize_t i; |
| 4159 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4160 | if (tmp == NULL) goto failed; |
| 4161 | if (!PyList_Check(tmp)) { |
| 4162 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4163 | goto failed; |
| 4164 | } |
| 4165 | len = PyList_GET_SIZE(tmp); |
| 4166 | body = _Py_asdl_seq_new(len, arena); |
| 4167 | if (body == NULL) goto failed; |
| 4168 | for (i = 0; i < len; i++) { |
| 4169 | stmt_ty value; |
| 4170 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4171 | if (res != 0) goto failed; |
| 4172 | asdl_seq_SET(body, i, value); |
| 4173 | } |
| 4174 | Py_CLEAR(tmp); |
| 4175 | } else { |
| 4176 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 4177 | return 1; |
| 4178 | } |
| 4179 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
| 4180 | int res; |
| 4181 | Py_ssize_t len; |
| 4182 | Py_ssize_t i; |
| 4183 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
| 4184 | if (tmp == NULL) goto failed; |
| 4185 | if (!PyList_Check(tmp)) { |
| 4186 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4187 | goto failed; |
| 4188 | } |
| 4189 | len = PyList_GET_SIZE(tmp); |
| 4190 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 4191 | if (decorator_list == NULL) goto failed; |
| 4192 | for (i = 0; i < len; i++) { |
| 4193 | expr_ty value; |
| 4194 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4195 | if (res != 0) goto failed; |
| 4196 | asdl_seq_SET(decorator_list, i, value); |
| 4197 | } |
| 4198 | Py_CLEAR(tmp); |
| 4199 | } else { |
| 4200 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 4201 | return 1; |
| 4202 | } |
| 4203 | if (exists_not_none(obj, &PyId_returns)) { |
| 4204 | int res; |
| 4205 | tmp = _PyObject_GetAttrId(obj, &PyId_returns); |
| 4206 | if (tmp == NULL) goto failed; |
| 4207 | res = obj2ast_expr(tmp, &returns, arena); |
| 4208 | if (res != 0) goto failed; |
| 4209 | Py_CLEAR(tmp); |
| 4210 | } else { |
| 4211 | returns = NULL; |
| 4212 | } |
| 4213 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
| 4214 | lineno, col_offset, arena); |
| 4215 | if (*out == NULL) goto failed; |
| 4216 | return 0; |
| 4217 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4218 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 4219 | if (isinstance == -1) { |
| 4220 | return 1; |
| 4221 | } |
| 4222 | if (isinstance) { |
| 4223 | identifier name; |
| 4224 | asdl_seq* bases; |
| 4225 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4226 | asdl_seq* body; |
| 4227 | asdl_seq* decorator_list; |
| 4228 | |
| 4229 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
| 4230 | int res; |
| 4231 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 4232 | if (tmp == NULL) goto failed; |
| 4233 | res = obj2ast_identifier(tmp, &name, 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 { |
| 4237 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 4238 | return 1; |
| 4239 | } |
| 4240 | if (_PyObject_HasAttrId(obj, &PyId_bases)) { |
| 4241 | int res; |
| 4242 | Py_ssize_t len; |
| 4243 | Py_ssize_t i; |
| 4244 | tmp = _PyObject_GetAttrId(obj, &PyId_bases); |
| 4245 | if (tmp == NULL) goto failed; |
| 4246 | if (!PyList_Check(tmp)) { |
| 4247 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4248 | goto failed; |
| 4249 | } |
| 4250 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4251 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4252 | if (bases == NULL) goto failed; |
| 4253 | for (i = 0; i < len; i++) { |
| 4254 | expr_ty value; |
| 4255 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4256 | if (res != 0) goto failed; |
| 4257 | asdl_seq_SET(bases, i, value); |
| 4258 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4259 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4260 | } else { |
| 4261 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 4262 | return 1; |
| 4263 | } |
| 4264 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
| 4265 | int res; |
| 4266 | Py_ssize_t len; |
| 4267 | Py_ssize_t i; |
| 4268 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
| 4269 | if (tmp == NULL) goto failed; |
| 4270 | if (!PyList_Check(tmp)) { |
| 4271 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4272 | goto failed; |
| 4273 | } |
| 4274 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4275 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4276 | if (keywords == NULL) goto failed; |
| 4277 | for (i = 0; i < len; i++) { |
| 4278 | keyword_ty value; |
| 4279 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4280 | if (res != 0) goto failed; |
| 4281 | asdl_seq_SET(keywords, i, value); |
| 4282 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4283 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4284 | } else { |
| 4285 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 4286 | return 1; |
| 4287 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4288 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4289 | int res; |
| 4290 | Py_ssize_t len; |
| 4291 | Py_ssize_t i; |
| 4292 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4293 | if (tmp == NULL) goto failed; |
| 4294 | if (!PyList_Check(tmp)) { |
| 4295 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4296 | goto failed; |
| 4297 | } |
| 4298 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4299 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4300 | if (body == NULL) goto failed; |
| 4301 | for (i = 0; i < len; i++) { |
| 4302 | stmt_ty value; |
| 4303 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4304 | if (res != 0) goto failed; |
| 4305 | asdl_seq_SET(body, i, value); |
| 4306 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4307 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4308 | } else { |
| 4309 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 4310 | return 1; |
| 4311 | } |
| 4312 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
| 4313 | int res; |
| 4314 | Py_ssize_t len; |
| 4315 | Py_ssize_t i; |
| 4316 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
| 4317 | if (tmp == NULL) goto failed; |
| 4318 | if (!PyList_Check(tmp)) { |
| 4319 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4320 | goto failed; |
| 4321 | } |
| 4322 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4323 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4324 | if (decorator_list == NULL) goto failed; |
| 4325 | for (i = 0; i < len; i++) { |
| 4326 | expr_ty value; |
| 4327 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4328 | if (res != 0) goto failed; |
| 4329 | asdl_seq_SET(decorator_list, i, value); |
| 4330 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4331 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4332 | } else { |
| 4333 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 4334 | return 1; |
| 4335 | } |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 4336 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
| 4337 | col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4338 | if (*out == NULL) goto failed; |
| 4339 | return 0; |
| 4340 | } |
| 4341 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 4342 | if (isinstance == -1) { |
| 4343 | return 1; |
| 4344 | } |
| 4345 | if (isinstance) { |
| 4346 | expr_ty value; |
| 4347 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4348 | if (exists_not_none(obj, &PyId_value)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4349 | int res; |
| 4350 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 4351 | if (tmp == NULL) goto failed; |
| 4352 | res = obj2ast_expr(tmp, &value, arena); |
| 4353 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4354 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4355 | } else { |
| 4356 | value = NULL; |
| 4357 | } |
| 4358 | *out = Return(value, lineno, col_offset, arena); |
| 4359 | if (*out == NULL) goto failed; |
| 4360 | return 0; |
| 4361 | } |
| 4362 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 4363 | if (isinstance == -1) { |
| 4364 | return 1; |
| 4365 | } |
| 4366 | if (isinstance) { |
| 4367 | asdl_seq* targets; |
| 4368 | |
| 4369 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
| 4370 | int res; |
| 4371 | Py_ssize_t len; |
| 4372 | Py_ssize_t i; |
| 4373 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
| 4374 | if (tmp == NULL) goto failed; |
| 4375 | if (!PyList_Check(tmp)) { |
| 4376 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4377 | goto failed; |
| 4378 | } |
| 4379 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4380 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4381 | if (targets == NULL) goto failed; |
| 4382 | for (i = 0; i < len; i++) { |
| 4383 | expr_ty value; |
| 4384 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4385 | if (res != 0) goto failed; |
| 4386 | asdl_seq_SET(targets, i, value); |
| 4387 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4388 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4389 | } else { |
| 4390 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 4391 | return 1; |
| 4392 | } |
| 4393 | *out = Delete(targets, lineno, col_offset, arena); |
| 4394 | if (*out == NULL) goto failed; |
| 4395 | return 0; |
| 4396 | } |
| 4397 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 4398 | if (isinstance == -1) { |
| 4399 | return 1; |
| 4400 | } |
| 4401 | if (isinstance) { |
| 4402 | asdl_seq* targets; |
| 4403 | expr_ty value; |
| 4404 | |
| 4405 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
| 4406 | int res; |
| 4407 | Py_ssize_t len; |
| 4408 | Py_ssize_t i; |
| 4409 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
| 4410 | if (tmp == NULL) goto failed; |
| 4411 | if (!PyList_Check(tmp)) { |
| 4412 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4413 | goto failed; |
| 4414 | } |
| 4415 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4416 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4417 | if (targets == NULL) goto failed; |
| 4418 | for (i = 0; i < len; i++) { |
| 4419 | expr_ty value; |
| 4420 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4421 | if (res != 0) goto failed; |
| 4422 | asdl_seq_SET(targets, i, value); |
| 4423 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4424 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4425 | } else { |
| 4426 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 4427 | return 1; |
| 4428 | } |
| 4429 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 4430 | int res; |
| 4431 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 4432 | if (tmp == NULL) goto failed; |
| 4433 | res = obj2ast_expr(tmp, &value, arena); |
| 4434 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4435 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4436 | } else { |
| 4437 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 4438 | return 1; |
| 4439 | } |
| 4440 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 4441 | if (*out == NULL) goto failed; |
| 4442 | return 0; |
| 4443 | } |
| 4444 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 4445 | if (isinstance == -1) { |
| 4446 | return 1; |
| 4447 | } |
| 4448 | if (isinstance) { |
| 4449 | expr_ty target; |
| 4450 | operator_ty op; |
| 4451 | expr_ty value; |
| 4452 | |
| 4453 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
| 4454 | int res; |
| 4455 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 4456 | if (tmp == NULL) goto failed; |
| 4457 | res = obj2ast_expr(tmp, &target, arena); |
| 4458 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4459 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4460 | } else { |
| 4461 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 4462 | return 1; |
| 4463 | } |
| 4464 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
| 4465 | int res; |
| 4466 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 4467 | if (tmp == NULL) goto failed; |
| 4468 | res = obj2ast_operator(tmp, &op, arena); |
| 4469 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4470 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4471 | } else { |
| 4472 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 4473 | return 1; |
| 4474 | } |
| 4475 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 4476 | int res; |
| 4477 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 4478 | if (tmp == NULL) goto failed; |
| 4479 | res = obj2ast_expr(tmp, &value, arena); |
| 4480 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4481 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4482 | } else { |
| 4483 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 4484 | return 1; |
| 4485 | } |
| 4486 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 4487 | if (*out == NULL) goto failed; |
| 4488 | return 0; |
| 4489 | } |
| 4490 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 4491 | if (isinstance == -1) { |
| 4492 | return 1; |
| 4493 | } |
| 4494 | if (isinstance) { |
| 4495 | expr_ty target; |
| 4496 | expr_ty iter; |
| 4497 | asdl_seq* body; |
| 4498 | asdl_seq* orelse; |
| 4499 | |
| 4500 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
| 4501 | int res; |
| 4502 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 4503 | if (tmp == NULL) goto failed; |
| 4504 | res = obj2ast_expr(tmp, &target, arena); |
| 4505 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4506 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4507 | } else { |
| 4508 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 4509 | return 1; |
| 4510 | } |
| 4511 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
| 4512 | int res; |
| 4513 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
| 4514 | if (tmp == NULL) goto failed; |
| 4515 | res = obj2ast_expr(tmp, &iter, arena); |
| 4516 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4517 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4518 | } else { |
| 4519 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 4520 | return 1; |
| 4521 | } |
| 4522 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4523 | int res; |
| 4524 | Py_ssize_t len; |
| 4525 | Py_ssize_t i; |
| 4526 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4527 | if (tmp == NULL) goto failed; |
| 4528 | if (!PyList_Check(tmp)) { |
| 4529 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4530 | goto failed; |
| 4531 | } |
| 4532 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4533 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4534 | if (body == NULL) goto failed; |
| 4535 | for (i = 0; i < len; i++) { |
| 4536 | stmt_ty value; |
| 4537 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4538 | if (res != 0) goto failed; |
| 4539 | asdl_seq_SET(body, i, value); |
| 4540 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4541 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4542 | } else { |
| 4543 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 4544 | return 1; |
| 4545 | } |
| 4546 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 4547 | int res; |
| 4548 | Py_ssize_t len; |
| 4549 | Py_ssize_t i; |
| 4550 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4551 | if (tmp == NULL) goto failed; |
| 4552 | if (!PyList_Check(tmp)) { |
| 4553 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4554 | goto failed; |
| 4555 | } |
| 4556 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4557 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4558 | if (orelse == NULL) goto failed; |
| 4559 | for (i = 0; i < len; i++) { |
| 4560 | stmt_ty value; |
| 4561 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4562 | if (res != 0) goto failed; |
| 4563 | asdl_seq_SET(orelse, i, value); |
| 4564 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4565 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4566 | } else { |
| 4567 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 4568 | return 1; |
| 4569 | } |
| 4570 | *out = For(target, iter, body, orelse, lineno, col_offset, arena); |
| 4571 | if (*out == NULL) goto failed; |
| 4572 | return 0; |
| 4573 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4574 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFor_type); |
| 4575 | if (isinstance == -1) { |
| 4576 | return 1; |
| 4577 | } |
| 4578 | if (isinstance) { |
| 4579 | expr_ty target; |
| 4580 | expr_ty iter; |
| 4581 | asdl_seq* body; |
| 4582 | asdl_seq* orelse; |
| 4583 | |
| 4584 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
| 4585 | int res; |
| 4586 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 4587 | if (tmp == NULL) goto failed; |
| 4588 | res = obj2ast_expr(tmp, &target, arena); |
| 4589 | if (res != 0) goto failed; |
| 4590 | Py_CLEAR(tmp); |
| 4591 | } else { |
| 4592 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 4593 | return 1; |
| 4594 | } |
| 4595 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
| 4596 | int res; |
| 4597 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
| 4598 | if (tmp == NULL) goto failed; |
| 4599 | res = obj2ast_expr(tmp, &iter, arena); |
| 4600 | if (res != 0) goto failed; |
| 4601 | Py_CLEAR(tmp); |
| 4602 | } else { |
| 4603 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 4604 | return 1; |
| 4605 | } |
| 4606 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4607 | int res; |
| 4608 | Py_ssize_t len; |
| 4609 | Py_ssize_t i; |
| 4610 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4611 | if (tmp == NULL) goto failed; |
| 4612 | if (!PyList_Check(tmp)) { |
| 4613 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4614 | goto failed; |
| 4615 | } |
| 4616 | len = PyList_GET_SIZE(tmp); |
| 4617 | body = _Py_asdl_seq_new(len, arena); |
| 4618 | if (body == NULL) goto failed; |
| 4619 | for (i = 0; i < len; i++) { |
| 4620 | stmt_ty value; |
| 4621 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4622 | if (res != 0) goto failed; |
| 4623 | asdl_seq_SET(body, i, value); |
| 4624 | } |
| 4625 | Py_CLEAR(tmp); |
| 4626 | } else { |
| 4627 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 4628 | return 1; |
| 4629 | } |
| 4630 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 4631 | int res; |
| 4632 | Py_ssize_t len; |
| 4633 | Py_ssize_t i; |
| 4634 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4635 | if (tmp == NULL) goto failed; |
| 4636 | if (!PyList_Check(tmp)) { |
| 4637 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4638 | goto failed; |
| 4639 | } |
| 4640 | len = PyList_GET_SIZE(tmp); |
| 4641 | orelse = _Py_asdl_seq_new(len, arena); |
| 4642 | if (orelse == NULL) goto failed; |
| 4643 | for (i = 0; i < len; i++) { |
| 4644 | stmt_ty value; |
| 4645 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4646 | if (res != 0) goto failed; |
| 4647 | asdl_seq_SET(orelse, i, value); |
| 4648 | } |
| 4649 | Py_CLEAR(tmp); |
| 4650 | } else { |
| 4651 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 4652 | return 1; |
| 4653 | } |
| 4654 | *out = AsyncFor(target, iter, body, orelse, lineno, col_offset, arena); |
| 4655 | if (*out == NULL) goto failed; |
| 4656 | return 0; |
| 4657 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4658 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 4659 | if (isinstance == -1) { |
| 4660 | return 1; |
| 4661 | } |
| 4662 | if (isinstance) { |
| 4663 | expr_ty test; |
| 4664 | asdl_seq* body; |
| 4665 | asdl_seq* orelse; |
| 4666 | |
| 4667 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
| 4668 | int res; |
| 4669 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 4670 | if (tmp == NULL) goto failed; |
| 4671 | res = obj2ast_expr(tmp, &test, arena); |
| 4672 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4673 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4674 | } else { |
| 4675 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 4676 | return 1; |
| 4677 | } |
| 4678 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4679 | int res; |
| 4680 | Py_ssize_t len; |
| 4681 | Py_ssize_t i; |
| 4682 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4683 | if (tmp == NULL) goto failed; |
| 4684 | if (!PyList_Check(tmp)) { |
| 4685 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4686 | goto failed; |
| 4687 | } |
| 4688 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4689 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4690 | if (body == NULL) goto failed; |
| 4691 | for (i = 0; i < len; i++) { |
| 4692 | stmt_ty value; |
| 4693 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4694 | if (res != 0) goto failed; |
| 4695 | asdl_seq_SET(body, i, value); |
| 4696 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4697 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4698 | } else { |
| 4699 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 4700 | return 1; |
| 4701 | } |
| 4702 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 4703 | int res; |
| 4704 | Py_ssize_t len; |
| 4705 | Py_ssize_t i; |
| 4706 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4707 | if (tmp == NULL) goto failed; |
| 4708 | if (!PyList_Check(tmp)) { |
| 4709 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4710 | goto failed; |
| 4711 | } |
| 4712 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4713 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4714 | if (orelse == NULL) goto failed; |
| 4715 | for (i = 0; i < len; i++) { |
| 4716 | stmt_ty value; |
| 4717 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4718 | if (res != 0) goto failed; |
| 4719 | asdl_seq_SET(orelse, i, value); |
| 4720 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4721 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4722 | } else { |
| 4723 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 4724 | return 1; |
| 4725 | } |
| 4726 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 4727 | if (*out == NULL) goto failed; |
| 4728 | return 0; |
| 4729 | } |
| 4730 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 4731 | if (isinstance == -1) { |
| 4732 | return 1; |
| 4733 | } |
| 4734 | if (isinstance) { |
| 4735 | expr_ty test; |
| 4736 | asdl_seq* body; |
| 4737 | asdl_seq* orelse; |
| 4738 | |
| 4739 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
| 4740 | int res; |
| 4741 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 4742 | if (tmp == NULL) goto failed; |
| 4743 | res = obj2ast_expr(tmp, &test, 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 { |
| 4747 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 4748 | return 1; |
| 4749 | } |
| 4750 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4751 | int res; |
| 4752 | Py_ssize_t len; |
| 4753 | Py_ssize_t i; |
| 4754 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4755 | if (tmp == NULL) goto failed; |
| 4756 | if (!PyList_Check(tmp)) { |
| 4757 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4758 | goto failed; |
| 4759 | } |
| 4760 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4761 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4762 | if (body == NULL) goto failed; |
| 4763 | for (i = 0; i < len; i++) { |
| 4764 | stmt_ty value; |
| 4765 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4766 | if (res != 0) goto failed; |
| 4767 | asdl_seq_SET(body, i, value); |
| 4768 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4769 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4770 | } else { |
| 4771 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 4772 | return 1; |
| 4773 | } |
| 4774 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 4775 | int res; |
| 4776 | Py_ssize_t len; |
| 4777 | Py_ssize_t i; |
| 4778 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4779 | if (tmp == NULL) goto failed; |
| 4780 | if (!PyList_Check(tmp)) { |
| 4781 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4782 | goto failed; |
| 4783 | } |
| 4784 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4785 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4786 | if (orelse == NULL) goto failed; |
| 4787 | for (i = 0; i < len; i++) { |
| 4788 | stmt_ty value; |
| 4789 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4790 | if (res != 0) goto failed; |
| 4791 | asdl_seq_SET(orelse, i, value); |
| 4792 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4793 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4794 | } else { |
| 4795 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4796 | return 1; |
| 4797 | } |
| 4798 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4799 | if (*out == NULL) goto failed; |
| 4800 | return 0; |
| 4801 | } |
| 4802 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 4803 | if (isinstance == -1) { |
| 4804 | return 1; |
| 4805 | } |
| 4806 | if (isinstance) { |
| 4807 | asdl_seq* items; |
| 4808 | asdl_seq* body; |
| 4809 | |
| 4810 | if (_PyObject_HasAttrId(obj, &PyId_items)) { |
| 4811 | int res; |
| 4812 | Py_ssize_t len; |
| 4813 | Py_ssize_t i; |
| 4814 | tmp = _PyObject_GetAttrId(obj, &PyId_items); |
| 4815 | if (tmp == NULL) goto failed; |
| 4816 | if (!PyList_Check(tmp)) { |
| 4817 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4818 | goto failed; |
| 4819 | } |
| 4820 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4821 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4822 | if (items == NULL) goto failed; |
| 4823 | for (i = 0; i < len; i++) { |
| 4824 | withitem_ty value; |
| 4825 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4826 | if (res != 0) goto failed; |
| 4827 | asdl_seq_SET(items, i, value); |
| 4828 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4829 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4830 | } else { |
| 4831 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 4832 | return 1; |
| 4833 | } |
| 4834 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4835 | int res; |
| 4836 | Py_ssize_t len; |
| 4837 | Py_ssize_t i; |
| 4838 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4839 | if (tmp == NULL) goto failed; |
| 4840 | if (!PyList_Check(tmp)) { |
| 4841 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4842 | goto failed; |
| 4843 | } |
| 4844 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4845 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4846 | if (body == NULL) goto failed; |
| 4847 | for (i = 0; i < len; i++) { |
| 4848 | stmt_ty value; |
| 4849 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4850 | if (res != 0) goto failed; |
| 4851 | asdl_seq_SET(body, i, value); |
| 4852 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4853 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4854 | } else { |
| 4855 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4856 | return 1; |
| 4857 | } |
| 4858 | *out = With(items, body, lineno, col_offset, arena); |
| 4859 | if (*out == NULL) goto failed; |
| 4860 | return 0; |
| 4861 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4862 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncWith_type); |
| 4863 | if (isinstance == -1) { |
| 4864 | return 1; |
| 4865 | } |
| 4866 | if (isinstance) { |
| 4867 | asdl_seq* items; |
| 4868 | asdl_seq* body; |
| 4869 | |
| 4870 | if (_PyObject_HasAttrId(obj, &PyId_items)) { |
| 4871 | int res; |
| 4872 | Py_ssize_t len; |
| 4873 | Py_ssize_t i; |
| 4874 | tmp = _PyObject_GetAttrId(obj, &PyId_items); |
| 4875 | if (tmp == NULL) goto failed; |
| 4876 | if (!PyList_Check(tmp)) { |
| 4877 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4878 | goto failed; |
| 4879 | } |
| 4880 | len = PyList_GET_SIZE(tmp); |
| 4881 | items = _Py_asdl_seq_new(len, arena); |
| 4882 | if (items == NULL) goto failed; |
| 4883 | for (i = 0; i < len; i++) { |
| 4884 | withitem_ty value; |
| 4885 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4886 | if (res != 0) goto failed; |
| 4887 | asdl_seq_SET(items, i, value); |
| 4888 | } |
| 4889 | Py_CLEAR(tmp); |
| 4890 | } else { |
| 4891 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 4892 | return 1; |
| 4893 | } |
| 4894 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4895 | int res; |
| 4896 | Py_ssize_t len; |
| 4897 | Py_ssize_t i; |
| 4898 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4899 | if (tmp == NULL) goto failed; |
| 4900 | if (!PyList_Check(tmp)) { |
| 4901 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4902 | goto failed; |
| 4903 | } |
| 4904 | len = PyList_GET_SIZE(tmp); |
| 4905 | body = _Py_asdl_seq_new(len, arena); |
| 4906 | if (body == NULL) goto failed; |
| 4907 | for (i = 0; i < len; i++) { |
| 4908 | stmt_ty value; |
| 4909 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4910 | if (res != 0) goto failed; |
| 4911 | asdl_seq_SET(body, i, value); |
| 4912 | } |
| 4913 | Py_CLEAR(tmp); |
| 4914 | } else { |
| 4915 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 4916 | return 1; |
| 4917 | } |
| 4918 | *out = AsyncWith(items, body, lineno, col_offset, arena); |
| 4919 | if (*out == NULL) goto failed; |
| 4920 | return 0; |
| 4921 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4922 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 4923 | if (isinstance == -1) { |
| 4924 | return 1; |
| 4925 | } |
| 4926 | if (isinstance) { |
| 4927 | expr_ty exc; |
| 4928 | expr_ty cause; |
| 4929 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4930 | if (exists_not_none(obj, &PyId_exc)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4931 | int res; |
| 4932 | tmp = _PyObject_GetAttrId(obj, &PyId_exc); |
| 4933 | if (tmp == NULL) goto failed; |
| 4934 | res = obj2ast_expr(tmp, &exc, arena); |
| 4935 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4936 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4937 | } else { |
| 4938 | exc = NULL; |
| 4939 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4940 | if (exists_not_none(obj, &PyId_cause)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4941 | int res; |
| 4942 | tmp = _PyObject_GetAttrId(obj, &PyId_cause); |
| 4943 | if (tmp == NULL) goto failed; |
| 4944 | res = obj2ast_expr(tmp, &cause, arena); |
| 4945 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4946 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4947 | } else { |
| 4948 | cause = NULL; |
| 4949 | } |
| 4950 | *out = Raise(exc, cause, lineno, col_offset, arena); |
| 4951 | if (*out == NULL) goto failed; |
| 4952 | return 0; |
| 4953 | } |
| 4954 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
| 4955 | if (isinstance == -1) { |
| 4956 | return 1; |
| 4957 | } |
| 4958 | if (isinstance) { |
| 4959 | asdl_seq* body; |
| 4960 | asdl_seq* handlers; |
| 4961 | asdl_seq* orelse; |
| 4962 | asdl_seq* finalbody; |
| 4963 | |
| 4964 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4965 | int res; |
| 4966 | Py_ssize_t len; |
| 4967 | Py_ssize_t i; |
| 4968 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4969 | if (tmp == NULL) goto failed; |
| 4970 | if (!PyList_Check(tmp)) { |
| 4971 | PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4972 | goto failed; |
| 4973 | } |
| 4974 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4975 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4976 | if (body == NULL) goto failed; |
| 4977 | for (i = 0; i < len; i++) { |
| 4978 | stmt_ty value; |
| 4979 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4980 | if (res != 0) goto failed; |
| 4981 | asdl_seq_SET(body, i, value); |
| 4982 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4983 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4984 | } else { |
| 4985 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 4986 | return 1; |
| 4987 | } |
| 4988 | if (_PyObject_HasAttrId(obj, &PyId_handlers)) { |
| 4989 | int res; |
| 4990 | Py_ssize_t len; |
| 4991 | Py_ssize_t i; |
| 4992 | tmp = _PyObject_GetAttrId(obj, &PyId_handlers); |
| 4993 | if (tmp == NULL) goto failed; |
| 4994 | if (!PyList_Check(tmp)) { |
| 4995 | PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4996 | goto failed; |
| 4997 | } |
| 4998 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4999 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5000 | if (handlers == NULL) goto failed; |
| 5001 | for (i = 0; i < len; i++) { |
| 5002 | excepthandler_ty value; |
| 5003 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5004 | if (res != 0) goto failed; |
| 5005 | asdl_seq_SET(handlers, i, value); |
| 5006 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5007 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5008 | } else { |
| 5009 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 5010 | return 1; |
| 5011 | } |
| 5012 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 5013 | int res; |
| 5014 | Py_ssize_t len; |
| 5015 | Py_ssize_t i; |
| 5016 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 5017 | if (tmp == NULL) goto failed; |
| 5018 | if (!PyList_Check(tmp)) { |
| 5019 | PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5020 | goto failed; |
| 5021 | } |
| 5022 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5023 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5024 | if (orelse == NULL) goto failed; |
| 5025 | for (i = 0; i < len; i++) { |
| 5026 | stmt_ty value; |
| 5027 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5028 | if (res != 0) goto failed; |
| 5029 | asdl_seq_SET(orelse, i, value); |
| 5030 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5031 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5032 | } else { |
| 5033 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 5034 | return 1; |
| 5035 | } |
| 5036 | if (_PyObject_HasAttrId(obj, &PyId_finalbody)) { |
| 5037 | int res; |
| 5038 | Py_ssize_t len; |
| 5039 | Py_ssize_t i; |
| 5040 | tmp = _PyObject_GetAttrId(obj, &PyId_finalbody); |
| 5041 | if (tmp == NULL) goto failed; |
| 5042 | if (!PyList_Check(tmp)) { |
| 5043 | PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5044 | goto failed; |
| 5045 | } |
| 5046 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5047 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5048 | if (finalbody == NULL) goto failed; |
| 5049 | for (i = 0; i < len; i++) { |
| 5050 | stmt_ty value; |
| 5051 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5052 | if (res != 0) goto failed; |
| 5053 | asdl_seq_SET(finalbody, i, value); |
| 5054 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5055 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5056 | } else { |
| 5057 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 5058 | return 1; |
| 5059 | } |
| 5060 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
| 5061 | arena); |
| 5062 | if (*out == NULL) goto failed; |
| 5063 | return 0; |
| 5064 | } |
| 5065 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 5066 | if (isinstance == -1) { |
| 5067 | return 1; |
| 5068 | } |
| 5069 | if (isinstance) { |
| 5070 | expr_ty test; |
| 5071 | expr_ty msg; |
| 5072 | |
| 5073 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
| 5074 | int res; |
| 5075 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 5076 | if (tmp == NULL) goto failed; |
| 5077 | res = obj2ast_expr(tmp, &test, arena); |
| 5078 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5079 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5080 | } else { |
| 5081 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 5082 | return 1; |
| 5083 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5084 | if (exists_not_none(obj, &PyId_msg)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5085 | int res; |
| 5086 | tmp = _PyObject_GetAttrId(obj, &PyId_msg); |
| 5087 | if (tmp == NULL) goto failed; |
| 5088 | res = obj2ast_expr(tmp, &msg, arena); |
| 5089 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5090 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5091 | } else { |
| 5092 | msg = NULL; |
| 5093 | } |
| 5094 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 5095 | if (*out == NULL) goto failed; |
| 5096 | return 0; |
| 5097 | } |
| 5098 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 5099 | if (isinstance == -1) { |
| 5100 | return 1; |
| 5101 | } |
| 5102 | if (isinstance) { |
| 5103 | asdl_seq* names; |
| 5104 | |
| 5105 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
| 5106 | int res; |
| 5107 | Py_ssize_t len; |
| 5108 | Py_ssize_t i; |
| 5109 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 5110 | if (tmp == NULL) goto failed; |
| 5111 | if (!PyList_Check(tmp)) { |
| 5112 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5113 | goto failed; |
| 5114 | } |
| 5115 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5116 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5117 | if (names == NULL) goto failed; |
| 5118 | for (i = 0; i < len; i++) { |
| 5119 | alias_ty value; |
| 5120 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5121 | if (res != 0) goto failed; |
| 5122 | asdl_seq_SET(names, i, value); |
| 5123 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5124 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5125 | } else { |
| 5126 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 5127 | return 1; |
| 5128 | } |
| 5129 | *out = Import(names, lineno, col_offset, arena); |
| 5130 | if (*out == NULL) goto failed; |
| 5131 | return 0; |
| 5132 | } |
| 5133 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 5134 | if (isinstance == -1) { |
| 5135 | return 1; |
| 5136 | } |
| 5137 | if (isinstance) { |
| 5138 | identifier module; |
| 5139 | asdl_seq* names; |
| 5140 | int level; |
| 5141 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5142 | if (exists_not_none(obj, &PyId_module)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5143 | int res; |
| 5144 | tmp = _PyObject_GetAttrId(obj, &PyId_module); |
| 5145 | if (tmp == NULL) goto failed; |
| 5146 | res = obj2ast_identifier(tmp, &module, arena); |
| 5147 | if (res != 0) goto failed; |
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 { |
| 5150 | module = NULL; |
| 5151 | } |
| 5152 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
| 5153 | int res; |
| 5154 | Py_ssize_t len; |
| 5155 | Py_ssize_t i; |
| 5156 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 5157 | if (tmp == NULL) goto failed; |
| 5158 | if (!PyList_Check(tmp)) { |
| 5159 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5160 | goto failed; |
| 5161 | } |
| 5162 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5163 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5164 | if (names == NULL) goto failed; |
| 5165 | for (i = 0; i < len; i++) { |
| 5166 | alias_ty value; |
| 5167 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5168 | if (res != 0) goto failed; |
| 5169 | asdl_seq_SET(names, i, value); |
| 5170 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5171 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5172 | } else { |
| 5173 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 5174 | return 1; |
| 5175 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5176 | if (exists_not_none(obj, &PyId_level)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5177 | int res; |
| 5178 | tmp = _PyObject_GetAttrId(obj, &PyId_level); |
| 5179 | if (tmp == NULL) goto failed; |
| 5180 | res = obj2ast_int(tmp, &level, arena); |
| 5181 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5182 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5183 | } else { |
| 5184 | level = 0; |
| 5185 | } |
| 5186 | *out = ImportFrom(module, names, level, lineno, col_offset, arena); |
| 5187 | if (*out == NULL) goto failed; |
| 5188 | return 0; |
| 5189 | } |
| 5190 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 5191 | if (isinstance == -1) { |
| 5192 | return 1; |
| 5193 | } |
| 5194 | if (isinstance) { |
| 5195 | asdl_seq* names; |
| 5196 | |
| 5197 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
| 5198 | int res; |
| 5199 | Py_ssize_t len; |
| 5200 | Py_ssize_t i; |
| 5201 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 5202 | if (tmp == NULL) goto failed; |
| 5203 | if (!PyList_Check(tmp)) { |
| 5204 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5205 | goto failed; |
| 5206 | } |
| 5207 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5208 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5209 | if (names == NULL) goto failed; |
| 5210 | for (i = 0; i < len; i++) { |
| 5211 | identifier value; |
| 5212 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5213 | if (res != 0) goto failed; |
| 5214 | asdl_seq_SET(names, i, value); |
| 5215 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5216 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5217 | } else { |
| 5218 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 5219 | return 1; |
| 5220 | } |
| 5221 | *out = Global(names, lineno, col_offset, arena); |
| 5222 | if (*out == NULL) goto failed; |
| 5223 | return 0; |
| 5224 | } |
| 5225 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 5226 | if (isinstance == -1) { |
| 5227 | return 1; |
| 5228 | } |
| 5229 | if (isinstance) { |
| 5230 | asdl_seq* names; |
| 5231 | |
| 5232 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
| 5233 | int res; |
| 5234 | Py_ssize_t len; |
| 5235 | Py_ssize_t i; |
| 5236 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 5237 | if (tmp == NULL) goto failed; |
| 5238 | if (!PyList_Check(tmp)) { |
| 5239 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5240 | goto failed; |
| 5241 | } |
| 5242 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5243 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5244 | if (names == NULL) goto failed; |
| 5245 | for (i = 0; i < len; i++) { |
| 5246 | identifier value; |
| 5247 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5248 | if (res != 0) goto failed; |
| 5249 | asdl_seq_SET(names, i, value); |
| 5250 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5251 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5252 | } else { |
| 5253 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 5254 | return 1; |
| 5255 | } |
| 5256 | *out = Nonlocal(names, lineno, col_offset, arena); |
| 5257 | if (*out == NULL) goto failed; |
| 5258 | return 0; |
| 5259 | } |
| 5260 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 5261 | if (isinstance == -1) { |
| 5262 | return 1; |
| 5263 | } |
| 5264 | if (isinstance) { |
| 5265 | expr_ty value; |
| 5266 | |
| 5267 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5268 | int res; |
| 5269 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5270 | if (tmp == NULL) goto failed; |
| 5271 | res = obj2ast_expr(tmp, &value, arena); |
| 5272 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5273 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5274 | } else { |
| 5275 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 5276 | return 1; |
| 5277 | } |
| 5278 | *out = Expr(value, lineno, col_offset, arena); |
| 5279 | if (*out == NULL) goto failed; |
| 5280 | return 0; |
| 5281 | } |
| 5282 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 5283 | if (isinstance == -1) { |
| 5284 | return 1; |
| 5285 | } |
| 5286 | if (isinstance) { |
| 5287 | |
| 5288 | *out = Pass(lineno, col_offset, arena); |
| 5289 | if (*out == NULL) goto failed; |
| 5290 | return 0; |
| 5291 | } |
| 5292 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 5293 | if (isinstance == -1) { |
| 5294 | return 1; |
| 5295 | } |
| 5296 | if (isinstance) { |
| 5297 | |
| 5298 | *out = Break(lineno, col_offset, arena); |
| 5299 | if (*out == NULL) goto failed; |
| 5300 | return 0; |
| 5301 | } |
| 5302 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 5303 | if (isinstance == -1) { |
| 5304 | return 1; |
| 5305 | } |
| 5306 | if (isinstance) { |
| 5307 | |
| 5308 | *out = Continue(lineno, col_offset, arena); |
| 5309 | if (*out == NULL) goto failed; |
| 5310 | return 0; |
| 5311 | } |
| 5312 | |
| 5313 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 5314 | failed: |
| 5315 | Py_XDECREF(tmp); |
| 5316 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5317 | } |
| 5318 | |
| 5319 | int |
| 5320 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 5321 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5322 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5323 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5324 | PyObject *tmp = NULL; |
| 5325 | int lineno; |
| 5326 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5327 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5328 | if (obj == Py_None) { |
| 5329 | *out = NULL; |
| 5330 | return 0; |
| 5331 | } |
| 5332 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
| 5333 | int res; |
| 5334 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 5335 | if (tmp == NULL) goto failed; |
| 5336 | res = obj2ast_int(tmp, &lineno, arena); |
| 5337 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5338 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5339 | } else { |
| 5340 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5341 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5342 | } |
| 5343 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
| 5344 | int res; |
| 5345 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 5346 | if (tmp == NULL) goto failed; |
| 5347 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5348 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5349 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5350 | } else { |
| 5351 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 5352 | return 1; |
| 5353 | } |
| 5354 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 5355 | if (isinstance == -1) { |
| 5356 | return 1; |
| 5357 | } |
| 5358 | if (isinstance) { |
| 5359 | boolop_ty op; |
| 5360 | asdl_seq* values; |
| 5361 | |
| 5362 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
| 5363 | int res; |
| 5364 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 5365 | if (tmp == NULL) goto failed; |
| 5366 | res = obj2ast_boolop(tmp, &op, arena); |
| 5367 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5368 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5369 | } else { |
| 5370 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 5371 | return 1; |
| 5372 | } |
| 5373 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
| 5374 | int res; |
| 5375 | Py_ssize_t len; |
| 5376 | Py_ssize_t i; |
| 5377 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
| 5378 | if (tmp == NULL) goto failed; |
| 5379 | if (!PyList_Check(tmp)) { |
| 5380 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5381 | goto failed; |
| 5382 | } |
| 5383 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5384 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5385 | if (values == NULL) goto failed; |
| 5386 | for (i = 0; i < len; i++) { |
| 5387 | expr_ty value; |
| 5388 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5389 | if (res != 0) goto failed; |
| 5390 | asdl_seq_SET(values, i, value); |
| 5391 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5392 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5393 | } else { |
| 5394 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 5395 | return 1; |
| 5396 | } |
| 5397 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 5398 | if (*out == NULL) goto failed; |
| 5399 | return 0; |
| 5400 | } |
| 5401 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 5402 | if (isinstance == -1) { |
| 5403 | return 1; |
| 5404 | } |
| 5405 | if (isinstance) { |
| 5406 | expr_ty left; |
| 5407 | operator_ty op; |
| 5408 | expr_ty right; |
| 5409 | |
| 5410 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
| 5411 | int res; |
| 5412 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
| 5413 | if (tmp == NULL) goto failed; |
| 5414 | res = obj2ast_expr(tmp, &left, arena); |
| 5415 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5416 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5417 | } else { |
| 5418 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 5419 | return 1; |
| 5420 | } |
| 5421 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
| 5422 | int res; |
| 5423 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 5424 | if (tmp == NULL) goto failed; |
| 5425 | res = obj2ast_operator(tmp, &op, arena); |
| 5426 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5427 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5428 | } else { |
| 5429 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 5430 | return 1; |
| 5431 | } |
| 5432 | if (_PyObject_HasAttrId(obj, &PyId_right)) { |
| 5433 | int res; |
| 5434 | tmp = _PyObject_GetAttrId(obj, &PyId_right); |
| 5435 | if (tmp == NULL) goto failed; |
| 5436 | res = obj2ast_expr(tmp, &right, arena); |
| 5437 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5438 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5439 | } else { |
| 5440 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 5441 | return 1; |
| 5442 | } |
| 5443 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 5444 | if (*out == NULL) goto failed; |
| 5445 | return 0; |
| 5446 | } |
| 5447 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 5448 | if (isinstance == -1) { |
| 5449 | return 1; |
| 5450 | } |
| 5451 | if (isinstance) { |
| 5452 | unaryop_ty op; |
| 5453 | expr_ty operand; |
| 5454 | |
| 5455 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
| 5456 | int res; |
| 5457 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 5458 | if (tmp == NULL) goto failed; |
| 5459 | res = obj2ast_unaryop(tmp, &op, arena); |
| 5460 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5461 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5462 | } else { |
| 5463 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 5464 | return 1; |
| 5465 | } |
| 5466 | if (_PyObject_HasAttrId(obj, &PyId_operand)) { |
| 5467 | int res; |
| 5468 | tmp = _PyObject_GetAttrId(obj, &PyId_operand); |
| 5469 | if (tmp == NULL) goto failed; |
| 5470 | res = obj2ast_expr(tmp, &operand, arena); |
| 5471 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5472 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5473 | } else { |
| 5474 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 5475 | return 1; |
| 5476 | } |
| 5477 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 5478 | if (*out == NULL) goto failed; |
| 5479 | return 0; |
| 5480 | } |
| 5481 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 5482 | if (isinstance == -1) { |
| 5483 | return 1; |
| 5484 | } |
| 5485 | if (isinstance) { |
| 5486 | arguments_ty args; |
| 5487 | expr_ty body; |
| 5488 | |
| 5489 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 5490 | int res; |
| 5491 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 5492 | if (tmp == NULL) goto failed; |
| 5493 | res = obj2ast_arguments(tmp, &args, arena); |
| 5494 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5495 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5496 | } else { |
| 5497 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 5498 | return 1; |
| 5499 | } |
| 5500 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 5501 | int res; |
| 5502 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 5503 | if (tmp == NULL) goto failed; |
| 5504 | res = obj2ast_expr(tmp, &body, 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 { |
| 5508 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 5509 | return 1; |
| 5510 | } |
| 5511 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 5512 | if (*out == NULL) goto failed; |
| 5513 | return 0; |
| 5514 | } |
| 5515 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 5516 | if (isinstance == -1) { |
| 5517 | return 1; |
| 5518 | } |
| 5519 | if (isinstance) { |
| 5520 | expr_ty test; |
| 5521 | expr_ty body; |
| 5522 | expr_ty orelse; |
| 5523 | |
| 5524 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
| 5525 | int res; |
| 5526 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 5527 | if (tmp == NULL) goto failed; |
| 5528 | res = obj2ast_expr(tmp, &test, arena); |
| 5529 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5530 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5531 | } else { |
| 5532 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 5533 | return 1; |
| 5534 | } |
| 5535 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 5536 | int res; |
| 5537 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 5538 | if (tmp == NULL) goto failed; |
| 5539 | res = obj2ast_expr(tmp, &body, arena); |
| 5540 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5541 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5542 | } else { |
| 5543 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 5544 | return 1; |
| 5545 | } |
| 5546 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 5547 | int res; |
| 5548 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 5549 | if (tmp == NULL) goto failed; |
| 5550 | res = obj2ast_expr(tmp, &orelse, arena); |
| 5551 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5552 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5553 | } else { |
| 5554 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 5555 | return 1; |
| 5556 | } |
| 5557 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 5558 | if (*out == NULL) goto failed; |
| 5559 | return 0; |
| 5560 | } |
| 5561 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 5562 | if (isinstance == -1) { |
| 5563 | return 1; |
| 5564 | } |
| 5565 | if (isinstance) { |
| 5566 | asdl_seq* keys; |
| 5567 | asdl_seq* values; |
| 5568 | |
| 5569 | if (_PyObject_HasAttrId(obj, &PyId_keys)) { |
| 5570 | int res; |
| 5571 | Py_ssize_t len; |
| 5572 | Py_ssize_t i; |
| 5573 | tmp = _PyObject_GetAttrId(obj, &PyId_keys); |
| 5574 | if (tmp == NULL) goto failed; |
| 5575 | if (!PyList_Check(tmp)) { |
| 5576 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5577 | goto failed; |
| 5578 | } |
| 5579 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5580 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5581 | if (keys == NULL) goto failed; |
| 5582 | for (i = 0; i < len; i++) { |
| 5583 | expr_ty value; |
| 5584 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5585 | if (res != 0) goto failed; |
| 5586 | asdl_seq_SET(keys, i, value); |
| 5587 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5588 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5589 | } else { |
| 5590 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 5591 | return 1; |
| 5592 | } |
| 5593 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
| 5594 | int res; |
| 5595 | Py_ssize_t len; |
| 5596 | Py_ssize_t i; |
| 5597 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
| 5598 | if (tmp == NULL) goto failed; |
| 5599 | if (!PyList_Check(tmp)) { |
| 5600 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5601 | goto failed; |
| 5602 | } |
| 5603 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5604 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5605 | if (values == NULL) goto failed; |
| 5606 | for (i = 0; i < len; i++) { |
| 5607 | expr_ty value; |
| 5608 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5609 | if (res != 0) goto failed; |
| 5610 | asdl_seq_SET(values, i, value); |
| 5611 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5612 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5613 | } else { |
| 5614 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 5615 | return 1; |
| 5616 | } |
| 5617 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 5618 | if (*out == NULL) goto failed; |
| 5619 | return 0; |
| 5620 | } |
| 5621 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 5622 | if (isinstance == -1) { |
| 5623 | return 1; |
| 5624 | } |
| 5625 | if (isinstance) { |
| 5626 | asdl_seq* elts; |
| 5627 | |
| 5628 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
| 5629 | int res; |
| 5630 | Py_ssize_t len; |
| 5631 | Py_ssize_t i; |
| 5632 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
| 5633 | if (tmp == NULL) goto failed; |
| 5634 | if (!PyList_Check(tmp)) { |
| 5635 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5636 | goto failed; |
| 5637 | } |
| 5638 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5639 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5640 | if (elts == NULL) goto failed; |
| 5641 | for (i = 0; i < len; i++) { |
| 5642 | expr_ty value; |
| 5643 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5644 | if (res != 0) goto failed; |
| 5645 | asdl_seq_SET(elts, i, value); |
| 5646 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5647 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5648 | } else { |
| 5649 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 5650 | return 1; |
| 5651 | } |
| 5652 | *out = Set(elts, lineno, col_offset, arena); |
| 5653 | if (*out == NULL) goto failed; |
| 5654 | return 0; |
| 5655 | } |
| 5656 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 5657 | if (isinstance == -1) { |
| 5658 | return 1; |
| 5659 | } |
| 5660 | if (isinstance) { |
| 5661 | expr_ty elt; |
| 5662 | asdl_seq* generators; |
| 5663 | |
| 5664 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
| 5665 | int res; |
| 5666 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
| 5667 | if (tmp == NULL) goto failed; |
| 5668 | res = obj2ast_expr(tmp, &elt, arena); |
| 5669 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5670 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5671 | } else { |
| 5672 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 5673 | return 1; |
| 5674 | } |
| 5675 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
| 5676 | int res; |
| 5677 | Py_ssize_t len; |
| 5678 | Py_ssize_t i; |
| 5679 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 5680 | if (tmp == NULL) goto failed; |
| 5681 | if (!PyList_Check(tmp)) { |
| 5682 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5683 | goto failed; |
| 5684 | } |
| 5685 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5686 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5687 | if (generators == NULL) goto failed; |
| 5688 | for (i = 0; i < len; i++) { |
| 5689 | comprehension_ty value; |
| 5690 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5691 | if (res != 0) goto failed; |
| 5692 | asdl_seq_SET(generators, i, value); |
| 5693 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5694 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5695 | } else { |
| 5696 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 5697 | return 1; |
| 5698 | } |
| 5699 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 5700 | if (*out == NULL) goto failed; |
| 5701 | return 0; |
| 5702 | } |
| 5703 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 5704 | if (isinstance == -1) { |
| 5705 | return 1; |
| 5706 | } |
| 5707 | if (isinstance) { |
| 5708 | expr_ty elt; |
| 5709 | asdl_seq* generators; |
| 5710 | |
| 5711 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
| 5712 | int res; |
| 5713 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
| 5714 | if (tmp == NULL) goto failed; |
| 5715 | res = obj2ast_expr(tmp, &elt, arena); |
| 5716 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5717 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5718 | } else { |
| 5719 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 5720 | return 1; |
| 5721 | } |
| 5722 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
| 5723 | int res; |
| 5724 | Py_ssize_t len; |
| 5725 | Py_ssize_t i; |
| 5726 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 5727 | if (tmp == NULL) goto failed; |
| 5728 | if (!PyList_Check(tmp)) { |
| 5729 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5730 | goto failed; |
| 5731 | } |
| 5732 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5733 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5734 | if (generators == NULL) goto failed; |
| 5735 | for (i = 0; i < len; i++) { |
| 5736 | comprehension_ty value; |
| 5737 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5738 | if (res != 0) goto failed; |
| 5739 | asdl_seq_SET(generators, i, value); |
| 5740 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5741 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5742 | } else { |
| 5743 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 5744 | return 1; |
| 5745 | } |
| 5746 | *out = SetComp(elt, generators, lineno, col_offset, arena); |
| 5747 | if (*out == NULL) goto failed; |
| 5748 | return 0; |
| 5749 | } |
| 5750 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 5751 | if (isinstance == -1) { |
| 5752 | return 1; |
| 5753 | } |
| 5754 | if (isinstance) { |
| 5755 | expr_ty key; |
| 5756 | expr_ty value; |
| 5757 | asdl_seq* generators; |
| 5758 | |
| 5759 | if (_PyObject_HasAttrId(obj, &PyId_key)) { |
| 5760 | int res; |
| 5761 | tmp = _PyObject_GetAttrId(obj, &PyId_key); |
| 5762 | if (tmp == NULL) goto failed; |
| 5763 | res = obj2ast_expr(tmp, &key, arena); |
| 5764 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5765 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5766 | } else { |
| 5767 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 5768 | return 1; |
| 5769 | } |
| 5770 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5771 | int res; |
| 5772 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5773 | if (tmp == NULL) goto failed; |
| 5774 | res = obj2ast_expr(tmp, &value, arena); |
| 5775 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5776 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5777 | } else { |
| 5778 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 5779 | return 1; |
| 5780 | } |
| 5781 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
| 5782 | int res; |
| 5783 | Py_ssize_t len; |
| 5784 | Py_ssize_t i; |
| 5785 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 5786 | if (tmp == NULL) goto failed; |
| 5787 | if (!PyList_Check(tmp)) { |
| 5788 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5789 | goto failed; |
| 5790 | } |
| 5791 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5792 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5793 | if (generators == NULL) goto failed; |
| 5794 | for (i = 0; i < len; i++) { |
| 5795 | comprehension_ty value; |
| 5796 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5797 | if (res != 0) goto failed; |
| 5798 | asdl_seq_SET(generators, i, value); |
| 5799 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5800 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5801 | } else { |
| 5802 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 5803 | return 1; |
| 5804 | } |
| 5805 | *out = DictComp(key, value, generators, lineno, col_offset, arena); |
| 5806 | if (*out == NULL) goto failed; |
| 5807 | return 0; |
| 5808 | } |
| 5809 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 5810 | if (isinstance == -1) { |
| 5811 | return 1; |
| 5812 | } |
| 5813 | if (isinstance) { |
| 5814 | expr_ty elt; |
| 5815 | asdl_seq* generators; |
| 5816 | |
| 5817 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
| 5818 | int res; |
| 5819 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
| 5820 | if (tmp == NULL) goto failed; |
| 5821 | res = obj2ast_expr(tmp, &elt, arena); |
| 5822 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5823 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5824 | } else { |
| 5825 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 5826 | return 1; |
| 5827 | } |
| 5828 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
| 5829 | int res; |
| 5830 | Py_ssize_t len; |
| 5831 | Py_ssize_t i; |
| 5832 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 5833 | if (tmp == NULL) goto failed; |
| 5834 | if (!PyList_Check(tmp)) { |
| 5835 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" 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 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5840 | if (generators == NULL) goto failed; |
| 5841 | for (i = 0; i < len; i++) { |
| 5842 | comprehension_ty value; |
| 5843 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5844 | if (res != 0) goto failed; |
| 5845 | asdl_seq_SET(generators, i, value); |
| 5846 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5847 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5848 | } else { |
| 5849 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 5850 | return 1; |
| 5851 | } |
| 5852 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 5853 | if (*out == NULL) goto failed; |
| 5854 | return 0; |
| 5855 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5856 | isinstance = PyObject_IsInstance(obj, (PyObject*)Await_type); |
| 5857 | if (isinstance == -1) { |
| 5858 | return 1; |
| 5859 | } |
| 5860 | if (isinstance) { |
| 5861 | expr_ty value; |
| 5862 | |
| 5863 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5864 | int res; |
| 5865 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5866 | if (tmp == NULL) goto failed; |
| 5867 | res = obj2ast_expr(tmp, &value, arena); |
| 5868 | if (res != 0) goto failed; |
| 5869 | Py_CLEAR(tmp); |
| 5870 | } else { |
| 5871 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 5872 | return 1; |
| 5873 | } |
| 5874 | *out = Await(value, lineno, col_offset, arena); |
| 5875 | if (*out == NULL) goto failed; |
| 5876 | return 0; |
| 5877 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5878 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 5879 | if (isinstance == -1) { |
| 5880 | return 1; |
| 5881 | } |
| 5882 | if (isinstance) { |
| 5883 | expr_ty value; |
| 5884 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5885 | if (exists_not_none(obj, &PyId_value)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5886 | int res; |
| 5887 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5888 | if (tmp == NULL) goto failed; |
| 5889 | res = obj2ast_expr(tmp, &value, arena); |
| 5890 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5891 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5892 | } else { |
| 5893 | value = NULL; |
| 5894 | } |
| 5895 | *out = Yield(value, lineno, col_offset, arena); |
| 5896 | if (*out == NULL) goto failed; |
| 5897 | return 0; |
| 5898 | } |
| 5899 | isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); |
| 5900 | if (isinstance == -1) { |
| 5901 | return 1; |
| 5902 | } |
| 5903 | if (isinstance) { |
| 5904 | expr_ty value; |
| 5905 | |
| 5906 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5907 | int res; |
| 5908 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5909 | if (tmp == NULL) goto failed; |
| 5910 | res = obj2ast_expr(tmp, &value, arena); |
| 5911 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5912 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5913 | } else { |
| 5914 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 5915 | return 1; |
| 5916 | } |
| 5917 | *out = YieldFrom(value, lineno, col_offset, arena); |
| 5918 | if (*out == NULL) goto failed; |
| 5919 | return 0; |
| 5920 | } |
| 5921 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 5922 | if (isinstance == -1) { |
| 5923 | return 1; |
| 5924 | } |
| 5925 | if (isinstance) { |
| 5926 | expr_ty left; |
| 5927 | asdl_int_seq* ops; |
| 5928 | asdl_seq* comparators; |
| 5929 | |
| 5930 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
| 5931 | int res; |
| 5932 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
| 5933 | if (tmp == NULL) goto failed; |
| 5934 | res = obj2ast_expr(tmp, &left, 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 { |
| 5938 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 5939 | return 1; |
| 5940 | } |
| 5941 | if (_PyObject_HasAttrId(obj, &PyId_ops)) { |
| 5942 | int res; |
| 5943 | Py_ssize_t len; |
| 5944 | Py_ssize_t i; |
| 5945 | tmp = _PyObject_GetAttrId(obj, &PyId_ops); |
| 5946 | if (tmp == NULL) goto failed; |
| 5947 | if (!PyList_Check(tmp)) { |
| 5948 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5949 | goto failed; |
| 5950 | } |
| 5951 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5952 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5953 | if (ops == NULL) goto failed; |
| 5954 | for (i = 0; i < len; i++) { |
| 5955 | cmpop_ty value; |
| 5956 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5957 | if (res != 0) goto failed; |
| 5958 | asdl_seq_SET(ops, i, value); |
| 5959 | } |
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 { |
| 5962 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 5963 | return 1; |
| 5964 | } |
| 5965 | if (_PyObject_HasAttrId(obj, &PyId_comparators)) { |
| 5966 | int res; |
| 5967 | Py_ssize_t len; |
| 5968 | Py_ssize_t i; |
| 5969 | tmp = _PyObject_GetAttrId(obj, &PyId_comparators); |
| 5970 | if (tmp == NULL) goto failed; |
| 5971 | if (!PyList_Check(tmp)) { |
| 5972 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5973 | goto failed; |
| 5974 | } |
| 5975 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5976 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5977 | if (comparators == NULL) goto failed; |
| 5978 | for (i = 0; i < len; i++) { |
| 5979 | expr_ty value; |
| 5980 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5981 | if (res != 0) goto failed; |
| 5982 | asdl_seq_SET(comparators, i, value); |
| 5983 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5984 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5985 | } else { |
| 5986 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 5987 | return 1; |
| 5988 | } |
| 5989 | *out = Compare(left, ops, comparators, lineno, col_offset, arena); |
| 5990 | if (*out == NULL) goto failed; |
| 5991 | return 0; |
| 5992 | } |
| 5993 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 5994 | if (isinstance == -1) { |
| 5995 | return 1; |
| 5996 | } |
| 5997 | if (isinstance) { |
| 5998 | expr_ty func; |
| 5999 | asdl_seq* args; |
| 6000 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6001 | |
| 6002 | if (_PyObject_HasAttrId(obj, &PyId_func)) { |
| 6003 | int res; |
| 6004 | tmp = _PyObject_GetAttrId(obj, &PyId_func); |
| 6005 | if (tmp == NULL) goto failed; |
| 6006 | res = obj2ast_expr(tmp, &func, arena); |
| 6007 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6008 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6009 | } else { |
| 6010 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 6011 | return 1; |
| 6012 | } |
| 6013 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 6014 | int res; |
| 6015 | Py_ssize_t len; |
| 6016 | Py_ssize_t i; |
| 6017 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 6018 | if (tmp == NULL) goto failed; |
| 6019 | if (!PyList_Check(tmp)) { |
| 6020 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6021 | goto failed; |
| 6022 | } |
| 6023 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6024 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6025 | if (args == NULL) goto failed; |
| 6026 | for (i = 0; i < len; i++) { |
| 6027 | expr_ty value; |
| 6028 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6029 | if (res != 0) goto failed; |
| 6030 | asdl_seq_SET(args, i, value); |
| 6031 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6032 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6033 | } else { |
| 6034 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 6035 | return 1; |
| 6036 | } |
| 6037 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
| 6038 | int res; |
| 6039 | Py_ssize_t len; |
| 6040 | Py_ssize_t i; |
| 6041 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
| 6042 | if (tmp == NULL) goto failed; |
| 6043 | if (!PyList_Check(tmp)) { |
| 6044 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6045 | goto failed; |
| 6046 | } |
| 6047 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6048 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6049 | if (keywords == NULL) goto failed; |
| 6050 | for (i = 0; i < len; i++) { |
| 6051 | keyword_ty value; |
| 6052 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6053 | if (res != 0) goto failed; |
| 6054 | asdl_seq_SET(keywords, i, value); |
| 6055 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6056 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6057 | } else { |
| 6058 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 6059 | return 1; |
| 6060 | } |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 6061 | *out = Call(func, args, keywords, lineno, col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6062 | if (*out == NULL) goto failed; |
| 6063 | return 0; |
| 6064 | } |
| 6065 | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); |
| 6066 | if (isinstance == -1) { |
| 6067 | return 1; |
| 6068 | } |
| 6069 | if (isinstance) { |
| 6070 | object n; |
| 6071 | |
| 6072 | if (_PyObject_HasAttrId(obj, &PyId_n)) { |
| 6073 | int res; |
| 6074 | tmp = _PyObject_GetAttrId(obj, &PyId_n); |
| 6075 | if (tmp == NULL) goto failed; |
| 6076 | res = obj2ast_object(tmp, &n, arena); |
| 6077 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6078 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6079 | } else { |
| 6080 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 6081 | return 1; |
| 6082 | } |
| 6083 | *out = Num(n, lineno, col_offset, arena); |
| 6084 | if (*out == NULL) goto failed; |
| 6085 | return 0; |
| 6086 | } |
| 6087 | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); |
| 6088 | if (isinstance == -1) { |
| 6089 | return 1; |
| 6090 | } |
| 6091 | if (isinstance) { |
| 6092 | string s; |
| 6093 | |
| 6094 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
| 6095 | int res; |
| 6096 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
| 6097 | if (tmp == NULL) goto failed; |
| 6098 | res = obj2ast_string(tmp, &s, arena); |
| 6099 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6100 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6101 | } else { |
| 6102 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 6103 | return 1; |
| 6104 | } |
| 6105 | *out = Str(s, lineno, col_offset, arena); |
| 6106 | if (*out == NULL) goto failed; |
| 6107 | return 0; |
| 6108 | } |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 6109 | isinstance = PyObject_IsInstance(obj, (PyObject*)FormattedValue_type); |
| 6110 | if (isinstance == -1) { |
| 6111 | return 1; |
| 6112 | } |
| 6113 | if (isinstance) { |
| 6114 | expr_ty value; |
| 6115 | int conversion; |
| 6116 | expr_ty format_spec; |
| 6117 | |
| 6118 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6119 | int res; |
| 6120 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6121 | if (tmp == NULL) goto failed; |
| 6122 | res = obj2ast_expr(tmp, &value, arena); |
| 6123 | if (res != 0) goto failed; |
| 6124 | Py_CLEAR(tmp); |
| 6125 | } else { |
| 6126 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 6127 | return 1; |
| 6128 | } |
| 6129 | if (exists_not_none(obj, &PyId_conversion)) { |
| 6130 | int res; |
| 6131 | tmp = _PyObject_GetAttrId(obj, &PyId_conversion); |
| 6132 | if (tmp == NULL) goto failed; |
| 6133 | res = obj2ast_int(tmp, &conversion, arena); |
| 6134 | if (res != 0) goto failed; |
| 6135 | Py_CLEAR(tmp); |
| 6136 | } else { |
| 6137 | conversion = 0; |
| 6138 | } |
| 6139 | if (exists_not_none(obj, &PyId_format_spec)) { |
| 6140 | int res; |
| 6141 | tmp = _PyObject_GetAttrId(obj, &PyId_format_spec); |
| 6142 | if (tmp == NULL) goto failed; |
| 6143 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 6144 | if (res != 0) goto failed; |
| 6145 | Py_CLEAR(tmp); |
| 6146 | } else { |
| 6147 | format_spec = NULL; |
| 6148 | } |
| 6149 | *out = FormattedValue(value, conversion, format_spec, lineno, |
| 6150 | col_offset, arena); |
| 6151 | if (*out == NULL) goto failed; |
| 6152 | return 0; |
| 6153 | } |
| 6154 | isinstance = PyObject_IsInstance(obj, (PyObject*)JoinedStr_type); |
| 6155 | if (isinstance == -1) { |
| 6156 | return 1; |
| 6157 | } |
| 6158 | if (isinstance) { |
| 6159 | asdl_seq* values; |
| 6160 | |
| 6161 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
| 6162 | int res; |
| 6163 | Py_ssize_t len; |
| 6164 | Py_ssize_t i; |
| 6165 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
| 6166 | if (tmp == NULL) goto failed; |
| 6167 | if (!PyList_Check(tmp)) { |
| 6168 | PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6169 | goto failed; |
| 6170 | } |
| 6171 | len = PyList_GET_SIZE(tmp); |
| 6172 | values = _Py_asdl_seq_new(len, arena); |
| 6173 | if (values == NULL) goto failed; |
| 6174 | for (i = 0; i < len; i++) { |
| 6175 | expr_ty value; |
| 6176 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6177 | if (res != 0) goto failed; |
| 6178 | asdl_seq_SET(values, i, value); |
| 6179 | } |
| 6180 | Py_CLEAR(tmp); |
| 6181 | } else { |
| 6182 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 6183 | return 1; |
| 6184 | } |
| 6185 | *out = JoinedStr(values, lineno, col_offset, arena); |
| 6186 | if (*out == NULL) goto failed; |
| 6187 | return 0; |
| 6188 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6189 | isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); |
| 6190 | if (isinstance == -1) { |
| 6191 | return 1; |
| 6192 | } |
| 6193 | if (isinstance) { |
| 6194 | bytes s; |
| 6195 | |
| 6196 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
| 6197 | int res; |
| 6198 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
| 6199 | if (tmp == NULL) goto failed; |
| 6200 | res = obj2ast_bytes(tmp, &s, arena); |
| 6201 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6202 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6203 | } else { |
| 6204 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); |
| 6205 | return 1; |
| 6206 | } |
| 6207 | *out = Bytes(s, lineno, col_offset, arena); |
| 6208 | if (*out == NULL) goto failed; |
| 6209 | return 0; |
| 6210 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6211 | isinstance = PyObject_IsInstance(obj, (PyObject*)NameConstant_type); |
| 6212 | if (isinstance == -1) { |
| 6213 | return 1; |
| 6214 | } |
| 6215 | if (isinstance) { |
| 6216 | singleton value; |
| 6217 | |
| 6218 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6219 | int res; |
| 6220 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6221 | if (tmp == NULL) goto failed; |
| 6222 | res = obj2ast_singleton(tmp, &value, arena); |
| 6223 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 6224 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6225 | } else { |
| 6226 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NameConstant"); |
| 6227 | return 1; |
| 6228 | } |
| 6229 | *out = NameConstant(value, lineno, col_offset, arena); |
| 6230 | if (*out == NULL) goto failed; |
| 6231 | return 0; |
| 6232 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6233 | isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); |
| 6234 | if (isinstance == -1) { |
| 6235 | return 1; |
| 6236 | } |
| 6237 | if (isinstance) { |
| 6238 | |
| 6239 | *out = Ellipsis(lineno, col_offset, arena); |
| 6240 | if (*out == NULL) goto failed; |
| 6241 | return 0; |
| 6242 | } |
| 6243 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 6244 | if (isinstance == -1) { |
| 6245 | return 1; |
| 6246 | } |
| 6247 | if (isinstance) { |
| 6248 | expr_ty value; |
| 6249 | identifier attr; |
| 6250 | expr_context_ty ctx; |
| 6251 | |
| 6252 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6253 | int res; |
| 6254 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6255 | if (tmp == NULL) goto failed; |
| 6256 | res = obj2ast_expr(tmp, &value, arena); |
| 6257 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6258 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6259 | } else { |
| 6260 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 6261 | return 1; |
| 6262 | } |
| 6263 | if (_PyObject_HasAttrId(obj, &PyId_attr)) { |
| 6264 | int res; |
| 6265 | tmp = _PyObject_GetAttrId(obj, &PyId_attr); |
| 6266 | if (tmp == NULL) goto failed; |
| 6267 | res = obj2ast_identifier(tmp, &attr, arena); |
| 6268 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6269 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6270 | } else { |
| 6271 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 6272 | return 1; |
| 6273 | } |
| 6274 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6275 | int res; |
| 6276 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6277 | if (tmp == NULL) goto failed; |
| 6278 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6279 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6280 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6281 | } else { |
| 6282 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 6283 | return 1; |
| 6284 | } |
| 6285 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 6286 | if (*out == NULL) goto failed; |
| 6287 | return 0; |
| 6288 | } |
| 6289 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 6290 | if (isinstance == -1) { |
| 6291 | return 1; |
| 6292 | } |
| 6293 | if (isinstance) { |
| 6294 | expr_ty value; |
| 6295 | slice_ty slice; |
| 6296 | expr_context_ty ctx; |
| 6297 | |
| 6298 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6299 | int res; |
| 6300 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6301 | if (tmp == NULL) goto failed; |
| 6302 | res = obj2ast_expr(tmp, &value, arena); |
| 6303 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6304 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6305 | } else { |
| 6306 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 6307 | return 1; |
| 6308 | } |
| 6309 | if (_PyObject_HasAttrId(obj, &PyId_slice)) { |
| 6310 | int res; |
| 6311 | tmp = _PyObject_GetAttrId(obj, &PyId_slice); |
| 6312 | if (tmp == NULL) goto failed; |
| 6313 | res = obj2ast_slice(tmp, &slice, arena); |
| 6314 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6315 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6316 | } else { |
| 6317 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 6318 | return 1; |
| 6319 | } |
| 6320 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6321 | int res; |
| 6322 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6323 | if (tmp == NULL) goto failed; |
| 6324 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6325 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6326 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6327 | } else { |
| 6328 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 6329 | return 1; |
| 6330 | } |
| 6331 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 6332 | if (*out == NULL) goto failed; |
| 6333 | return 0; |
| 6334 | } |
| 6335 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 6336 | if (isinstance == -1) { |
| 6337 | return 1; |
| 6338 | } |
| 6339 | if (isinstance) { |
| 6340 | expr_ty value; |
| 6341 | expr_context_ty ctx; |
| 6342 | |
| 6343 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6344 | int res; |
| 6345 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6346 | if (tmp == NULL) goto failed; |
| 6347 | res = obj2ast_expr(tmp, &value, arena); |
| 6348 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6349 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6350 | } else { |
| 6351 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 6352 | return 1; |
| 6353 | } |
| 6354 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6355 | int res; |
| 6356 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6357 | if (tmp == NULL) goto failed; |
| 6358 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6359 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6360 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6361 | } else { |
| 6362 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 6363 | return 1; |
| 6364 | } |
| 6365 | *out = Starred(value, ctx, lineno, col_offset, arena); |
| 6366 | if (*out == NULL) goto failed; |
| 6367 | return 0; |
| 6368 | } |
| 6369 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 6370 | if (isinstance == -1) { |
| 6371 | return 1; |
| 6372 | } |
| 6373 | if (isinstance) { |
| 6374 | identifier id; |
| 6375 | expr_context_ty ctx; |
| 6376 | |
| 6377 | if (_PyObject_HasAttrId(obj, &PyId_id)) { |
| 6378 | int res; |
| 6379 | tmp = _PyObject_GetAttrId(obj, &PyId_id); |
| 6380 | if (tmp == NULL) goto failed; |
| 6381 | res = obj2ast_identifier(tmp, &id, arena); |
| 6382 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6383 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6384 | } else { |
| 6385 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 6386 | return 1; |
| 6387 | } |
| 6388 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6389 | int res; |
| 6390 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6391 | if (tmp == NULL) goto failed; |
| 6392 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6393 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6394 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6395 | } else { |
| 6396 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 6397 | return 1; |
| 6398 | } |
| 6399 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 6400 | if (*out == NULL) goto failed; |
| 6401 | return 0; |
| 6402 | } |
| 6403 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 6404 | if (isinstance == -1) { |
| 6405 | return 1; |
| 6406 | } |
| 6407 | if (isinstance) { |
| 6408 | asdl_seq* elts; |
| 6409 | expr_context_ty ctx; |
| 6410 | |
| 6411 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
| 6412 | int res; |
| 6413 | Py_ssize_t len; |
| 6414 | Py_ssize_t i; |
| 6415 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
| 6416 | if (tmp == NULL) goto failed; |
| 6417 | if (!PyList_Check(tmp)) { |
| 6418 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6419 | goto failed; |
| 6420 | } |
| 6421 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6422 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6423 | if (elts == NULL) goto failed; |
| 6424 | for (i = 0; i < len; i++) { |
| 6425 | expr_ty value; |
| 6426 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6427 | if (res != 0) goto failed; |
| 6428 | asdl_seq_SET(elts, i, value); |
| 6429 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6430 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6431 | } else { |
| 6432 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 6433 | return 1; |
| 6434 | } |
| 6435 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6436 | int res; |
| 6437 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6438 | if (tmp == NULL) goto failed; |
| 6439 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6440 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6441 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6442 | } else { |
| 6443 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 6444 | return 1; |
| 6445 | } |
| 6446 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 6447 | if (*out == NULL) goto failed; |
| 6448 | return 0; |
| 6449 | } |
| 6450 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 6451 | if (isinstance == -1) { |
| 6452 | return 1; |
| 6453 | } |
| 6454 | if (isinstance) { |
| 6455 | asdl_seq* elts; |
| 6456 | expr_context_ty ctx; |
| 6457 | |
| 6458 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
| 6459 | int res; |
| 6460 | Py_ssize_t len; |
| 6461 | Py_ssize_t i; |
| 6462 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
| 6463 | if (tmp == NULL) goto failed; |
| 6464 | if (!PyList_Check(tmp)) { |
| 6465 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6466 | goto failed; |
| 6467 | } |
| 6468 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6469 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6470 | if (elts == NULL) goto failed; |
| 6471 | for (i = 0; i < len; i++) { |
| 6472 | expr_ty value; |
| 6473 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6474 | if (res != 0) goto failed; |
| 6475 | asdl_seq_SET(elts, i, value); |
| 6476 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6477 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6478 | } else { |
| 6479 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 6480 | return 1; |
| 6481 | } |
| 6482 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6483 | int res; |
| 6484 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6485 | if (tmp == NULL) goto failed; |
| 6486 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6487 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6488 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6489 | } else { |
| 6490 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 6491 | return 1; |
| 6492 | } |
| 6493 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 6494 | if (*out == NULL) goto failed; |
| 6495 | return 0; |
| 6496 | } |
| 6497 | |
| 6498 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 6499 | failed: |
| 6500 | Py_XDECREF(tmp); |
| 6501 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6502 | } |
| 6503 | |
| 6504 | int |
| 6505 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 6506 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6507 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6508 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6509 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 6510 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6511 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6512 | } |
| 6513 | if (isinstance) { |
| 6514 | *out = Load; |
| 6515 | return 0; |
| 6516 | } |
| 6517 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 6518 | if (isinstance == -1) { |
| 6519 | return 1; |
| 6520 | } |
| 6521 | if (isinstance) { |
| 6522 | *out = Store; |
| 6523 | return 0; |
| 6524 | } |
| 6525 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 6526 | if (isinstance == -1) { |
| 6527 | return 1; |
| 6528 | } |
| 6529 | if (isinstance) { |
| 6530 | *out = Del; |
| 6531 | return 0; |
| 6532 | } |
| 6533 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 6534 | if (isinstance == -1) { |
| 6535 | return 1; |
| 6536 | } |
| 6537 | if (isinstance) { |
| 6538 | *out = AugLoad; |
| 6539 | return 0; |
| 6540 | } |
| 6541 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 6542 | if (isinstance == -1) { |
| 6543 | return 1; |
| 6544 | } |
| 6545 | if (isinstance) { |
| 6546 | *out = AugStore; |
| 6547 | return 0; |
| 6548 | } |
| 6549 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 6550 | if (isinstance == -1) { |
| 6551 | return 1; |
| 6552 | } |
| 6553 | if (isinstance) { |
| 6554 | *out = Param; |
| 6555 | return 0; |
| 6556 | } |
| 6557 | |
| 6558 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 6559 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6560 | } |
| 6561 | |
| 6562 | int |
| 6563 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 6564 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6565 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6566 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6567 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6568 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6569 | if (obj == Py_None) { |
| 6570 | *out = NULL; |
| 6571 | return 0; |
| 6572 | } |
| 6573 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 6574 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6575 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6576 | } |
| 6577 | if (isinstance) { |
| 6578 | expr_ty lower; |
| 6579 | expr_ty upper; |
| 6580 | expr_ty step; |
| 6581 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6582 | if (exists_not_none(obj, &PyId_lower)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6583 | int res; |
| 6584 | tmp = _PyObject_GetAttrId(obj, &PyId_lower); |
| 6585 | if (tmp == NULL) goto failed; |
| 6586 | res = obj2ast_expr(tmp, &lower, arena); |
| 6587 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6588 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6589 | } else { |
| 6590 | lower = NULL; |
| 6591 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6592 | if (exists_not_none(obj, &PyId_upper)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6593 | int res; |
| 6594 | tmp = _PyObject_GetAttrId(obj, &PyId_upper); |
| 6595 | if (tmp == NULL) goto failed; |
| 6596 | res = obj2ast_expr(tmp, &upper, arena); |
| 6597 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6598 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6599 | } else { |
| 6600 | upper = NULL; |
| 6601 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6602 | if (exists_not_none(obj, &PyId_step)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6603 | int res; |
| 6604 | tmp = _PyObject_GetAttrId(obj, &PyId_step); |
| 6605 | if (tmp == NULL) goto failed; |
| 6606 | res = obj2ast_expr(tmp, &step, arena); |
| 6607 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6608 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6609 | } else { |
| 6610 | step = NULL; |
| 6611 | } |
| 6612 | *out = Slice(lower, upper, step, arena); |
| 6613 | if (*out == NULL) goto failed; |
| 6614 | return 0; |
| 6615 | } |
| 6616 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 6617 | if (isinstance == -1) { |
| 6618 | return 1; |
| 6619 | } |
| 6620 | if (isinstance) { |
| 6621 | asdl_seq* dims; |
| 6622 | |
| 6623 | if (_PyObject_HasAttrId(obj, &PyId_dims)) { |
| 6624 | int res; |
| 6625 | Py_ssize_t len; |
| 6626 | Py_ssize_t i; |
| 6627 | tmp = _PyObject_GetAttrId(obj, &PyId_dims); |
| 6628 | if (tmp == NULL) goto failed; |
| 6629 | if (!PyList_Check(tmp)) { |
| 6630 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6631 | goto failed; |
| 6632 | } |
| 6633 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6634 | dims = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6635 | if (dims == NULL) goto failed; |
| 6636 | for (i = 0; i < len; i++) { |
| 6637 | slice_ty value; |
| 6638 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6639 | if (res != 0) goto failed; |
| 6640 | asdl_seq_SET(dims, i, value); |
| 6641 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6642 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6643 | } else { |
| 6644 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 6645 | return 1; |
| 6646 | } |
| 6647 | *out = ExtSlice(dims, arena); |
| 6648 | if (*out == NULL) goto failed; |
| 6649 | return 0; |
| 6650 | } |
| 6651 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 6652 | if (isinstance == -1) { |
| 6653 | return 1; |
| 6654 | } |
| 6655 | if (isinstance) { |
| 6656 | expr_ty value; |
| 6657 | |
| 6658 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6659 | int res; |
| 6660 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6661 | if (tmp == NULL) goto failed; |
| 6662 | res = obj2ast_expr(tmp, &value, arena); |
| 6663 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6664 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6665 | } else { |
| 6666 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 6667 | return 1; |
| 6668 | } |
| 6669 | *out = Index(value, arena); |
| 6670 | if (*out == NULL) goto failed; |
| 6671 | return 0; |
| 6672 | } |
| 6673 | |
| 6674 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 6675 | failed: |
| 6676 | Py_XDECREF(tmp); |
| 6677 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6678 | } |
| 6679 | |
| 6680 | int |
| 6681 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 6682 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6683 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6684 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6685 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 6686 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6687 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6688 | } |
| 6689 | if (isinstance) { |
| 6690 | *out = And; |
| 6691 | return 0; |
| 6692 | } |
| 6693 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 6694 | if (isinstance == -1) { |
| 6695 | return 1; |
| 6696 | } |
| 6697 | if (isinstance) { |
| 6698 | *out = Or; |
| 6699 | return 0; |
| 6700 | } |
| 6701 | |
| 6702 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 6703 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6704 | } |
| 6705 | |
| 6706 | int |
| 6707 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 6708 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6709 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6710 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6711 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 6712 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6713 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6714 | } |
| 6715 | if (isinstance) { |
| 6716 | *out = Add; |
| 6717 | return 0; |
| 6718 | } |
| 6719 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 6720 | if (isinstance == -1) { |
| 6721 | return 1; |
| 6722 | } |
| 6723 | if (isinstance) { |
| 6724 | *out = Sub; |
| 6725 | return 0; |
| 6726 | } |
| 6727 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 6728 | if (isinstance == -1) { |
| 6729 | return 1; |
| 6730 | } |
| 6731 | if (isinstance) { |
| 6732 | *out = Mult; |
| 6733 | return 0; |
| 6734 | } |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 6735 | isinstance = PyObject_IsInstance(obj, (PyObject *)MatMult_type); |
| 6736 | if (isinstance == -1) { |
| 6737 | return 1; |
| 6738 | } |
| 6739 | if (isinstance) { |
| 6740 | *out = MatMult; |
| 6741 | return 0; |
| 6742 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6743 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 6744 | if (isinstance == -1) { |
| 6745 | return 1; |
| 6746 | } |
| 6747 | if (isinstance) { |
| 6748 | *out = Div; |
| 6749 | return 0; |
| 6750 | } |
| 6751 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 6752 | if (isinstance == -1) { |
| 6753 | return 1; |
| 6754 | } |
| 6755 | if (isinstance) { |
| 6756 | *out = Mod; |
| 6757 | return 0; |
| 6758 | } |
| 6759 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 6760 | if (isinstance == -1) { |
| 6761 | return 1; |
| 6762 | } |
| 6763 | if (isinstance) { |
| 6764 | *out = Pow; |
| 6765 | return 0; |
| 6766 | } |
| 6767 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 6768 | if (isinstance == -1) { |
| 6769 | return 1; |
| 6770 | } |
| 6771 | if (isinstance) { |
| 6772 | *out = LShift; |
| 6773 | return 0; |
| 6774 | } |
| 6775 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 6776 | if (isinstance == -1) { |
| 6777 | return 1; |
| 6778 | } |
| 6779 | if (isinstance) { |
| 6780 | *out = RShift; |
| 6781 | return 0; |
| 6782 | } |
| 6783 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 6784 | if (isinstance == -1) { |
| 6785 | return 1; |
| 6786 | } |
| 6787 | if (isinstance) { |
| 6788 | *out = BitOr; |
| 6789 | return 0; |
| 6790 | } |
| 6791 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 6792 | if (isinstance == -1) { |
| 6793 | return 1; |
| 6794 | } |
| 6795 | if (isinstance) { |
| 6796 | *out = BitXor; |
| 6797 | return 0; |
| 6798 | } |
| 6799 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 6800 | if (isinstance == -1) { |
| 6801 | return 1; |
| 6802 | } |
| 6803 | if (isinstance) { |
| 6804 | *out = BitAnd; |
| 6805 | return 0; |
| 6806 | } |
| 6807 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 6808 | if (isinstance == -1) { |
| 6809 | return 1; |
| 6810 | } |
| 6811 | if (isinstance) { |
| 6812 | *out = FloorDiv; |
| 6813 | return 0; |
| 6814 | } |
| 6815 | |
| 6816 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 6817 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6818 | } |
| 6819 | |
| 6820 | int |
| 6821 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 6822 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6823 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6824 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6825 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 6826 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6827 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6828 | } |
| 6829 | if (isinstance) { |
| 6830 | *out = Invert; |
| 6831 | return 0; |
| 6832 | } |
| 6833 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 6834 | if (isinstance == -1) { |
| 6835 | return 1; |
| 6836 | } |
| 6837 | if (isinstance) { |
| 6838 | *out = Not; |
| 6839 | return 0; |
| 6840 | } |
| 6841 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 6842 | if (isinstance == -1) { |
| 6843 | return 1; |
| 6844 | } |
| 6845 | if (isinstance) { |
| 6846 | *out = UAdd; |
| 6847 | return 0; |
| 6848 | } |
| 6849 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 6850 | if (isinstance == -1) { |
| 6851 | return 1; |
| 6852 | } |
| 6853 | if (isinstance) { |
| 6854 | *out = USub; |
| 6855 | return 0; |
| 6856 | } |
| 6857 | |
| 6858 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 6859 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6860 | } |
| 6861 | |
| 6862 | int |
| 6863 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 6864 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6865 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6866 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6867 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 6868 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6869 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6870 | } |
| 6871 | if (isinstance) { |
| 6872 | *out = Eq; |
| 6873 | return 0; |
| 6874 | } |
| 6875 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 6876 | if (isinstance == -1) { |
| 6877 | return 1; |
| 6878 | } |
| 6879 | if (isinstance) { |
| 6880 | *out = NotEq; |
| 6881 | return 0; |
| 6882 | } |
| 6883 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 6884 | if (isinstance == -1) { |
| 6885 | return 1; |
| 6886 | } |
| 6887 | if (isinstance) { |
| 6888 | *out = Lt; |
| 6889 | return 0; |
| 6890 | } |
| 6891 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 6892 | if (isinstance == -1) { |
| 6893 | return 1; |
| 6894 | } |
| 6895 | if (isinstance) { |
| 6896 | *out = LtE; |
| 6897 | return 0; |
| 6898 | } |
| 6899 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 6900 | if (isinstance == -1) { |
| 6901 | return 1; |
| 6902 | } |
| 6903 | if (isinstance) { |
| 6904 | *out = Gt; |
| 6905 | return 0; |
| 6906 | } |
| 6907 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 6908 | if (isinstance == -1) { |
| 6909 | return 1; |
| 6910 | } |
| 6911 | if (isinstance) { |
| 6912 | *out = GtE; |
| 6913 | return 0; |
| 6914 | } |
| 6915 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 6916 | if (isinstance == -1) { |
| 6917 | return 1; |
| 6918 | } |
| 6919 | if (isinstance) { |
| 6920 | *out = Is; |
| 6921 | return 0; |
| 6922 | } |
| 6923 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 6924 | if (isinstance == -1) { |
| 6925 | return 1; |
| 6926 | } |
| 6927 | if (isinstance) { |
| 6928 | *out = IsNot; |
| 6929 | return 0; |
| 6930 | } |
| 6931 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 6932 | if (isinstance == -1) { |
| 6933 | return 1; |
| 6934 | } |
| 6935 | if (isinstance) { |
| 6936 | *out = In; |
| 6937 | return 0; |
| 6938 | } |
| 6939 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 6940 | if (isinstance == -1) { |
| 6941 | return 1; |
| 6942 | } |
| 6943 | if (isinstance) { |
| 6944 | *out = NotIn; |
| 6945 | return 0; |
| 6946 | } |
| 6947 | |
| 6948 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 6949 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6950 | } |
| 6951 | |
| 6952 | int |
| 6953 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 6954 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6955 | PyObject* tmp = NULL; |
| 6956 | expr_ty target; |
| 6957 | expr_ty iter; |
| 6958 | asdl_seq* ifs; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6959 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6960 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
| 6961 | int res; |
| 6962 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 6963 | if (tmp == NULL) goto failed; |
| 6964 | res = obj2ast_expr(tmp, &target, arena); |
| 6965 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6966 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6967 | } else { |
| 6968 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6969 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6970 | } |
| 6971 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
| 6972 | int res; |
| 6973 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
| 6974 | if (tmp == NULL) goto failed; |
| 6975 | res = obj2ast_expr(tmp, &iter, arena); |
| 6976 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6977 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6978 | } else { |
| 6979 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 6980 | return 1; |
| 6981 | } |
| 6982 | if (_PyObject_HasAttrId(obj, &PyId_ifs)) { |
| 6983 | int res; |
| 6984 | Py_ssize_t len; |
| 6985 | Py_ssize_t i; |
| 6986 | tmp = _PyObject_GetAttrId(obj, &PyId_ifs); |
| 6987 | if (tmp == NULL) goto failed; |
| 6988 | if (!PyList_Check(tmp)) { |
| 6989 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6990 | goto failed; |
| 6991 | } |
| 6992 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6993 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6994 | if (ifs == NULL) goto failed; |
| 6995 | for (i = 0; i < len; i++) { |
| 6996 | expr_ty value; |
| 6997 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6998 | if (res != 0) goto failed; |
| 6999 | asdl_seq_SET(ifs, i, value); |
| 7000 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7001 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7002 | } else { |
| 7003 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 7004 | return 1; |
| 7005 | } |
| 7006 | *out = comprehension(target, iter, ifs, arena); |
| 7007 | return 0; |
| 7008 | failed: |
| 7009 | Py_XDECREF(tmp); |
| 7010 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7011 | } |
| 7012 | |
| 7013 | int |
| 7014 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 7015 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7016 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 7017 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7018 | PyObject *tmp = NULL; |
| 7019 | int lineno; |
| 7020 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7021 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7022 | if (obj == Py_None) { |
| 7023 | *out = NULL; |
| 7024 | return 0; |
| 7025 | } |
| 7026 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
| 7027 | int res; |
| 7028 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 7029 | if (tmp == NULL) goto failed; |
| 7030 | res = obj2ast_int(tmp, &lineno, arena); |
| 7031 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7032 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7033 | } else { |
| 7034 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7035 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7036 | } |
| 7037 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
| 7038 | int res; |
| 7039 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 7040 | if (tmp == NULL) goto failed; |
| 7041 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7042 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7043 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7044 | } else { |
| 7045 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 7046 | return 1; |
| 7047 | } |
| 7048 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 7049 | if (isinstance == -1) { |
| 7050 | return 1; |
| 7051 | } |
| 7052 | if (isinstance) { |
| 7053 | expr_ty type; |
| 7054 | identifier name; |
| 7055 | asdl_seq* body; |
| 7056 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7057 | if (exists_not_none(obj, &PyId_type)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7058 | int res; |
| 7059 | tmp = _PyObject_GetAttrId(obj, &PyId_type); |
| 7060 | if (tmp == NULL) goto failed; |
| 7061 | res = obj2ast_expr(tmp, &type, arena); |
| 7062 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7063 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7064 | } else { |
| 7065 | type = NULL; |
| 7066 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7067 | if (exists_not_none(obj, &PyId_name)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7068 | int res; |
| 7069 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 7070 | if (tmp == NULL) goto failed; |
| 7071 | res = obj2ast_identifier(tmp, &name, arena); |
| 7072 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7073 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7074 | } else { |
| 7075 | name = NULL; |
| 7076 | } |
| 7077 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 7078 | int res; |
| 7079 | Py_ssize_t len; |
| 7080 | Py_ssize_t i; |
| 7081 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 7082 | if (tmp == NULL) goto failed; |
| 7083 | if (!PyList_Check(tmp)) { |
| 7084 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7085 | goto failed; |
| 7086 | } |
| 7087 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7088 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7089 | if (body == NULL) goto failed; |
| 7090 | for (i = 0; i < len; i++) { |
| 7091 | stmt_ty value; |
| 7092 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 7093 | if (res != 0) goto failed; |
| 7094 | asdl_seq_SET(body, i, value); |
| 7095 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7096 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7097 | } else { |
| 7098 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 7099 | return 1; |
| 7100 | } |
| 7101 | *out = ExceptHandler(type, name, body, lineno, col_offset, arena); |
| 7102 | if (*out == NULL) goto failed; |
| 7103 | return 0; |
| 7104 | } |
| 7105 | |
| 7106 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 7107 | failed: |
| 7108 | Py_XDECREF(tmp); |
| 7109 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7110 | } |
| 7111 | |
| 7112 | int |
| 7113 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 7114 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7115 | PyObject* tmp = NULL; |
| 7116 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7117 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7118 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7119 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7120 | arg_ty kwarg; |
| 7121 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7122 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7123 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 7124 | int res; |
| 7125 | Py_ssize_t len; |
| 7126 | Py_ssize_t i; |
| 7127 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 7128 | if (tmp == NULL) goto failed; |
| 7129 | if (!PyList_Check(tmp)) { |
| 7130 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7131 | goto failed; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7132 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7133 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7134 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7135 | if (args == NULL) goto failed; |
| 7136 | for (i = 0; i < len; i++) { |
| 7137 | arg_ty value; |
| 7138 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 7139 | if (res != 0) goto failed; |
| 7140 | asdl_seq_SET(args, i, value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7141 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7142 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7143 | } else { |
| 7144 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7145 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7146 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7147 | if (exists_not_none(obj, &PyId_vararg)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7148 | int res; |
| 7149 | tmp = _PyObject_GetAttrId(obj, &PyId_vararg); |
| 7150 | if (tmp == NULL) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7151 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7152 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7153 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7154 | } else { |
| 7155 | vararg = NULL; |
| 7156 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7157 | if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) { |
| 7158 | int res; |
| 7159 | Py_ssize_t len; |
| 7160 | Py_ssize_t i; |
| 7161 | tmp = _PyObject_GetAttrId(obj, &PyId_kwonlyargs); |
| 7162 | if (tmp == NULL) goto failed; |
| 7163 | if (!PyList_Check(tmp)) { |
| 7164 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7165 | goto failed; |
| 7166 | } |
| 7167 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7168 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7169 | if (kwonlyargs == NULL) goto failed; |
| 7170 | for (i = 0; i < len; i++) { |
| 7171 | arg_ty value; |
| 7172 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 7173 | if (res != 0) goto failed; |
| 7174 | asdl_seq_SET(kwonlyargs, i, value); |
| 7175 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7176 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7177 | } else { |
| 7178 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 7179 | return 1; |
| 7180 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7181 | if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) { |
| 7182 | int res; |
| 7183 | Py_ssize_t len; |
| 7184 | Py_ssize_t i; |
| 7185 | tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults); |
| 7186 | if (tmp == NULL) goto failed; |
| 7187 | if (!PyList_Check(tmp)) { |
| 7188 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7189 | goto failed; |
| 7190 | } |
| 7191 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7192 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7193 | if (kw_defaults == NULL) goto failed; |
| 7194 | for (i = 0; i < len; i++) { |
| 7195 | expr_ty value; |
| 7196 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 7197 | if (res != 0) goto failed; |
| 7198 | asdl_seq_SET(kw_defaults, i, value); |
| 7199 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7200 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7201 | } else { |
| 7202 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 7203 | return 1; |
| 7204 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7205 | if (exists_not_none(obj, &PyId_kwarg)) { |
| 7206 | int res; |
| 7207 | tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); |
| 7208 | if (tmp == NULL) goto failed; |
| 7209 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 7210 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 7211 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7212 | } else { |
| 7213 | kwarg = NULL; |
| 7214 | } |
| 7215 | if (_PyObject_HasAttrId(obj, &PyId_defaults)) { |
| 7216 | int res; |
| 7217 | Py_ssize_t len; |
| 7218 | Py_ssize_t i; |
| 7219 | tmp = _PyObject_GetAttrId(obj, &PyId_defaults); |
| 7220 | if (tmp == NULL) goto failed; |
| 7221 | if (!PyList_Check(tmp)) { |
| 7222 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7223 | goto failed; |
| 7224 | } |
| 7225 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7226 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7227 | if (defaults == NULL) goto failed; |
| 7228 | for (i = 0; i < len; i++) { |
| 7229 | expr_ty value; |
| 7230 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 7231 | if (res != 0) goto failed; |
| 7232 | asdl_seq_SET(defaults, i, value); |
| 7233 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 7234 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7235 | } else { |
| 7236 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 7237 | return 1; |
| 7238 | } |
| 7239 | *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg, defaults, |
| 7240 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7241 | return 0; |
| 7242 | failed: |
| 7243 | Py_XDECREF(tmp); |
| 7244 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7245 | } |
| 7246 | |
| 7247 | int |
| 7248 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 7249 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7250 | PyObject* tmp = NULL; |
| 7251 | identifier arg; |
| 7252 | expr_ty annotation; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame^] | 7253 | int lineno; |
| 7254 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7255 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7256 | if (_PyObject_HasAttrId(obj, &PyId_arg)) { |
| 7257 | int res; |
| 7258 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
| 7259 | if (tmp == NULL) goto failed; |
| 7260 | res = obj2ast_identifier(tmp, &arg, arena); |
| 7261 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7262 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7263 | } else { |
| 7264 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7265 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7266 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7267 | if (exists_not_none(obj, &PyId_annotation)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7268 | int res; |
| 7269 | tmp = _PyObject_GetAttrId(obj, &PyId_annotation); |
| 7270 | if (tmp == NULL) goto failed; |
| 7271 | res = obj2ast_expr(tmp, &annotation, arena); |
| 7272 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7273 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7274 | } else { |
| 7275 | annotation = NULL; |
| 7276 | } |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame^] | 7277 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
| 7278 | int res; |
| 7279 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 7280 | if (tmp == NULL) goto failed; |
| 7281 | res = obj2ast_int(tmp, &lineno, arena); |
| 7282 | if (res != 0) goto failed; |
| 7283 | Py_CLEAR(tmp); |
| 7284 | } else { |
| 7285 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 7286 | return 1; |
| 7287 | } |
| 7288 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
| 7289 | int res; |
| 7290 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 7291 | if (tmp == NULL) goto failed; |
| 7292 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7293 | if (res != 0) goto failed; |
| 7294 | Py_CLEAR(tmp); |
| 7295 | } else { |
| 7296 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 7297 | return 1; |
| 7298 | } |
| 7299 | *out = arg(arg, annotation, lineno, col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7300 | return 0; |
| 7301 | failed: |
| 7302 | Py_XDECREF(tmp); |
| 7303 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7304 | } |
| 7305 | |
| 7306 | int |
| 7307 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 7308 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7309 | PyObject* tmp = NULL; |
| 7310 | identifier arg; |
| 7311 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7312 | |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 7313 | if (exists_not_none(obj, &PyId_arg)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7314 | int res; |
| 7315 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
| 7316 | if (tmp == NULL) goto failed; |
| 7317 | res = obj2ast_identifier(tmp, &arg, arena); |
| 7318 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7319 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7320 | } else { |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 7321 | arg = NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7322 | } |
| 7323 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 7324 | int res; |
| 7325 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 7326 | if (tmp == NULL) goto failed; |
| 7327 | res = obj2ast_expr(tmp, &value, arena); |
| 7328 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7329 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7330 | } else { |
| 7331 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 7332 | return 1; |
| 7333 | } |
| 7334 | *out = keyword(arg, value, arena); |
| 7335 | return 0; |
| 7336 | failed: |
| 7337 | Py_XDECREF(tmp); |
| 7338 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7339 | } |
| 7340 | |
| 7341 | int |
| 7342 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 7343 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7344 | PyObject* tmp = NULL; |
| 7345 | identifier name; |
| 7346 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7347 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7348 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
| 7349 | int res; |
| 7350 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 7351 | if (tmp == NULL) goto failed; |
| 7352 | res = obj2ast_identifier(tmp, &name, arena); |
| 7353 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7354 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7355 | } else { |
| 7356 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7357 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7358 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7359 | if (exists_not_none(obj, &PyId_asname)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7360 | int res; |
| 7361 | tmp = _PyObject_GetAttrId(obj, &PyId_asname); |
| 7362 | if (tmp == NULL) goto failed; |
| 7363 | res = obj2ast_identifier(tmp, &asname, arena); |
| 7364 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7365 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7366 | } else { |
| 7367 | asname = NULL; |
| 7368 | } |
| 7369 | *out = alias(name, asname, arena); |
| 7370 | return 0; |
| 7371 | failed: |
| 7372 | Py_XDECREF(tmp); |
| 7373 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7374 | } |
| 7375 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7376 | int |
| 7377 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 7378 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7379 | PyObject* tmp = NULL; |
| 7380 | expr_ty context_expr; |
| 7381 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7382 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7383 | if (_PyObject_HasAttrId(obj, &PyId_context_expr)) { |
| 7384 | int res; |
| 7385 | tmp = _PyObject_GetAttrId(obj, &PyId_context_expr); |
| 7386 | if (tmp == NULL) goto failed; |
| 7387 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 7388 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7389 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7390 | } else { |
| 7391 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7392 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7393 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7394 | if (exists_not_none(obj, &PyId_optional_vars)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7395 | int res; |
| 7396 | tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars); |
| 7397 | if (tmp == NULL) goto failed; |
| 7398 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 7399 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7400 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7401 | } else { |
| 7402 | optional_vars = NULL; |
| 7403 | } |
| 7404 | *out = withitem(context_expr, optional_vars, arena); |
| 7405 | return 0; |
| 7406 | failed: |
| 7407 | Py_XDECREF(tmp); |
| 7408 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7409 | } |
| 7410 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7411 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7412 | static struct PyModuleDef _astmodule = { |
| 7413 | PyModuleDef_HEAD_INIT, "_ast" |
| 7414 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 7415 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7416 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 7417 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7418 | PyObject *m, *d; |
| 7419 | if (!init_types()) return NULL; |
| 7420 | m = PyModule_Create(&_astmodule); |
| 7421 | if (!m) return NULL; |
| 7422 | d = PyModule_GetDict(m); |
| 7423 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7424 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7425 | return NULL; |
| 7426 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; |
| 7427 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return |
| 7428 | NULL; |
| 7429 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) < |
| 7430 | 0) return NULL; |
| 7431 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0) |
| 7432 | return NULL; |
| 7433 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 7434 | NULL; |
| 7435 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL; |
| 7436 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) < |
| 7437 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7438 | if (PyDict_SetItemString(d, "AsyncFunctionDef", |
| 7439 | (PyObject*)AsyncFunctionDef_type) < 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7440 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 7441 | return NULL; |
| 7442 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return |
| 7443 | NULL; |
| 7444 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return |
| 7445 | NULL; |
| 7446 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return |
| 7447 | NULL; |
| 7448 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0) |
| 7449 | return NULL; |
| 7450 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7451 | if (PyDict_SetItemString(d, "AsyncFor", (PyObject*)AsyncFor_type) < 0) |
| 7452 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7453 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 7454 | NULL; |
| 7455 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 7456 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7457 | if (PyDict_SetItemString(d, "AsyncWith", (PyObject*)AsyncWith_type) < 0) |
| 7458 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7459 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 7460 | NULL; |
| 7461 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL; |
| 7462 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return |
| 7463 | NULL; |
| 7464 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return |
| 7465 | NULL; |
| 7466 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0) |
| 7467 | return NULL; |
| 7468 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return |
| 7469 | NULL; |
| 7470 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
| 7471 | return NULL; |
| 7472 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL; |
| 7473 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL; |
| 7474 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 7475 | NULL; |
| 7476 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 7477 | return NULL; |
| 7478 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL; |
| 7479 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return |
| 7480 | NULL; |
| 7481 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 7482 | NULL; |
| 7483 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return |
| 7484 | NULL; |
| 7485 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return |
| 7486 | NULL; |
| 7487 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 7488 | NULL; |
| 7489 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL; |
| 7490 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL; |
| 7491 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 7492 | return NULL; |
| 7493 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return |
| 7494 | NULL; |
| 7495 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
| 7496 | return NULL; |
| 7497 | if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) < |
| 7498 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7499 | if (PyDict_SetItemString(d, "Await", (PyObject*)Await_type) < 0) return |
| 7500 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7501 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 7502 | NULL; |
| 7503 | if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0) |
| 7504 | return NULL; |
| 7505 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return |
| 7506 | NULL; |
| 7507 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL; |
| 7508 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return NULL; |
| 7509 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return NULL; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 7510 | if (PyDict_SetItemString(d, "FormattedValue", |
| 7511 | (PyObject*)FormattedValue_type) < 0) return NULL; |
| 7512 | if (PyDict_SetItemString(d, "JoinedStr", (PyObject*)JoinedStr_type) < 0) |
| 7513 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7514 | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return |
| 7515 | NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7516 | if (PyDict_SetItemString(d, "NameConstant", (PyObject*)NameConstant_type) < |
| 7517 | 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7518 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
| 7519 | return NULL; |
| 7520 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0) |
| 7521 | return NULL; |
| 7522 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0) |
| 7523 | return NULL; |
| 7524 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return |
| 7525 | NULL; |
| 7526 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL; |
| 7527 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL; |
| 7528 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 7529 | NULL; |
| 7530 | if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) < |
| 7531 | 0) return NULL; |
| 7532 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL; |
| 7533 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 7534 | NULL; |
| 7535 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL; |
| 7536 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return |
| 7537 | NULL; |
| 7538 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 7539 | return NULL; |
| 7540 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 7541 | NULL; |
| 7542 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 7543 | NULL; |
| 7544 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 7545 | NULL; |
| 7546 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 7547 | return NULL; |
| 7548 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 7549 | NULL; |
| 7550 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return |
| 7551 | NULL; |
| 7552 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL; |
| 7553 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
| 7554 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 7555 | return NULL; |
| 7556 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL; |
| 7557 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL; |
| 7558 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 7559 | if (PyDict_SetItemString(d, "MatMult", (PyObject*)MatMult_type) < 0) return |
| 7560 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7561 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL; |
| 7562 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL; |
| 7563 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL; |
| 7564 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return |
| 7565 | NULL; |
| 7566 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return |
| 7567 | NULL; |
| 7568 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 7569 | NULL; |
| 7570 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return |
| 7571 | NULL; |
| 7572 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return |
| 7573 | NULL; |
| 7574 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 7575 | return NULL; |
| 7576 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return |
| 7577 | NULL; |
| 7578 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return |
| 7579 | NULL; |
| 7580 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL; |
| 7581 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL; |
| 7582 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL; |
| 7583 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 7584 | NULL; |
| 7585 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 7586 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 7587 | NULL; |
| 7588 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 7589 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL; |
| 7590 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 7591 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL; |
| 7592 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 7593 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 7594 | NULL; |
| 7595 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 7596 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 7597 | NULL; |
| 7598 | if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type) |
| 7599 | < 0) return NULL; |
| 7600 | if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type) |
| 7601 | < 0) return NULL; |
| 7602 | if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type) |
| 7603 | < 0) return NULL; |
| 7604 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0) |
| 7605 | return NULL; |
| 7606 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL; |
| 7607 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return |
| 7608 | NULL; |
| 7609 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 7610 | NULL; |
| 7611 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 7612 | return NULL; |
| 7613 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 7614 | } |
| 7615 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7616 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7617 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7618 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 7619 | if (!init_types()) |
| 7620 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7621 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7622 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7623 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7624 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 7625 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7626 | { |
| 7627 | mod_ty res; |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 7628 | PyObject *req_type[3]; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7629 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7630 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 7631 | |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 7632 | req_type[0] = (PyObject*)Module_type; |
| 7633 | req_type[1] = (PyObject*)Expression_type; |
| 7634 | req_type[2] = (PyObject*)Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 7635 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7636 | assert(0 <= mode && mode <= 2); |
| 7637 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 7638 | if (!init_types()) |
| 7639 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7640 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7641 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 7642 | if (isinstance == -1) |
| 7643 | return NULL; |
| 7644 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7645 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 7646 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7647 | return NULL; |
| 7648 | } |
| 7649 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 7650 | return NULL; |
| 7651 | else |
| 7652 | return res; |
| 7653 | } |
| 7654 | |
| 7655 | int PyAST_Check(PyObject* obj) |
| 7656 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 7657 | if (!init_types()) |
| 7658 | return -1; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 7659 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7660 | } |
| 7661 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7662 | |