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 |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 2428 | arg(identifier arg, expr_ty annotation, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2429 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2430 | arg_ty p; |
| 2431 | if (!arg) { |
| 2432 | PyErr_SetString(PyExc_ValueError, |
| 2433 | "field arg is required for arg"); |
| 2434 | return NULL; |
| 2435 | } |
| 2436 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2437 | if (!p) |
| 2438 | return NULL; |
| 2439 | p->arg = arg; |
| 2440 | p->annotation = annotation; |
| 2441 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 2442 | } |
| 2443 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2444 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2445 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2446 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2447 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2448 | if (!value) { |
| 2449 | PyErr_SetString(PyExc_ValueError, |
| 2450 | "field value is required for keyword"); |
| 2451 | return NULL; |
| 2452 | } |
| 2453 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2454 | if (!p) |
| 2455 | return NULL; |
| 2456 | p->arg = arg; |
| 2457 | p->value = value; |
| 2458 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2459 | } |
| 2460 | |
| 2461 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2462 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2463 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2464 | alias_ty p; |
| 2465 | if (!name) { |
| 2466 | PyErr_SetString(PyExc_ValueError, |
| 2467 | "field name is required for alias"); |
| 2468 | return NULL; |
| 2469 | } |
| 2470 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2471 | if (!p) |
| 2472 | return NULL; |
| 2473 | p->name = name; |
| 2474 | p->asname = asname; |
| 2475 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2476 | } |
| 2477 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2478 | withitem_ty |
| 2479 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 2480 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2481 | withitem_ty p; |
| 2482 | if (!context_expr) { |
| 2483 | PyErr_SetString(PyExc_ValueError, |
| 2484 | "field context_expr is required for withitem"); |
| 2485 | return NULL; |
| 2486 | } |
| 2487 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2488 | if (!p) |
| 2489 | return NULL; |
| 2490 | p->context_expr = context_expr; |
| 2491 | p->optional_vars = optional_vars; |
| 2492 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2493 | } |
| 2494 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2495 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2496 | PyObject* |
| 2497 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2498 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2499 | mod_ty o = (mod_ty)_o; |
| 2500 | PyObject *result = NULL, *value = NULL; |
| 2501 | if (!o) { |
| 2502 | Py_INCREF(Py_None); |
| 2503 | return Py_None; |
| 2504 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2505 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2506 | switch (o->kind) { |
| 2507 | case Module_kind: |
| 2508 | result = PyType_GenericNew(Module_type, NULL, NULL); |
| 2509 | if (!result) goto failed; |
| 2510 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 2511 | if (!value) goto failed; |
| 2512 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2513 | goto failed; |
| 2514 | Py_DECREF(value); |
| 2515 | break; |
| 2516 | case Interactive_kind: |
| 2517 | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
| 2518 | if (!result) goto failed; |
| 2519 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 2520 | if (!value) goto failed; |
| 2521 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2522 | goto failed; |
| 2523 | Py_DECREF(value); |
| 2524 | break; |
| 2525 | case Expression_kind: |
| 2526 | result = PyType_GenericNew(Expression_type, NULL, NULL); |
| 2527 | if (!result) goto failed; |
| 2528 | value = ast2obj_expr(o->v.Expression.body); |
| 2529 | if (!value) goto failed; |
| 2530 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2531 | goto failed; |
| 2532 | Py_DECREF(value); |
| 2533 | break; |
| 2534 | case Suite_kind: |
| 2535 | result = PyType_GenericNew(Suite_type, NULL, NULL); |
| 2536 | if (!result) goto failed; |
| 2537 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 2538 | if (!value) goto failed; |
| 2539 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2540 | goto failed; |
| 2541 | Py_DECREF(value); |
| 2542 | break; |
| 2543 | } |
| 2544 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2545 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2546 | Py_XDECREF(value); |
| 2547 | Py_XDECREF(result); |
| 2548 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2549 | } |
| 2550 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2551 | PyObject* |
| 2552 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2553 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2554 | stmt_ty o = (stmt_ty)_o; |
| 2555 | PyObject *result = NULL, *value = NULL; |
| 2556 | if (!o) { |
| 2557 | Py_INCREF(Py_None); |
| 2558 | return Py_None; |
| 2559 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2560 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2561 | switch (o->kind) { |
| 2562 | case FunctionDef_kind: |
| 2563 | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
| 2564 | if (!result) goto failed; |
| 2565 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 2566 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2567 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2568 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2569 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2570 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2571 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2572 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2573 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 2574 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2575 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 2576 | if (!value) goto failed; |
| 2577 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2578 | goto failed; |
| 2579 | Py_DECREF(value); |
| 2580 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 2581 | if (!value) goto failed; |
| 2582 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2583 | goto failed; |
| 2584 | Py_DECREF(value); |
| 2585 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 2586 | if (!value) goto failed; |
| 2587 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2588 | goto failed; |
| 2589 | Py_DECREF(value); |
| 2590 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2591 | case AsyncFunctionDef_kind: |
| 2592 | result = PyType_GenericNew(AsyncFunctionDef_type, NULL, NULL); |
| 2593 | if (!result) goto failed; |
| 2594 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 2595 | if (!value) goto failed; |
| 2596 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2597 | goto failed; |
| 2598 | Py_DECREF(value); |
| 2599 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 2600 | if (!value) goto failed; |
| 2601 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 2602 | goto failed; |
| 2603 | Py_DECREF(value); |
| 2604 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 2605 | if (!value) goto failed; |
| 2606 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2607 | goto failed; |
| 2608 | Py_DECREF(value); |
| 2609 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 2610 | ast2obj_expr); |
| 2611 | if (!value) goto failed; |
| 2612 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2613 | goto failed; |
| 2614 | Py_DECREF(value); |
| 2615 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 2616 | if (!value) goto failed; |
| 2617 | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
| 2618 | goto failed; |
| 2619 | Py_DECREF(value); |
| 2620 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2621 | case ClassDef_kind: |
| 2622 | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
| 2623 | if (!result) goto failed; |
| 2624 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 2625 | if (!value) goto failed; |
| 2626 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 2627 | goto failed; |
| 2628 | Py_DECREF(value); |
| 2629 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 2630 | if (!value) goto failed; |
| 2631 | if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) |
| 2632 | goto failed; |
| 2633 | Py_DECREF(value); |
| 2634 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 2635 | if (!value) goto failed; |
| 2636 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 2637 | goto failed; |
| 2638 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2639 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 2640 | if (!value) goto failed; |
| 2641 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2642 | goto failed; |
| 2643 | Py_DECREF(value); |
| 2644 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 2645 | if (!value) goto failed; |
| 2646 | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
| 2647 | goto failed; |
| 2648 | Py_DECREF(value); |
| 2649 | break; |
| 2650 | case Return_kind: |
| 2651 | result = PyType_GenericNew(Return_type, NULL, NULL); |
| 2652 | if (!result) goto failed; |
| 2653 | value = ast2obj_expr(o->v.Return.value); |
| 2654 | if (!value) goto failed; |
| 2655 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2656 | goto failed; |
| 2657 | Py_DECREF(value); |
| 2658 | break; |
| 2659 | case Delete_kind: |
| 2660 | result = PyType_GenericNew(Delete_type, NULL, NULL); |
| 2661 | if (!result) goto failed; |
| 2662 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 2663 | if (!value) goto failed; |
| 2664 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2665 | goto failed; |
| 2666 | Py_DECREF(value); |
| 2667 | break; |
| 2668 | case Assign_kind: |
| 2669 | result = PyType_GenericNew(Assign_type, NULL, NULL); |
| 2670 | if (!result) goto failed; |
| 2671 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 2672 | if (!value) goto failed; |
| 2673 | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
| 2674 | goto failed; |
| 2675 | Py_DECREF(value); |
| 2676 | value = ast2obj_expr(o->v.Assign.value); |
| 2677 | if (!value) goto failed; |
| 2678 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2679 | goto failed; |
| 2680 | Py_DECREF(value); |
| 2681 | break; |
| 2682 | case AugAssign_kind: |
| 2683 | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
| 2684 | if (!result) goto failed; |
| 2685 | value = ast2obj_expr(o->v.AugAssign.target); |
| 2686 | if (!value) goto failed; |
| 2687 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2688 | goto failed; |
| 2689 | Py_DECREF(value); |
| 2690 | value = ast2obj_operator(o->v.AugAssign.op); |
| 2691 | if (!value) goto failed; |
| 2692 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2693 | goto failed; |
| 2694 | Py_DECREF(value); |
| 2695 | value = ast2obj_expr(o->v.AugAssign.value); |
| 2696 | if (!value) goto failed; |
| 2697 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2698 | goto failed; |
| 2699 | Py_DECREF(value); |
| 2700 | break; |
| 2701 | case For_kind: |
| 2702 | result = PyType_GenericNew(For_type, NULL, NULL); |
| 2703 | if (!result) goto failed; |
| 2704 | value = ast2obj_expr(o->v.For.target); |
| 2705 | if (!value) goto failed; |
| 2706 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2707 | goto failed; |
| 2708 | Py_DECREF(value); |
| 2709 | value = ast2obj_expr(o->v.For.iter); |
| 2710 | if (!value) goto failed; |
| 2711 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2712 | goto failed; |
| 2713 | Py_DECREF(value); |
| 2714 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 2715 | if (!value) goto failed; |
| 2716 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2717 | goto failed; |
| 2718 | Py_DECREF(value); |
| 2719 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 2720 | if (!value) goto failed; |
| 2721 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2722 | goto failed; |
| 2723 | Py_DECREF(value); |
| 2724 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2725 | case AsyncFor_kind: |
| 2726 | result = PyType_GenericNew(AsyncFor_type, NULL, NULL); |
| 2727 | if (!result) goto failed; |
| 2728 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 2729 | if (!value) goto failed; |
| 2730 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 2731 | goto failed; |
| 2732 | Py_DECREF(value); |
| 2733 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 2734 | if (!value) goto failed; |
| 2735 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 2736 | goto failed; |
| 2737 | Py_DECREF(value); |
| 2738 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 2739 | if (!value) goto failed; |
| 2740 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2741 | goto failed; |
| 2742 | Py_DECREF(value); |
| 2743 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 2744 | if (!value) goto failed; |
| 2745 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2746 | goto failed; |
| 2747 | Py_DECREF(value); |
| 2748 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2749 | case While_kind: |
| 2750 | result = PyType_GenericNew(While_type, NULL, NULL); |
| 2751 | if (!result) goto failed; |
| 2752 | value = ast2obj_expr(o->v.While.test); |
| 2753 | if (!value) goto failed; |
| 2754 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2755 | goto failed; |
| 2756 | Py_DECREF(value); |
| 2757 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 2758 | if (!value) goto failed; |
| 2759 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2760 | goto failed; |
| 2761 | Py_DECREF(value); |
| 2762 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 2763 | if (!value) goto failed; |
| 2764 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2765 | goto failed; |
| 2766 | Py_DECREF(value); |
| 2767 | break; |
| 2768 | case If_kind: |
| 2769 | result = PyType_GenericNew(If_type, NULL, NULL); |
| 2770 | if (!result) goto failed; |
| 2771 | value = ast2obj_expr(o->v.If.test); |
| 2772 | if (!value) goto failed; |
| 2773 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2774 | goto failed; |
| 2775 | Py_DECREF(value); |
| 2776 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 2777 | if (!value) goto failed; |
| 2778 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2779 | goto failed; |
| 2780 | Py_DECREF(value); |
| 2781 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 2782 | if (!value) goto failed; |
| 2783 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2784 | goto failed; |
| 2785 | Py_DECREF(value); |
| 2786 | break; |
| 2787 | case With_kind: |
| 2788 | result = PyType_GenericNew(With_type, NULL, NULL); |
| 2789 | if (!result) goto failed; |
| 2790 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 2791 | if (!value) goto failed; |
| 2792 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 2793 | goto failed; |
| 2794 | Py_DECREF(value); |
| 2795 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 2796 | if (!value) goto failed; |
| 2797 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2798 | goto failed; |
| 2799 | Py_DECREF(value); |
| 2800 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2801 | case AsyncWith_kind: |
| 2802 | result = PyType_GenericNew(AsyncWith_type, NULL, NULL); |
| 2803 | if (!result) goto failed; |
| 2804 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 2805 | if (!value) goto failed; |
| 2806 | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
| 2807 | goto failed; |
| 2808 | Py_DECREF(value); |
| 2809 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 2810 | if (!value) goto failed; |
| 2811 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2812 | goto failed; |
| 2813 | Py_DECREF(value); |
| 2814 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2815 | case Raise_kind: |
| 2816 | result = PyType_GenericNew(Raise_type, NULL, NULL); |
| 2817 | if (!result) goto failed; |
| 2818 | value = ast2obj_expr(o->v.Raise.exc); |
| 2819 | if (!value) goto failed; |
| 2820 | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
| 2821 | goto failed; |
| 2822 | Py_DECREF(value); |
| 2823 | value = ast2obj_expr(o->v.Raise.cause); |
| 2824 | if (!value) goto failed; |
| 2825 | if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) |
| 2826 | goto failed; |
| 2827 | Py_DECREF(value); |
| 2828 | break; |
| 2829 | case Try_kind: |
| 2830 | result = PyType_GenericNew(Try_type, NULL, NULL); |
| 2831 | if (!result) goto failed; |
| 2832 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 2833 | if (!value) goto failed; |
| 2834 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 2835 | goto failed; |
| 2836 | Py_DECREF(value); |
| 2837 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 2838 | if (!value) goto failed; |
| 2839 | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
| 2840 | goto failed; |
| 2841 | Py_DECREF(value); |
| 2842 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 2843 | if (!value) goto failed; |
| 2844 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 2845 | goto failed; |
| 2846 | Py_DECREF(value); |
| 2847 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 2848 | if (!value) goto failed; |
| 2849 | if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) |
| 2850 | goto failed; |
| 2851 | Py_DECREF(value); |
| 2852 | break; |
| 2853 | case Assert_kind: |
| 2854 | result = PyType_GenericNew(Assert_type, NULL, NULL); |
| 2855 | if (!result) goto failed; |
| 2856 | value = ast2obj_expr(o->v.Assert.test); |
| 2857 | if (!value) goto failed; |
| 2858 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 2859 | goto failed; |
| 2860 | Py_DECREF(value); |
| 2861 | value = ast2obj_expr(o->v.Assert.msg); |
| 2862 | if (!value) goto failed; |
| 2863 | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
| 2864 | goto failed; |
| 2865 | Py_DECREF(value); |
| 2866 | break; |
| 2867 | case Import_kind: |
| 2868 | result = PyType_GenericNew(Import_type, NULL, NULL); |
| 2869 | if (!result) goto failed; |
| 2870 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 2871 | if (!value) goto failed; |
| 2872 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2873 | goto failed; |
| 2874 | Py_DECREF(value); |
| 2875 | break; |
| 2876 | case ImportFrom_kind: |
| 2877 | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
| 2878 | if (!result) goto failed; |
| 2879 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 2880 | if (!value) goto failed; |
| 2881 | if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) |
| 2882 | goto failed; |
| 2883 | Py_DECREF(value); |
| 2884 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 2885 | if (!value) goto failed; |
| 2886 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2887 | goto failed; |
| 2888 | Py_DECREF(value); |
| 2889 | value = ast2obj_int(o->v.ImportFrom.level); |
| 2890 | if (!value) goto failed; |
| 2891 | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
| 2892 | goto failed; |
| 2893 | Py_DECREF(value); |
| 2894 | break; |
| 2895 | case Global_kind: |
| 2896 | result = PyType_GenericNew(Global_type, NULL, NULL); |
| 2897 | if (!result) goto failed; |
| 2898 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 2899 | if (!value) goto failed; |
| 2900 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2901 | goto failed; |
| 2902 | Py_DECREF(value); |
| 2903 | break; |
| 2904 | case Nonlocal_kind: |
| 2905 | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
| 2906 | if (!result) goto failed; |
| 2907 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 2908 | if (!value) goto failed; |
| 2909 | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
| 2910 | goto failed; |
| 2911 | Py_DECREF(value); |
| 2912 | break; |
| 2913 | case Expr_kind: |
| 2914 | result = PyType_GenericNew(Expr_type, NULL, NULL); |
| 2915 | if (!result) goto failed; |
| 2916 | value = ast2obj_expr(o->v.Expr.value); |
| 2917 | if (!value) goto failed; |
| 2918 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2919 | goto failed; |
| 2920 | Py_DECREF(value); |
| 2921 | break; |
| 2922 | case Pass_kind: |
| 2923 | result = PyType_GenericNew(Pass_type, NULL, NULL); |
| 2924 | if (!result) goto failed; |
| 2925 | break; |
| 2926 | case Break_kind: |
| 2927 | result = PyType_GenericNew(Break_type, NULL, NULL); |
| 2928 | if (!result) goto failed; |
| 2929 | break; |
| 2930 | case Continue_kind: |
| 2931 | result = PyType_GenericNew(Continue_type, NULL, NULL); |
| 2932 | if (!result) goto failed; |
| 2933 | break; |
| 2934 | } |
| 2935 | value = ast2obj_int(o->lineno); |
| 2936 | if (!value) goto failed; |
| 2937 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 2938 | goto failed; |
| 2939 | Py_DECREF(value); |
| 2940 | value = ast2obj_int(o->col_offset); |
| 2941 | if (!value) goto failed; |
| 2942 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 2943 | goto failed; |
| 2944 | Py_DECREF(value); |
| 2945 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2946 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2947 | Py_XDECREF(value); |
| 2948 | Py_XDECREF(result); |
| 2949 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2950 | } |
| 2951 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2952 | PyObject* |
| 2953 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2954 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2955 | expr_ty o = (expr_ty)_o; |
| 2956 | PyObject *result = NULL, *value = NULL; |
| 2957 | if (!o) { |
| 2958 | Py_INCREF(Py_None); |
| 2959 | return Py_None; |
| 2960 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2961 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2962 | switch (o->kind) { |
| 2963 | case BoolOp_kind: |
| 2964 | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
| 2965 | if (!result) goto failed; |
| 2966 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 2967 | if (!value) goto failed; |
| 2968 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2969 | goto failed; |
| 2970 | Py_DECREF(value); |
| 2971 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 2972 | if (!value) goto failed; |
| 2973 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 2974 | goto failed; |
| 2975 | Py_DECREF(value); |
| 2976 | break; |
| 2977 | case BinOp_kind: |
| 2978 | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
| 2979 | if (!result) goto failed; |
| 2980 | value = ast2obj_expr(o->v.BinOp.left); |
| 2981 | if (!value) goto failed; |
| 2982 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 2983 | goto failed; |
| 2984 | Py_DECREF(value); |
| 2985 | value = ast2obj_operator(o->v.BinOp.op); |
| 2986 | if (!value) goto failed; |
| 2987 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 2988 | goto failed; |
| 2989 | Py_DECREF(value); |
| 2990 | value = ast2obj_expr(o->v.BinOp.right); |
| 2991 | if (!value) goto failed; |
| 2992 | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
| 2993 | goto failed; |
| 2994 | Py_DECREF(value); |
| 2995 | break; |
| 2996 | case UnaryOp_kind: |
| 2997 | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
| 2998 | if (!result) goto failed; |
| 2999 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 3000 | if (!value) goto failed; |
| 3001 | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
| 3002 | goto failed; |
| 3003 | Py_DECREF(value); |
| 3004 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 3005 | if (!value) goto failed; |
| 3006 | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
| 3007 | goto failed; |
| 3008 | Py_DECREF(value); |
| 3009 | break; |
| 3010 | case Lambda_kind: |
| 3011 | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
| 3012 | if (!result) goto failed; |
| 3013 | value = ast2obj_arguments(o->v.Lambda.args); |
| 3014 | if (!value) goto failed; |
| 3015 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3016 | goto failed; |
| 3017 | Py_DECREF(value); |
| 3018 | value = ast2obj_expr(o->v.Lambda.body); |
| 3019 | if (!value) goto failed; |
| 3020 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3021 | goto failed; |
| 3022 | Py_DECREF(value); |
| 3023 | break; |
| 3024 | case IfExp_kind: |
| 3025 | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
| 3026 | if (!result) goto failed; |
| 3027 | value = ast2obj_expr(o->v.IfExp.test); |
| 3028 | if (!value) goto failed; |
| 3029 | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
| 3030 | goto failed; |
| 3031 | Py_DECREF(value); |
| 3032 | value = ast2obj_expr(o->v.IfExp.body); |
| 3033 | if (!value) goto failed; |
| 3034 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3035 | goto failed; |
| 3036 | Py_DECREF(value); |
| 3037 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 3038 | if (!value) goto failed; |
| 3039 | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
| 3040 | goto failed; |
| 3041 | Py_DECREF(value); |
| 3042 | break; |
| 3043 | case Dict_kind: |
| 3044 | result = PyType_GenericNew(Dict_type, NULL, NULL); |
| 3045 | if (!result) goto failed; |
| 3046 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 3047 | if (!value) goto failed; |
| 3048 | if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) |
| 3049 | goto failed; |
| 3050 | Py_DECREF(value); |
| 3051 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 3052 | if (!value) goto failed; |
| 3053 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3054 | goto failed; |
| 3055 | Py_DECREF(value); |
| 3056 | break; |
| 3057 | case Set_kind: |
| 3058 | result = PyType_GenericNew(Set_type, NULL, NULL); |
| 3059 | if (!result) goto failed; |
| 3060 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 3061 | if (!value) goto failed; |
| 3062 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3063 | goto failed; |
| 3064 | Py_DECREF(value); |
| 3065 | break; |
| 3066 | case ListComp_kind: |
| 3067 | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 3068 | if (!result) goto failed; |
| 3069 | value = ast2obj_expr(o->v.ListComp.elt); |
| 3070 | if (!value) goto failed; |
| 3071 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3072 | goto failed; |
| 3073 | Py_DECREF(value); |
| 3074 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 3075 | if (!value) goto failed; |
| 3076 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3077 | goto failed; |
| 3078 | Py_DECREF(value); |
| 3079 | break; |
| 3080 | case SetComp_kind: |
| 3081 | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
| 3082 | if (!result) goto failed; |
| 3083 | value = ast2obj_expr(o->v.SetComp.elt); |
| 3084 | if (!value) goto failed; |
| 3085 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3086 | goto failed; |
| 3087 | Py_DECREF(value); |
| 3088 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 3089 | if (!value) goto failed; |
| 3090 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3091 | goto failed; |
| 3092 | Py_DECREF(value); |
| 3093 | break; |
| 3094 | case DictComp_kind: |
| 3095 | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
| 3096 | if (!result) goto failed; |
| 3097 | value = ast2obj_expr(o->v.DictComp.key); |
| 3098 | if (!value) goto failed; |
| 3099 | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
| 3100 | goto failed; |
| 3101 | Py_DECREF(value); |
| 3102 | value = ast2obj_expr(o->v.DictComp.value); |
| 3103 | if (!value) goto failed; |
| 3104 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3105 | goto failed; |
| 3106 | Py_DECREF(value); |
| 3107 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 3108 | if (!value) goto failed; |
| 3109 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3110 | goto failed; |
| 3111 | Py_DECREF(value); |
| 3112 | break; |
| 3113 | case GeneratorExp_kind: |
| 3114 | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
| 3115 | if (!result) goto failed; |
| 3116 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 3117 | if (!value) goto failed; |
| 3118 | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
| 3119 | goto failed; |
| 3120 | Py_DECREF(value); |
| 3121 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 3122 | ast2obj_comprehension); |
| 3123 | if (!value) goto failed; |
| 3124 | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
| 3125 | goto failed; |
| 3126 | Py_DECREF(value); |
| 3127 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3128 | case Await_kind: |
| 3129 | result = PyType_GenericNew(Await_type, NULL, NULL); |
| 3130 | if (!result) goto failed; |
| 3131 | value = ast2obj_expr(o->v.Await.value); |
| 3132 | if (!value) goto failed; |
| 3133 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3134 | goto failed; |
| 3135 | Py_DECREF(value); |
| 3136 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3137 | case Yield_kind: |
| 3138 | result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 3139 | if (!result) goto failed; |
| 3140 | value = ast2obj_expr(o->v.Yield.value); |
| 3141 | if (!value) goto failed; |
| 3142 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3143 | goto failed; |
| 3144 | Py_DECREF(value); |
| 3145 | break; |
| 3146 | case YieldFrom_kind: |
| 3147 | result = PyType_GenericNew(YieldFrom_type, NULL, NULL); |
| 3148 | if (!result) goto failed; |
| 3149 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 3150 | if (!value) goto failed; |
| 3151 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3152 | goto failed; |
| 3153 | Py_DECREF(value); |
| 3154 | break; |
| 3155 | case Compare_kind: |
| 3156 | result = PyType_GenericNew(Compare_type, NULL, NULL); |
| 3157 | if (!result) goto failed; |
| 3158 | value = ast2obj_expr(o->v.Compare.left); |
| 3159 | if (!value) goto failed; |
| 3160 | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
| 3161 | goto failed; |
| 3162 | Py_DECREF(value); |
| 3163 | { |
| 3164 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 3165 | value = PyList_New(n); |
| 3166 | if (!value) goto failed; |
| 3167 | for(i = 0; i < n; i++) |
| 3168 | 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] | 3169 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3170 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3171 | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
| 3172 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3173 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3174 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3175 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3176 | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
| 3177 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3178 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3179 | break; |
| 3180 | case Call_kind: |
| 3181 | result = PyType_GenericNew(Call_type, NULL, NULL); |
| 3182 | if (!result) goto failed; |
| 3183 | value = ast2obj_expr(o->v.Call.func); |
| 3184 | if (!value) goto failed; |
| 3185 | if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) |
| 3186 | goto failed; |
| 3187 | Py_DECREF(value); |
| 3188 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 3189 | if (!value) goto failed; |
| 3190 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3191 | goto failed; |
| 3192 | Py_DECREF(value); |
| 3193 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 3194 | if (!value) goto failed; |
| 3195 | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
| 3196 | goto failed; |
| 3197 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3198 | break; |
| 3199 | case Num_kind: |
| 3200 | result = PyType_GenericNew(Num_type, NULL, NULL); |
| 3201 | if (!result) goto failed; |
| 3202 | value = ast2obj_object(o->v.Num.n); |
| 3203 | if (!value) goto failed; |
| 3204 | if (_PyObject_SetAttrId(result, &PyId_n, value) == -1) |
| 3205 | goto failed; |
| 3206 | Py_DECREF(value); |
| 3207 | break; |
| 3208 | case Str_kind: |
| 3209 | result = PyType_GenericNew(Str_type, NULL, NULL); |
| 3210 | if (!result) goto failed; |
| 3211 | value = ast2obj_string(o->v.Str.s); |
| 3212 | if (!value) goto failed; |
| 3213 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
| 3214 | goto failed; |
| 3215 | Py_DECREF(value); |
| 3216 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame^] | 3217 | case FormattedValue_kind: |
| 3218 | result = PyType_GenericNew(FormattedValue_type, NULL, NULL); |
| 3219 | if (!result) goto failed; |
| 3220 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 3221 | if (!value) goto failed; |
| 3222 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3223 | goto failed; |
| 3224 | Py_DECREF(value); |
| 3225 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 3226 | if (!value) goto failed; |
| 3227 | if (_PyObject_SetAttrId(result, &PyId_conversion, value) == -1) |
| 3228 | goto failed; |
| 3229 | Py_DECREF(value); |
| 3230 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 3231 | if (!value) goto failed; |
| 3232 | if (_PyObject_SetAttrId(result, &PyId_format_spec, value) == -1) |
| 3233 | goto failed; |
| 3234 | Py_DECREF(value); |
| 3235 | break; |
| 3236 | case JoinedStr_kind: |
| 3237 | result = PyType_GenericNew(JoinedStr_type, NULL, NULL); |
| 3238 | if (!result) goto failed; |
| 3239 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 3240 | if (!value) goto failed; |
| 3241 | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
| 3242 | goto failed; |
| 3243 | Py_DECREF(value); |
| 3244 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3245 | case Bytes_kind: |
| 3246 | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
| 3247 | if (!result) goto failed; |
| 3248 | value = ast2obj_bytes(o->v.Bytes.s); |
| 3249 | if (!value) goto failed; |
| 3250 | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
| 3251 | goto failed; |
| 3252 | Py_DECREF(value); |
| 3253 | break; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3254 | case NameConstant_kind: |
| 3255 | result = PyType_GenericNew(NameConstant_type, NULL, NULL); |
| 3256 | if (!result) goto failed; |
| 3257 | value = ast2obj_singleton(o->v.NameConstant.value); |
| 3258 | if (!value) goto failed; |
| 3259 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3260 | goto failed; |
| 3261 | Py_DECREF(value); |
| 3262 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3263 | case Ellipsis_kind: |
| 3264 | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
| 3265 | if (!result) goto failed; |
| 3266 | break; |
| 3267 | case Attribute_kind: |
| 3268 | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
| 3269 | if (!result) goto failed; |
| 3270 | value = ast2obj_expr(o->v.Attribute.value); |
| 3271 | if (!value) goto failed; |
| 3272 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3273 | goto failed; |
| 3274 | Py_DECREF(value); |
| 3275 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 3276 | if (!value) goto failed; |
| 3277 | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
| 3278 | goto failed; |
| 3279 | Py_DECREF(value); |
| 3280 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 3281 | if (!value) goto failed; |
| 3282 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3283 | goto failed; |
| 3284 | Py_DECREF(value); |
| 3285 | break; |
| 3286 | case Subscript_kind: |
| 3287 | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
| 3288 | if (!result) goto failed; |
| 3289 | value = ast2obj_expr(o->v.Subscript.value); |
| 3290 | if (!value) goto failed; |
| 3291 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3292 | goto failed; |
| 3293 | Py_DECREF(value); |
| 3294 | value = ast2obj_slice(o->v.Subscript.slice); |
| 3295 | if (!value) goto failed; |
| 3296 | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
| 3297 | goto failed; |
| 3298 | Py_DECREF(value); |
| 3299 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 3300 | if (!value) goto failed; |
| 3301 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3302 | goto failed; |
| 3303 | Py_DECREF(value); |
| 3304 | break; |
| 3305 | case Starred_kind: |
| 3306 | result = PyType_GenericNew(Starred_type, NULL, NULL); |
| 3307 | if (!result) goto failed; |
| 3308 | value = ast2obj_expr(o->v.Starred.value); |
| 3309 | if (!value) goto failed; |
| 3310 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3311 | goto failed; |
| 3312 | Py_DECREF(value); |
| 3313 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 3314 | if (!value) goto failed; |
| 3315 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3316 | goto failed; |
| 3317 | Py_DECREF(value); |
| 3318 | break; |
| 3319 | case Name_kind: |
| 3320 | result = PyType_GenericNew(Name_type, NULL, NULL); |
| 3321 | if (!result) goto failed; |
| 3322 | value = ast2obj_identifier(o->v.Name.id); |
| 3323 | if (!value) goto failed; |
| 3324 | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
| 3325 | goto failed; |
| 3326 | Py_DECREF(value); |
| 3327 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 3328 | if (!value) goto failed; |
| 3329 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3330 | goto failed; |
| 3331 | Py_DECREF(value); |
| 3332 | break; |
| 3333 | case List_kind: |
| 3334 | result = PyType_GenericNew(List_type, NULL, NULL); |
| 3335 | if (!result) goto failed; |
| 3336 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 3337 | if (!value) goto failed; |
| 3338 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3339 | goto failed; |
| 3340 | Py_DECREF(value); |
| 3341 | value = ast2obj_expr_context(o->v.List.ctx); |
| 3342 | if (!value) goto failed; |
| 3343 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3344 | goto failed; |
| 3345 | Py_DECREF(value); |
| 3346 | break; |
| 3347 | case Tuple_kind: |
| 3348 | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
| 3349 | if (!result) goto failed; |
| 3350 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 3351 | if (!value) goto failed; |
| 3352 | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
| 3353 | goto failed; |
| 3354 | Py_DECREF(value); |
| 3355 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 3356 | if (!value) goto failed; |
| 3357 | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
| 3358 | goto failed; |
| 3359 | Py_DECREF(value); |
| 3360 | break; |
| 3361 | } |
| 3362 | value = ast2obj_int(o->lineno); |
| 3363 | if (!value) goto failed; |
| 3364 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3365 | goto failed; |
| 3366 | Py_DECREF(value); |
| 3367 | value = ast2obj_int(o->col_offset); |
| 3368 | if (!value) goto failed; |
| 3369 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3370 | goto failed; |
| 3371 | Py_DECREF(value); |
| 3372 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3373 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3374 | Py_XDECREF(value); |
| 3375 | Py_XDECREF(result); |
| 3376 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3377 | } |
| 3378 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3379 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3380 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3381 | switch(o) { |
| 3382 | case Load: |
| 3383 | Py_INCREF(Load_singleton); |
| 3384 | return Load_singleton; |
| 3385 | case Store: |
| 3386 | Py_INCREF(Store_singleton); |
| 3387 | return Store_singleton; |
| 3388 | case Del: |
| 3389 | Py_INCREF(Del_singleton); |
| 3390 | return Del_singleton; |
| 3391 | case AugLoad: |
| 3392 | Py_INCREF(AugLoad_singleton); |
| 3393 | return AugLoad_singleton; |
| 3394 | case AugStore: |
| 3395 | Py_INCREF(AugStore_singleton); |
| 3396 | return AugStore_singleton; |
| 3397 | case Param: |
| 3398 | Py_INCREF(Param_singleton); |
| 3399 | return Param_singleton; |
| 3400 | default: |
| 3401 | /* should never happen, but just in case ... */ |
| 3402 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 3403 | return NULL; |
| 3404 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3405 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3406 | PyObject* |
| 3407 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3408 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3409 | slice_ty o = (slice_ty)_o; |
| 3410 | PyObject *result = NULL, *value = NULL; |
| 3411 | if (!o) { |
| 3412 | Py_INCREF(Py_None); |
| 3413 | return Py_None; |
| 3414 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3415 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3416 | switch (o->kind) { |
| 3417 | case Slice_kind: |
| 3418 | result = PyType_GenericNew(Slice_type, NULL, NULL); |
| 3419 | if (!result) goto failed; |
| 3420 | value = ast2obj_expr(o->v.Slice.lower); |
| 3421 | if (!value) goto failed; |
| 3422 | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
| 3423 | goto failed; |
| 3424 | Py_DECREF(value); |
| 3425 | value = ast2obj_expr(o->v.Slice.upper); |
| 3426 | if (!value) goto failed; |
| 3427 | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
| 3428 | goto failed; |
| 3429 | Py_DECREF(value); |
| 3430 | value = ast2obj_expr(o->v.Slice.step); |
| 3431 | if (!value) goto failed; |
| 3432 | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
| 3433 | goto failed; |
| 3434 | Py_DECREF(value); |
| 3435 | break; |
| 3436 | case ExtSlice_kind: |
| 3437 | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
| 3438 | if (!result) goto failed; |
| 3439 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 3440 | if (!value) goto failed; |
| 3441 | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
| 3442 | goto failed; |
| 3443 | Py_DECREF(value); |
| 3444 | break; |
| 3445 | case Index_kind: |
| 3446 | result = PyType_GenericNew(Index_type, NULL, NULL); |
| 3447 | if (!result) goto failed; |
| 3448 | value = ast2obj_expr(o->v.Index.value); |
| 3449 | if (!value) goto failed; |
| 3450 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3451 | goto failed; |
| 3452 | Py_DECREF(value); |
| 3453 | break; |
| 3454 | } |
| 3455 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3456 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3457 | Py_XDECREF(value); |
| 3458 | Py_XDECREF(result); |
| 3459 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3460 | } |
| 3461 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3462 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3463 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3464 | switch(o) { |
| 3465 | case And: |
| 3466 | Py_INCREF(And_singleton); |
| 3467 | return And_singleton; |
| 3468 | case Or: |
| 3469 | Py_INCREF(Or_singleton); |
| 3470 | return Or_singleton; |
| 3471 | default: |
| 3472 | /* should never happen, but just in case ... */ |
| 3473 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 3474 | return NULL; |
| 3475 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3476 | } |
| 3477 | PyObject* ast2obj_operator(operator_ty o) |
| 3478 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3479 | switch(o) { |
| 3480 | case Add: |
| 3481 | Py_INCREF(Add_singleton); |
| 3482 | return Add_singleton; |
| 3483 | case Sub: |
| 3484 | Py_INCREF(Sub_singleton); |
| 3485 | return Sub_singleton; |
| 3486 | case Mult: |
| 3487 | Py_INCREF(Mult_singleton); |
| 3488 | return Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 3489 | case MatMult: |
| 3490 | Py_INCREF(MatMult_singleton); |
| 3491 | return MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3492 | case Div: |
| 3493 | Py_INCREF(Div_singleton); |
| 3494 | return Div_singleton; |
| 3495 | case Mod: |
| 3496 | Py_INCREF(Mod_singleton); |
| 3497 | return Mod_singleton; |
| 3498 | case Pow: |
| 3499 | Py_INCREF(Pow_singleton); |
| 3500 | return Pow_singleton; |
| 3501 | case LShift: |
| 3502 | Py_INCREF(LShift_singleton); |
| 3503 | return LShift_singleton; |
| 3504 | case RShift: |
| 3505 | Py_INCREF(RShift_singleton); |
| 3506 | return RShift_singleton; |
| 3507 | case BitOr: |
| 3508 | Py_INCREF(BitOr_singleton); |
| 3509 | return BitOr_singleton; |
| 3510 | case BitXor: |
| 3511 | Py_INCREF(BitXor_singleton); |
| 3512 | return BitXor_singleton; |
| 3513 | case BitAnd: |
| 3514 | Py_INCREF(BitAnd_singleton); |
| 3515 | return BitAnd_singleton; |
| 3516 | case FloorDiv: |
| 3517 | Py_INCREF(FloorDiv_singleton); |
| 3518 | return FloorDiv_singleton; |
| 3519 | default: |
| 3520 | /* should never happen, but just in case ... */ |
| 3521 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 3522 | return NULL; |
| 3523 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3524 | } |
| 3525 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 3526 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3527 | switch(o) { |
| 3528 | case Invert: |
| 3529 | Py_INCREF(Invert_singleton); |
| 3530 | return Invert_singleton; |
| 3531 | case Not: |
| 3532 | Py_INCREF(Not_singleton); |
| 3533 | return Not_singleton; |
| 3534 | case UAdd: |
| 3535 | Py_INCREF(UAdd_singleton); |
| 3536 | return UAdd_singleton; |
| 3537 | case USub: |
| 3538 | Py_INCREF(USub_singleton); |
| 3539 | return USub_singleton; |
| 3540 | default: |
| 3541 | /* should never happen, but just in case ... */ |
| 3542 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 3543 | return NULL; |
| 3544 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3545 | } |
| 3546 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 3547 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3548 | switch(o) { |
| 3549 | case Eq: |
| 3550 | Py_INCREF(Eq_singleton); |
| 3551 | return Eq_singleton; |
| 3552 | case NotEq: |
| 3553 | Py_INCREF(NotEq_singleton); |
| 3554 | return NotEq_singleton; |
| 3555 | case Lt: |
| 3556 | Py_INCREF(Lt_singleton); |
| 3557 | return Lt_singleton; |
| 3558 | case LtE: |
| 3559 | Py_INCREF(LtE_singleton); |
| 3560 | return LtE_singleton; |
| 3561 | case Gt: |
| 3562 | Py_INCREF(Gt_singleton); |
| 3563 | return Gt_singleton; |
| 3564 | case GtE: |
| 3565 | Py_INCREF(GtE_singleton); |
| 3566 | return GtE_singleton; |
| 3567 | case Is: |
| 3568 | Py_INCREF(Is_singleton); |
| 3569 | return Is_singleton; |
| 3570 | case IsNot: |
| 3571 | Py_INCREF(IsNot_singleton); |
| 3572 | return IsNot_singleton; |
| 3573 | case In: |
| 3574 | Py_INCREF(In_singleton); |
| 3575 | return In_singleton; |
| 3576 | case NotIn: |
| 3577 | Py_INCREF(NotIn_singleton); |
| 3578 | return NotIn_singleton; |
| 3579 | default: |
| 3580 | /* should never happen, but just in case ... */ |
| 3581 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 3582 | return NULL; |
| 3583 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3584 | } |
| 3585 | PyObject* |
| 3586 | ast2obj_comprehension(void* _o) |
| 3587 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3588 | comprehension_ty o = (comprehension_ty)_o; |
| 3589 | PyObject *result = NULL, *value = NULL; |
| 3590 | if (!o) { |
| 3591 | Py_INCREF(Py_None); |
| 3592 | return Py_None; |
| 3593 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3594 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3595 | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
| 3596 | if (!result) return NULL; |
| 3597 | value = ast2obj_expr(o->target); |
| 3598 | if (!value) goto failed; |
| 3599 | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
| 3600 | goto failed; |
| 3601 | Py_DECREF(value); |
| 3602 | value = ast2obj_expr(o->iter); |
| 3603 | if (!value) goto failed; |
| 3604 | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
| 3605 | goto failed; |
| 3606 | Py_DECREF(value); |
| 3607 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 3608 | if (!value) goto failed; |
| 3609 | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
| 3610 | goto failed; |
| 3611 | Py_DECREF(value); |
| 3612 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3613 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3614 | Py_XDECREF(value); |
| 3615 | Py_XDECREF(result); |
| 3616 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3617 | } |
| 3618 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3619 | PyObject* |
| 3620 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3621 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3622 | excepthandler_ty o = (excepthandler_ty)_o; |
| 3623 | PyObject *result = NULL, *value = NULL; |
| 3624 | if (!o) { |
| 3625 | Py_INCREF(Py_None); |
| 3626 | return Py_None; |
| 3627 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3628 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3629 | switch (o->kind) { |
| 3630 | case ExceptHandler_kind: |
| 3631 | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
| 3632 | if (!result) goto failed; |
| 3633 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3634 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3635 | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
| 3636 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3637 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3638 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3639 | if (!value) goto failed; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3640 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3641 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3642 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3643 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 3644 | if (!value) goto failed; |
| 3645 | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
| 3646 | goto failed; |
| 3647 | Py_DECREF(value); |
| 3648 | break; |
| 3649 | } |
| 3650 | value = ast2obj_int(o->lineno); |
| 3651 | if (!value) goto failed; |
| 3652 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3653 | goto failed; |
| 3654 | Py_DECREF(value); |
| 3655 | value = ast2obj_int(o->col_offset); |
| 3656 | if (!value) goto failed; |
| 3657 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3658 | goto failed; |
| 3659 | Py_DECREF(value); |
| 3660 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3661 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3662 | Py_XDECREF(value); |
| 3663 | Py_XDECREF(result); |
| 3664 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3665 | } |
| 3666 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3667 | PyObject* |
| 3668 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3669 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3670 | arguments_ty o = (arguments_ty)_o; |
| 3671 | PyObject *result = NULL, *value = NULL; |
| 3672 | if (!o) { |
| 3673 | Py_INCREF(Py_None); |
| 3674 | return Py_None; |
| 3675 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3676 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3677 | result = PyType_GenericNew(arguments_type, NULL, NULL); |
| 3678 | if (!result) return NULL; |
| 3679 | value = ast2obj_list(o->args, ast2obj_arg); |
| 3680 | if (!value) goto failed; |
| 3681 | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
| 3682 | goto failed; |
| 3683 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3684 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3685 | if (!value) goto failed; |
| 3686 | if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) |
| 3687 | goto failed; |
| 3688 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3689 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 3690 | if (!value) goto failed; |
| 3691 | if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) |
| 3692 | goto failed; |
| 3693 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3694 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3695 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3696 | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3697 | goto failed; |
| 3698 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3699 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3700 | if (!value) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3701 | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3702 | goto failed; |
| 3703 | Py_DECREF(value); |
| 3704 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 3705 | if (!value) goto failed; |
| 3706 | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
| 3707 | goto failed; |
| 3708 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3709 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3710 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3711 | Py_XDECREF(value); |
| 3712 | Py_XDECREF(result); |
| 3713 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3714 | } |
| 3715 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3716 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3717 | ast2obj_arg(void* _o) |
| 3718 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3719 | arg_ty o = (arg_ty)_o; |
| 3720 | PyObject *result = NULL, *value = NULL; |
| 3721 | if (!o) { |
| 3722 | Py_INCREF(Py_None); |
| 3723 | return Py_None; |
| 3724 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3725 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3726 | result = PyType_GenericNew(arg_type, NULL, NULL); |
| 3727 | if (!result) return NULL; |
| 3728 | value = ast2obj_identifier(o->arg); |
| 3729 | if (!value) goto failed; |
| 3730 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 3731 | goto failed; |
| 3732 | Py_DECREF(value); |
| 3733 | value = ast2obj_expr(o->annotation); |
| 3734 | if (!value) goto failed; |
| 3735 | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
| 3736 | goto failed; |
| 3737 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3738 | value = ast2obj_int(o->lineno); |
| 3739 | if (!value) goto failed; |
| 3740 | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
| 3741 | goto failed; |
| 3742 | Py_DECREF(value); |
| 3743 | value = ast2obj_int(o->col_offset); |
| 3744 | if (!value) goto failed; |
| 3745 | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
| 3746 | goto failed; |
| 3747 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3748 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3749 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3750 | Py_XDECREF(value); |
| 3751 | Py_XDECREF(result); |
| 3752 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3753 | } |
| 3754 | |
| 3755 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3756 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3757 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3758 | keyword_ty o = (keyword_ty)_o; |
| 3759 | PyObject *result = NULL, *value = NULL; |
| 3760 | if (!o) { |
| 3761 | Py_INCREF(Py_None); |
| 3762 | return Py_None; |
| 3763 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3764 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3765 | result = PyType_GenericNew(keyword_type, NULL, NULL); |
| 3766 | if (!result) return NULL; |
| 3767 | value = ast2obj_identifier(o->arg); |
| 3768 | if (!value) goto failed; |
| 3769 | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
| 3770 | goto failed; |
| 3771 | Py_DECREF(value); |
| 3772 | value = ast2obj_expr(o->value); |
| 3773 | if (!value) goto failed; |
| 3774 | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 3775 | goto failed; |
| 3776 | Py_DECREF(value); |
| 3777 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3778 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3779 | Py_XDECREF(value); |
| 3780 | Py_XDECREF(result); |
| 3781 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3782 | } |
| 3783 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3784 | PyObject* |
| 3785 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3786 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3787 | alias_ty o = (alias_ty)_o; |
| 3788 | PyObject *result = NULL, *value = NULL; |
| 3789 | if (!o) { |
| 3790 | Py_INCREF(Py_None); |
| 3791 | return Py_None; |
| 3792 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3793 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3794 | result = PyType_GenericNew(alias_type, NULL, NULL); |
| 3795 | if (!result) return NULL; |
| 3796 | value = ast2obj_identifier(o->name); |
| 3797 | if (!value) goto failed; |
| 3798 | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
| 3799 | goto failed; |
| 3800 | Py_DECREF(value); |
| 3801 | value = ast2obj_identifier(o->asname); |
| 3802 | if (!value) goto failed; |
| 3803 | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
| 3804 | goto failed; |
| 3805 | Py_DECREF(value); |
| 3806 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3807 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3808 | Py_XDECREF(value); |
| 3809 | Py_XDECREF(result); |
| 3810 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3811 | } |
| 3812 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3813 | PyObject* |
| 3814 | ast2obj_withitem(void* _o) |
| 3815 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3816 | withitem_ty o = (withitem_ty)_o; |
| 3817 | PyObject *result = NULL, *value = NULL; |
| 3818 | if (!o) { |
| 3819 | Py_INCREF(Py_None); |
| 3820 | return Py_None; |
| 3821 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3822 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3823 | result = PyType_GenericNew(withitem_type, NULL, NULL); |
| 3824 | if (!result) return NULL; |
| 3825 | value = ast2obj_expr(o->context_expr); |
| 3826 | if (!value) goto failed; |
| 3827 | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
| 3828 | goto failed; |
| 3829 | Py_DECREF(value); |
| 3830 | value = ast2obj_expr(o->optional_vars); |
| 3831 | if (!value) goto failed; |
| 3832 | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
| 3833 | goto failed; |
| 3834 | Py_DECREF(value); |
| 3835 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3836 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3837 | Py_XDECREF(value); |
| 3838 | Py_XDECREF(result); |
| 3839 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3840 | } |
| 3841 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3842 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3843 | int |
| 3844 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 3845 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3846 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3847 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3848 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3849 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3850 | if (obj == Py_None) { |
| 3851 | *out = NULL; |
| 3852 | return 0; |
| 3853 | } |
| 3854 | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
| 3855 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3856 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3857 | } |
| 3858 | if (isinstance) { |
| 3859 | asdl_seq* body; |
| 3860 | |
| 3861 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3862 | int res; |
| 3863 | Py_ssize_t len; |
| 3864 | Py_ssize_t i; |
| 3865 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 3866 | if (tmp == NULL) goto failed; |
| 3867 | if (!PyList_Check(tmp)) { |
| 3868 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3869 | goto failed; |
| 3870 | } |
| 3871 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3872 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3873 | if (body == NULL) goto failed; |
| 3874 | for (i = 0; i < len; i++) { |
| 3875 | stmt_ty value; |
| 3876 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3877 | if (res != 0) goto failed; |
| 3878 | asdl_seq_SET(body, i, value); |
| 3879 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3880 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3881 | } else { |
| 3882 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 3883 | return 1; |
| 3884 | } |
| 3885 | *out = Module(body, arena); |
| 3886 | if (*out == NULL) goto failed; |
| 3887 | return 0; |
| 3888 | } |
| 3889 | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
| 3890 | if (isinstance == -1) { |
| 3891 | return 1; |
| 3892 | } |
| 3893 | if (isinstance) { |
| 3894 | asdl_seq* body; |
| 3895 | |
| 3896 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3897 | int res; |
| 3898 | Py_ssize_t len; |
| 3899 | Py_ssize_t i; |
| 3900 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 3901 | if (tmp == NULL) goto failed; |
| 3902 | if (!PyList_Check(tmp)) { |
| 3903 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3904 | goto failed; |
| 3905 | } |
| 3906 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3907 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3908 | if (body == NULL) goto failed; |
| 3909 | for (i = 0; i < len; i++) { |
| 3910 | stmt_ty value; |
| 3911 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3912 | if (res != 0) goto failed; |
| 3913 | asdl_seq_SET(body, i, value); |
| 3914 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3915 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3916 | } else { |
| 3917 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 3918 | return 1; |
| 3919 | } |
| 3920 | *out = Interactive(body, arena); |
| 3921 | if (*out == NULL) goto failed; |
| 3922 | return 0; |
| 3923 | } |
| 3924 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
| 3925 | if (isinstance == -1) { |
| 3926 | return 1; |
| 3927 | } |
| 3928 | if (isinstance) { |
| 3929 | expr_ty body; |
| 3930 | |
| 3931 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3932 | int res; |
| 3933 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 3934 | if (tmp == NULL) goto failed; |
| 3935 | res = obj2ast_expr(tmp, &body, arena); |
| 3936 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3937 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3938 | } else { |
| 3939 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 3940 | return 1; |
| 3941 | } |
| 3942 | *out = Expression(body, arena); |
| 3943 | if (*out == NULL) goto failed; |
| 3944 | return 0; |
| 3945 | } |
| 3946 | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
| 3947 | if (isinstance == -1) { |
| 3948 | return 1; |
| 3949 | } |
| 3950 | if (isinstance) { |
| 3951 | asdl_seq* body; |
| 3952 | |
| 3953 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 3954 | int res; |
| 3955 | Py_ssize_t len; |
| 3956 | Py_ssize_t i; |
| 3957 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 3958 | if (tmp == NULL) goto failed; |
| 3959 | if (!PyList_Check(tmp)) { |
| 3960 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 3961 | goto failed; |
| 3962 | } |
| 3963 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 3964 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3965 | if (body == NULL) goto failed; |
| 3966 | for (i = 0; i < len; i++) { |
| 3967 | stmt_ty value; |
| 3968 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 3969 | if (res != 0) goto failed; |
| 3970 | asdl_seq_SET(body, i, value); |
| 3971 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 3972 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3973 | } else { |
| 3974 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 3975 | return 1; |
| 3976 | } |
| 3977 | *out = Suite(body, arena); |
| 3978 | if (*out == NULL) goto failed; |
| 3979 | return 0; |
| 3980 | } |
| 3981 | |
| 3982 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 3983 | failed: |
| 3984 | Py_XDECREF(tmp); |
| 3985 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3986 | } |
| 3987 | |
| 3988 | int |
| 3989 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 3990 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3991 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3992 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3993 | PyObject *tmp = NULL; |
| 3994 | int lineno; |
| 3995 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 3996 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3997 | if (obj == Py_None) { |
| 3998 | *out = NULL; |
| 3999 | return 0; |
| 4000 | } |
| 4001 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
| 4002 | int res; |
| 4003 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 4004 | if (tmp == NULL) goto failed; |
| 4005 | res = obj2ast_int(tmp, &lineno, arena); |
| 4006 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4007 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4008 | } else { |
| 4009 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4010 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4011 | } |
| 4012 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
| 4013 | int res; |
| 4014 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 4015 | if (tmp == NULL) goto failed; |
| 4016 | res = obj2ast_int(tmp, &col_offset, arena); |
| 4017 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4018 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4019 | } else { |
| 4020 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 4021 | return 1; |
| 4022 | } |
| 4023 | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
| 4024 | if (isinstance == -1) { |
| 4025 | return 1; |
| 4026 | } |
| 4027 | if (isinstance) { |
| 4028 | identifier name; |
| 4029 | arguments_ty args; |
| 4030 | asdl_seq* body; |
| 4031 | asdl_seq* decorator_list; |
| 4032 | expr_ty returns; |
| 4033 | |
| 4034 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
| 4035 | int res; |
| 4036 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 4037 | if (tmp == NULL) goto failed; |
| 4038 | res = obj2ast_identifier(tmp, &name, arena); |
| 4039 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4040 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4041 | } else { |
| 4042 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 4043 | return 1; |
| 4044 | } |
| 4045 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 4046 | int res; |
| 4047 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 4048 | if (tmp == NULL) goto failed; |
| 4049 | res = obj2ast_arguments(tmp, &args, arena); |
| 4050 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4051 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4052 | } else { |
| 4053 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 4054 | return 1; |
| 4055 | } |
| 4056 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4057 | int res; |
| 4058 | Py_ssize_t len; |
| 4059 | Py_ssize_t i; |
| 4060 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4061 | if (tmp == NULL) goto failed; |
| 4062 | if (!PyList_Check(tmp)) { |
| 4063 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4064 | goto failed; |
| 4065 | } |
| 4066 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4067 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4068 | if (body == NULL) goto failed; |
| 4069 | for (i = 0; i < len; i++) { |
| 4070 | stmt_ty value; |
| 4071 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4072 | if (res != 0) goto failed; |
| 4073 | asdl_seq_SET(body, i, value); |
| 4074 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4075 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4076 | } else { |
| 4077 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 4078 | return 1; |
| 4079 | } |
| 4080 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
| 4081 | int res; |
| 4082 | Py_ssize_t len; |
| 4083 | Py_ssize_t i; |
| 4084 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
| 4085 | if (tmp == NULL) goto failed; |
| 4086 | if (!PyList_Check(tmp)) { |
| 4087 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4088 | goto failed; |
| 4089 | } |
| 4090 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4091 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4092 | if (decorator_list == NULL) goto failed; |
| 4093 | for (i = 0; i < len; i++) { |
| 4094 | expr_ty value; |
| 4095 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4096 | if (res != 0) goto failed; |
| 4097 | asdl_seq_SET(decorator_list, i, value); |
| 4098 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4099 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4100 | } else { |
| 4101 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 4102 | return 1; |
| 4103 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4104 | if (exists_not_none(obj, &PyId_returns)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4105 | int res; |
| 4106 | tmp = _PyObject_GetAttrId(obj, &PyId_returns); |
| 4107 | if (tmp == NULL) goto failed; |
| 4108 | res = obj2ast_expr(tmp, &returns, arena); |
| 4109 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4110 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4111 | } else { |
| 4112 | returns = NULL; |
| 4113 | } |
| 4114 | *out = FunctionDef(name, args, body, decorator_list, returns, lineno, |
| 4115 | col_offset, arena); |
| 4116 | if (*out == NULL) goto failed; |
| 4117 | return 0; |
| 4118 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4119 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFunctionDef_type); |
| 4120 | if (isinstance == -1) { |
| 4121 | return 1; |
| 4122 | } |
| 4123 | if (isinstance) { |
| 4124 | identifier name; |
| 4125 | arguments_ty args; |
| 4126 | asdl_seq* body; |
| 4127 | asdl_seq* decorator_list; |
| 4128 | expr_ty returns; |
| 4129 | |
| 4130 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
| 4131 | int res; |
| 4132 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 4133 | if (tmp == NULL) goto failed; |
| 4134 | res = obj2ast_identifier(tmp, &name, arena); |
| 4135 | if (res != 0) goto failed; |
| 4136 | Py_CLEAR(tmp); |
| 4137 | } else { |
| 4138 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 4139 | return 1; |
| 4140 | } |
| 4141 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 4142 | int res; |
| 4143 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 4144 | if (tmp == NULL) goto failed; |
| 4145 | res = obj2ast_arguments(tmp, &args, arena); |
| 4146 | if (res != 0) goto failed; |
| 4147 | Py_CLEAR(tmp); |
| 4148 | } else { |
| 4149 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 4150 | return 1; |
| 4151 | } |
| 4152 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4153 | int res; |
| 4154 | Py_ssize_t len; |
| 4155 | Py_ssize_t i; |
| 4156 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4157 | if (tmp == NULL) goto failed; |
| 4158 | if (!PyList_Check(tmp)) { |
| 4159 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4160 | goto failed; |
| 4161 | } |
| 4162 | len = PyList_GET_SIZE(tmp); |
| 4163 | body = _Py_asdl_seq_new(len, arena); |
| 4164 | if (body == NULL) goto failed; |
| 4165 | for (i = 0; i < len; i++) { |
| 4166 | stmt_ty value; |
| 4167 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4168 | if (res != 0) goto failed; |
| 4169 | asdl_seq_SET(body, i, value); |
| 4170 | } |
| 4171 | Py_CLEAR(tmp); |
| 4172 | } else { |
| 4173 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 4174 | return 1; |
| 4175 | } |
| 4176 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
| 4177 | int res; |
| 4178 | Py_ssize_t len; |
| 4179 | Py_ssize_t i; |
| 4180 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
| 4181 | if (tmp == NULL) goto failed; |
| 4182 | if (!PyList_Check(tmp)) { |
| 4183 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4184 | goto failed; |
| 4185 | } |
| 4186 | len = PyList_GET_SIZE(tmp); |
| 4187 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 4188 | if (decorator_list == NULL) goto failed; |
| 4189 | for (i = 0; i < len; i++) { |
| 4190 | expr_ty value; |
| 4191 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4192 | if (res != 0) goto failed; |
| 4193 | asdl_seq_SET(decorator_list, i, value); |
| 4194 | } |
| 4195 | Py_CLEAR(tmp); |
| 4196 | } else { |
| 4197 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 4198 | return 1; |
| 4199 | } |
| 4200 | if (exists_not_none(obj, &PyId_returns)) { |
| 4201 | int res; |
| 4202 | tmp = _PyObject_GetAttrId(obj, &PyId_returns); |
| 4203 | if (tmp == NULL) goto failed; |
| 4204 | res = obj2ast_expr(tmp, &returns, arena); |
| 4205 | if (res != 0) goto failed; |
| 4206 | Py_CLEAR(tmp); |
| 4207 | } else { |
| 4208 | returns = NULL; |
| 4209 | } |
| 4210 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
| 4211 | lineno, col_offset, arena); |
| 4212 | if (*out == NULL) goto failed; |
| 4213 | return 0; |
| 4214 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4215 | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
| 4216 | if (isinstance == -1) { |
| 4217 | return 1; |
| 4218 | } |
| 4219 | if (isinstance) { |
| 4220 | identifier name; |
| 4221 | asdl_seq* bases; |
| 4222 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4223 | asdl_seq* body; |
| 4224 | asdl_seq* decorator_list; |
| 4225 | |
| 4226 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
| 4227 | int res; |
| 4228 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 4229 | if (tmp == NULL) goto failed; |
| 4230 | res = obj2ast_identifier(tmp, &name, arena); |
| 4231 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4232 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4233 | } else { |
| 4234 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 4235 | return 1; |
| 4236 | } |
| 4237 | if (_PyObject_HasAttrId(obj, &PyId_bases)) { |
| 4238 | int res; |
| 4239 | Py_ssize_t len; |
| 4240 | Py_ssize_t i; |
| 4241 | tmp = _PyObject_GetAttrId(obj, &PyId_bases); |
| 4242 | if (tmp == NULL) goto failed; |
| 4243 | if (!PyList_Check(tmp)) { |
| 4244 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4245 | goto failed; |
| 4246 | } |
| 4247 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4248 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4249 | if (bases == NULL) goto failed; |
| 4250 | for (i = 0; i < len; i++) { |
| 4251 | expr_ty value; |
| 4252 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4253 | if (res != 0) goto failed; |
| 4254 | asdl_seq_SET(bases, i, value); |
| 4255 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4256 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4257 | } else { |
| 4258 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 4259 | return 1; |
| 4260 | } |
| 4261 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
| 4262 | int res; |
| 4263 | Py_ssize_t len; |
| 4264 | Py_ssize_t i; |
| 4265 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
| 4266 | if (tmp == NULL) goto failed; |
| 4267 | if (!PyList_Check(tmp)) { |
| 4268 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4269 | goto failed; |
| 4270 | } |
| 4271 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4272 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4273 | if (keywords == NULL) goto failed; |
| 4274 | for (i = 0; i < len; i++) { |
| 4275 | keyword_ty value; |
| 4276 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4277 | if (res != 0) goto failed; |
| 4278 | asdl_seq_SET(keywords, i, value); |
| 4279 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4280 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4281 | } else { |
| 4282 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 4283 | return 1; |
| 4284 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4285 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4286 | int res; |
| 4287 | Py_ssize_t len; |
| 4288 | Py_ssize_t i; |
| 4289 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4290 | if (tmp == NULL) goto failed; |
| 4291 | if (!PyList_Check(tmp)) { |
| 4292 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4293 | goto failed; |
| 4294 | } |
| 4295 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4296 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4297 | if (body == NULL) goto failed; |
| 4298 | for (i = 0; i < len; i++) { |
| 4299 | stmt_ty value; |
| 4300 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4301 | if (res != 0) goto failed; |
| 4302 | asdl_seq_SET(body, i, value); |
| 4303 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4304 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4305 | } else { |
| 4306 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 4307 | return 1; |
| 4308 | } |
| 4309 | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
| 4310 | int res; |
| 4311 | Py_ssize_t len; |
| 4312 | Py_ssize_t i; |
| 4313 | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
| 4314 | if (tmp == NULL) goto failed; |
| 4315 | if (!PyList_Check(tmp)) { |
| 4316 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4317 | goto failed; |
| 4318 | } |
| 4319 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4320 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4321 | if (decorator_list == NULL) goto failed; |
| 4322 | for (i = 0; i < len; i++) { |
| 4323 | expr_ty value; |
| 4324 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4325 | if (res != 0) goto failed; |
| 4326 | asdl_seq_SET(decorator_list, i, value); |
| 4327 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4328 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4329 | } else { |
| 4330 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 4331 | return 1; |
| 4332 | } |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 4333 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
| 4334 | col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4335 | if (*out == NULL) goto failed; |
| 4336 | return 0; |
| 4337 | } |
| 4338 | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
| 4339 | if (isinstance == -1) { |
| 4340 | return 1; |
| 4341 | } |
| 4342 | if (isinstance) { |
| 4343 | expr_ty value; |
| 4344 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4345 | if (exists_not_none(obj, &PyId_value)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4346 | int res; |
| 4347 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 4348 | if (tmp == NULL) goto failed; |
| 4349 | res = obj2ast_expr(tmp, &value, arena); |
| 4350 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4351 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4352 | } else { |
| 4353 | value = NULL; |
| 4354 | } |
| 4355 | *out = Return(value, lineno, col_offset, arena); |
| 4356 | if (*out == NULL) goto failed; |
| 4357 | return 0; |
| 4358 | } |
| 4359 | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
| 4360 | if (isinstance == -1) { |
| 4361 | return 1; |
| 4362 | } |
| 4363 | if (isinstance) { |
| 4364 | asdl_seq* targets; |
| 4365 | |
| 4366 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
| 4367 | int res; |
| 4368 | Py_ssize_t len; |
| 4369 | Py_ssize_t i; |
| 4370 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
| 4371 | if (tmp == NULL) goto failed; |
| 4372 | if (!PyList_Check(tmp)) { |
| 4373 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4374 | goto failed; |
| 4375 | } |
| 4376 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4377 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4378 | if (targets == NULL) goto failed; |
| 4379 | for (i = 0; i < len; i++) { |
| 4380 | expr_ty value; |
| 4381 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4382 | if (res != 0) goto failed; |
| 4383 | asdl_seq_SET(targets, i, value); |
| 4384 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4385 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4386 | } else { |
| 4387 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 4388 | return 1; |
| 4389 | } |
| 4390 | *out = Delete(targets, lineno, col_offset, arena); |
| 4391 | if (*out == NULL) goto failed; |
| 4392 | return 0; |
| 4393 | } |
| 4394 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
| 4395 | if (isinstance == -1) { |
| 4396 | return 1; |
| 4397 | } |
| 4398 | if (isinstance) { |
| 4399 | asdl_seq* targets; |
| 4400 | expr_ty value; |
| 4401 | |
| 4402 | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
| 4403 | int res; |
| 4404 | Py_ssize_t len; |
| 4405 | Py_ssize_t i; |
| 4406 | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
| 4407 | if (tmp == NULL) goto failed; |
| 4408 | if (!PyList_Check(tmp)) { |
| 4409 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4410 | goto failed; |
| 4411 | } |
| 4412 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4413 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4414 | if (targets == NULL) goto failed; |
| 4415 | for (i = 0; i < len; i++) { |
| 4416 | expr_ty value; |
| 4417 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4418 | if (res != 0) goto failed; |
| 4419 | asdl_seq_SET(targets, i, value); |
| 4420 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4421 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4422 | } else { |
| 4423 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 4424 | return 1; |
| 4425 | } |
| 4426 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 4427 | int res; |
| 4428 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 4429 | if (tmp == NULL) goto failed; |
| 4430 | res = obj2ast_expr(tmp, &value, arena); |
| 4431 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4432 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4433 | } else { |
| 4434 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 4435 | return 1; |
| 4436 | } |
| 4437 | *out = Assign(targets, value, lineno, col_offset, arena); |
| 4438 | if (*out == NULL) goto failed; |
| 4439 | return 0; |
| 4440 | } |
| 4441 | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
| 4442 | if (isinstance == -1) { |
| 4443 | return 1; |
| 4444 | } |
| 4445 | if (isinstance) { |
| 4446 | expr_ty target; |
| 4447 | operator_ty op; |
| 4448 | expr_ty value; |
| 4449 | |
| 4450 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
| 4451 | int res; |
| 4452 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 4453 | if (tmp == NULL) goto failed; |
| 4454 | res = obj2ast_expr(tmp, &target, arena); |
| 4455 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4456 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4457 | } else { |
| 4458 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 4459 | return 1; |
| 4460 | } |
| 4461 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
| 4462 | int res; |
| 4463 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 4464 | if (tmp == NULL) goto failed; |
| 4465 | res = obj2ast_operator(tmp, &op, arena); |
| 4466 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4467 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4468 | } else { |
| 4469 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 4470 | return 1; |
| 4471 | } |
| 4472 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 4473 | int res; |
| 4474 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 4475 | if (tmp == NULL) goto failed; |
| 4476 | res = obj2ast_expr(tmp, &value, arena); |
| 4477 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4478 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4479 | } else { |
| 4480 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 4481 | return 1; |
| 4482 | } |
| 4483 | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
| 4484 | if (*out == NULL) goto failed; |
| 4485 | return 0; |
| 4486 | } |
| 4487 | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
| 4488 | if (isinstance == -1) { |
| 4489 | return 1; |
| 4490 | } |
| 4491 | if (isinstance) { |
| 4492 | expr_ty target; |
| 4493 | expr_ty iter; |
| 4494 | asdl_seq* body; |
| 4495 | asdl_seq* orelse; |
| 4496 | |
| 4497 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
| 4498 | int res; |
| 4499 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 4500 | if (tmp == NULL) goto failed; |
| 4501 | res = obj2ast_expr(tmp, &target, arena); |
| 4502 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4503 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4504 | } else { |
| 4505 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 4506 | return 1; |
| 4507 | } |
| 4508 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
| 4509 | int res; |
| 4510 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
| 4511 | if (tmp == NULL) goto failed; |
| 4512 | res = obj2ast_expr(tmp, &iter, arena); |
| 4513 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4514 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4515 | } else { |
| 4516 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 4517 | return 1; |
| 4518 | } |
| 4519 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4520 | int res; |
| 4521 | Py_ssize_t len; |
| 4522 | Py_ssize_t i; |
| 4523 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4524 | if (tmp == NULL) goto failed; |
| 4525 | if (!PyList_Check(tmp)) { |
| 4526 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4527 | goto failed; |
| 4528 | } |
| 4529 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4530 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4531 | if (body == NULL) goto failed; |
| 4532 | for (i = 0; i < len; i++) { |
| 4533 | stmt_ty value; |
| 4534 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4535 | if (res != 0) goto failed; |
| 4536 | asdl_seq_SET(body, i, value); |
| 4537 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4538 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4539 | } else { |
| 4540 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 4541 | return 1; |
| 4542 | } |
| 4543 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 4544 | int res; |
| 4545 | Py_ssize_t len; |
| 4546 | Py_ssize_t i; |
| 4547 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4548 | if (tmp == NULL) goto failed; |
| 4549 | if (!PyList_Check(tmp)) { |
| 4550 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4551 | goto failed; |
| 4552 | } |
| 4553 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4554 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4555 | if (orelse == NULL) goto failed; |
| 4556 | for (i = 0; i < len; i++) { |
| 4557 | stmt_ty value; |
| 4558 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4559 | if (res != 0) goto failed; |
| 4560 | asdl_seq_SET(orelse, i, value); |
| 4561 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4562 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4563 | } else { |
| 4564 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 4565 | return 1; |
| 4566 | } |
| 4567 | *out = For(target, iter, body, orelse, lineno, col_offset, arena); |
| 4568 | if (*out == NULL) goto failed; |
| 4569 | return 0; |
| 4570 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4571 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFor_type); |
| 4572 | if (isinstance == -1) { |
| 4573 | return 1; |
| 4574 | } |
| 4575 | if (isinstance) { |
| 4576 | expr_ty target; |
| 4577 | expr_ty iter; |
| 4578 | asdl_seq* body; |
| 4579 | asdl_seq* orelse; |
| 4580 | |
| 4581 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
| 4582 | int res; |
| 4583 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 4584 | if (tmp == NULL) goto failed; |
| 4585 | res = obj2ast_expr(tmp, &target, arena); |
| 4586 | if (res != 0) goto failed; |
| 4587 | Py_CLEAR(tmp); |
| 4588 | } else { |
| 4589 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 4590 | return 1; |
| 4591 | } |
| 4592 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
| 4593 | int res; |
| 4594 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
| 4595 | if (tmp == NULL) goto failed; |
| 4596 | res = obj2ast_expr(tmp, &iter, arena); |
| 4597 | if (res != 0) goto failed; |
| 4598 | Py_CLEAR(tmp); |
| 4599 | } else { |
| 4600 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 4601 | return 1; |
| 4602 | } |
| 4603 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4604 | int res; |
| 4605 | Py_ssize_t len; |
| 4606 | Py_ssize_t i; |
| 4607 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4608 | if (tmp == NULL) goto failed; |
| 4609 | if (!PyList_Check(tmp)) { |
| 4610 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4611 | goto failed; |
| 4612 | } |
| 4613 | len = PyList_GET_SIZE(tmp); |
| 4614 | body = _Py_asdl_seq_new(len, arena); |
| 4615 | if (body == NULL) goto failed; |
| 4616 | for (i = 0; i < len; i++) { |
| 4617 | stmt_ty value; |
| 4618 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4619 | if (res != 0) goto failed; |
| 4620 | asdl_seq_SET(body, i, value); |
| 4621 | } |
| 4622 | Py_CLEAR(tmp); |
| 4623 | } else { |
| 4624 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 4625 | return 1; |
| 4626 | } |
| 4627 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 4628 | int res; |
| 4629 | Py_ssize_t len; |
| 4630 | Py_ssize_t i; |
| 4631 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4632 | if (tmp == NULL) goto failed; |
| 4633 | if (!PyList_Check(tmp)) { |
| 4634 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4635 | goto failed; |
| 4636 | } |
| 4637 | len = PyList_GET_SIZE(tmp); |
| 4638 | orelse = _Py_asdl_seq_new(len, arena); |
| 4639 | if (orelse == NULL) goto failed; |
| 4640 | for (i = 0; i < len; i++) { |
| 4641 | stmt_ty value; |
| 4642 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4643 | if (res != 0) goto failed; |
| 4644 | asdl_seq_SET(orelse, i, value); |
| 4645 | } |
| 4646 | Py_CLEAR(tmp); |
| 4647 | } else { |
| 4648 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 4649 | return 1; |
| 4650 | } |
| 4651 | *out = AsyncFor(target, iter, body, orelse, lineno, col_offset, arena); |
| 4652 | if (*out == NULL) goto failed; |
| 4653 | return 0; |
| 4654 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4655 | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
| 4656 | if (isinstance == -1) { |
| 4657 | return 1; |
| 4658 | } |
| 4659 | if (isinstance) { |
| 4660 | expr_ty test; |
| 4661 | asdl_seq* body; |
| 4662 | asdl_seq* orelse; |
| 4663 | |
| 4664 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
| 4665 | int res; |
| 4666 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 4667 | if (tmp == NULL) goto failed; |
| 4668 | res = obj2ast_expr(tmp, &test, arena); |
| 4669 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4670 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4671 | } else { |
| 4672 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 4673 | return 1; |
| 4674 | } |
| 4675 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4676 | int res; |
| 4677 | Py_ssize_t len; |
| 4678 | Py_ssize_t i; |
| 4679 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4680 | if (tmp == NULL) goto failed; |
| 4681 | if (!PyList_Check(tmp)) { |
| 4682 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4683 | goto failed; |
| 4684 | } |
| 4685 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4686 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4687 | if (body == NULL) goto failed; |
| 4688 | for (i = 0; i < len; i++) { |
| 4689 | stmt_ty value; |
| 4690 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4691 | if (res != 0) goto failed; |
| 4692 | asdl_seq_SET(body, i, value); |
| 4693 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4694 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4695 | } else { |
| 4696 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 4697 | return 1; |
| 4698 | } |
| 4699 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 4700 | int res; |
| 4701 | Py_ssize_t len; |
| 4702 | Py_ssize_t i; |
| 4703 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4704 | if (tmp == NULL) goto failed; |
| 4705 | if (!PyList_Check(tmp)) { |
| 4706 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4707 | goto failed; |
| 4708 | } |
| 4709 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4710 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4711 | if (orelse == NULL) goto failed; |
| 4712 | for (i = 0; i < len; i++) { |
| 4713 | stmt_ty value; |
| 4714 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4715 | if (res != 0) goto failed; |
| 4716 | asdl_seq_SET(orelse, i, value); |
| 4717 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4718 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4719 | } else { |
| 4720 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 4721 | return 1; |
| 4722 | } |
| 4723 | *out = While(test, body, orelse, lineno, col_offset, arena); |
| 4724 | if (*out == NULL) goto failed; |
| 4725 | return 0; |
| 4726 | } |
| 4727 | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
| 4728 | if (isinstance == -1) { |
| 4729 | return 1; |
| 4730 | } |
| 4731 | if (isinstance) { |
| 4732 | expr_ty test; |
| 4733 | asdl_seq* body; |
| 4734 | asdl_seq* orelse; |
| 4735 | |
| 4736 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
| 4737 | int res; |
| 4738 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 4739 | if (tmp == NULL) goto failed; |
| 4740 | res = obj2ast_expr(tmp, &test, arena); |
| 4741 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4742 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4743 | } else { |
| 4744 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 4745 | return 1; |
| 4746 | } |
| 4747 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4748 | int res; |
| 4749 | Py_ssize_t len; |
| 4750 | Py_ssize_t i; |
| 4751 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4752 | if (tmp == NULL) goto failed; |
| 4753 | if (!PyList_Check(tmp)) { |
| 4754 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4755 | goto failed; |
| 4756 | } |
| 4757 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4758 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4759 | if (body == NULL) goto failed; |
| 4760 | for (i = 0; i < len; i++) { |
| 4761 | stmt_ty value; |
| 4762 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4763 | if (res != 0) goto failed; |
| 4764 | asdl_seq_SET(body, i, value); |
| 4765 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4766 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4767 | } else { |
| 4768 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 4769 | return 1; |
| 4770 | } |
| 4771 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 4772 | int res; |
| 4773 | Py_ssize_t len; |
| 4774 | Py_ssize_t i; |
| 4775 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 4776 | if (tmp == NULL) goto failed; |
| 4777 | if (!PyList_Check(tmp)) { |
| 4778 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4779 | goto failed; |
| 4780 | } |
| 4781 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4782 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4783 | if (orelse == NULL) goto failed; |
| 4784 | for (i = 0; i < len; i++) { |
| 4785 | stmt_ty value; |
| 4786 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4787 | if (res != 0) goto failed; |
| 4788 | asdl_seq_SET(orelse, i, value); |
| 4789 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4790 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4791 | } else { |
| 4792 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 4793 | return 1; |
| 4794 | } |
| 4795 | *out = If(test, body, orelse, lineno, col_offset, arena); |
| 4796 | if (*out == NULL) goto failed; |
| 4797 | return 0; |
| 4798 | } |
| 4799 | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
| 4800 | if (isinstance == -1) { |
| 4801 | return 1; |
| 4802 | } |
| 4803 | if (isinstance) { |
| 4804 | asdl_seq* items; |
| 4805 | asdl_seq* body; |
| 4806 | |
| 4807 | if (_PyObject_HasAttrId(obj, &PyId_items)) { |
| 4808 | int res; |
| 4809 | Py_ssize_t len; |
| 4810 | Py_ssize_t i; |
| 4811 | tmp = _PyObject_GetAttrId(obj, &PyId_items); |
| 4812 | if (tmp == NULL) goto failed; |
| 4813 | if (!PyList_Check(tmp)) { |
| 4814 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4815 | goto failed; |
| 4816 | } |
| 4817 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4818 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4819 | if (items == NULL) goto failed; |
| 4820 | for (i = 0; i < len; i++) { |
| 4821 | withitem_ty value; |
| 4822 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4823 | if (res != 0) goto failed; |
| 4824 | asdl_seq_SET(items, i, value); |
| 4825 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4826 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4827 | } else { |
| 4828 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 4829 | return 1; |
| 4830 | } |
| 4831 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4832 | int res; |
| 4833 | Py_ssize_t len; |
| 4834 | Py_ssize_t i; |
| 4835 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4836 | if (tmp == NULL) goto failed; |
| 4837 | if (!PyList_Check(tmp)) { |
| 4838 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4839 | goto failed; |
| 4840 | } |
| 4841 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4842 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4843 | if (body == NULL) goto failed; |
| 4844 | for (i = 0; i < len; i++) { |
| 4845 | stmt_ty value; |
| 4846 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4847 | if (res != 0) goto failed; |
| 4848 | asdl_seq_SET(body, i, value); |
| 4849 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4850 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4851 | } else { |
| 4852 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 4853 | return 1; |
| 4854 | } |
| 4855 | *out = With(items, body, lineno, col_offset, arena); |
| 4856 | if (*out == NULL) goto failed; |
| 4857 | return 0; |
| 4858 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4859 | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncWith_type); |
| 4860 | if (isinstance == -1) { |
| 4861 | return 1; |
| 4862 | } |
| 4863 | if (isinstance) { |
| 4864 | asdl_seq* items; |
| 4865 | asdl_seq* body; |
| 4866 | |
| 4867 | if (_PyObject_HasAttrId(obj, &PyId_items)) { |
| 4868 | int res; |
| 4869 | Py_ssize_t len; |
| 4870 | Py_ssize_t i; |
| 4871 | tmp = _PyObject_GetAttrId(obj, &PyId_items); |
| 4872 | if (tmp == NULL) goto failed; |
| 4873 | if (!PyList_Check(tmp)) { |
| 4874 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4875 | goto failed; |
| 4876 | } |
| 4877 | len = PyList_GET_SIZE(tmp); |
| 4878 | items = _Py_asdl_seq_new(len, arena); |
| 4879 | if (items == NULL) goto failed; |
| 4880 | for (i = 0; i < len; i++) { |
| 4881 | withitem_ty value; |
| 4882 | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4883 | if (res != 0) goto failed; |
| 4884 | asdl_seq_SET(items, i, value); |
| 4885 | } |
| 4886 | Py_CLEAR(tmp); |
| 4887 | } else { |
| 4888 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 4889 | return 1; |
| 4890 | } |
| 4891 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4892 | int res; |
| 4893 | Py_ssize_t len; |
| 4894 | Py_ssize_t i; |
| 4895 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4896 | if (tmp == NULL) goto failed; |
| 4897 | if (!PyList_Check(tmp)) { |
| 4898 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4899 | goto failed; |
| 4900 | } |
| 4901 | len = PyList_GET_SIZE(tmp); |
| 4902 | body = _Py_asdl_seq_new(len, arena); |
| 4903 | if (body == NULL) goto failed; |
| 4904 | for (i = 0; i < len; i++) { |
| 4905 | stmt_ty value; |
| 4906 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4907 | if (res != 0) goto failed; |
| 4908 | asdl_seq_SET(body, i, value); |
| 4909 | } |
| 4910 | Py_CLEAR(tmp); |
| 4911 | } else { |
| 4912 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 4913 | return 1; |
| 4914 | } |
| 4915 | *out = AsyncWith(items, body, lineno, col_offset, arena); |
| 4916 | if (*out == NULL) goto failed; |
| 4917 | return 0; |
| 4918 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4919 | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
| 4920 | if (isinstance == -1) { |
| 4921 | return 1; |
| 4922 | } |
| 4923 | if (isinstance) { |
| 4924 | expr_ty exc; |
| 4925 | expr_ty cause; |
| 4926 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4927 | if (exists_not_none(obj, &PyId_exc)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4928 | int res; |
| 4929 | tmp = _PyObject_GetAttrId(obj, &PyId_exc); |
| 4930 | if (tmp == NULL) goto failed; |
| 4931 | res = obj2ast_expr(tmp, &exc, arena); |
| 4932 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4933 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4934 | } else { |
| 4935 | exc = NULL; |
| 4936 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4937 | if (exists_not_none(obj, &PyId_cause)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4938 | int res; |
| 4939 | tmp = _PyObject_GetAttrId(obj, &PyId_cause); |
| 4940 | if (tmp == NULL) goto failed; |
| 4941 | res = obj2ast_expr(tmp, &cause, arena); |
| 4942 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4943 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4944 | } else { |
| 4945 | cause = NULL; |
| 4946 | } |
| 4947 | *out = Raise(exc, cause, lineno, col_offset, arena); |
| 4948 | if (*out == NULL) goto failed; |
| 4949 | return 0; |
| 4950 | } |
| 4951 | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
| 4952 | if (isinstance == -1) { |
| 4953 | return 1; |
| 4954 | } |
| 4955 | if (isinstance) { |
| 4956 | asdl_seq* body; |
| 4957 | asdl_seq* handlers; |
| 4958 | asdl_seq* orelse; |
| 4959 | asdl_seq* finalbody; |
| 4960 | |
| 4961 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 4962 | int res; |
| 4963 | Py_ssize_t len; |
| 4964 | Py_ssize_t i; |
| 4965 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 4966 | if (tmp == NULL) goto failed; |
| 4967 | if (!PyList_Check(tmp)) { |
| 4968 | PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4969 | goto failed; |
| 4970 | } |
| 4971 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4972 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4973 | if (body == NULL) goto failed; |
| 4974 | for (i = 0; i < len; i++) { |
| 4975 | stmt_ty value; |
| 4976 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 4977 | if (res != 0) goto failed; |
| 4978 | asdl_seq_SET(body, i, value); |
| 4979 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 4980 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4981 | } else { |
| 4982 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 4983 | return 1; |
| 4984 | } |
| 4985 | if (_PyObject_HasAttrId(obj, &PyId_handlers)) { |
| 4986 | int res; |
| 4987 | Py_ssize_t len; |
| 4988 | Py_ssize_t i; |
| 4989 | tmp = _PyObject_GetAttrId(obj, &PyId_handlers); |
| 4990 | if (tmp == NULL) goto failed; |
| 4991 | if (!PyList_Check(tmp)) { |
| 4992 | PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 4993 | goto failed; |
| 4994 | } |
| 4995 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4996 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4997 | if (handlers == NULL) goto failed; |
| 4998 | for (i = 0; i < len; i++) { |
| 4999 | excepthandler_ty value; |
| 5000 | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5001 | if (res != 0) goto failed; |
| 5002 | asdl_seq_SET(handlers, i, value); |
| 5003 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5004 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5005 | } else { |
| 5006 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 5007 | return 1; |
| 5008 | } |
| 5009 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 5010 | int res; |
| 5011 | Py_ssize_t len; |
| 5012 | Py_ssize_t i; |
| 5013 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 5014 | if (tmp == NULL) goto failed; |
| 5015 | if (!PyList_Check(tmp)) { |
| 5016 | PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5017 | goto failed; |
| 5018 | } |
| 5019 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5020 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5021 | if (orelse == NULL) goto failed; |
| 5022 | for (i = 0; i < len; i++) { |
| 5023 | stmt_ty value; |
| 5024 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5025 | if (res != 0) goto failed; |
| 5026 | asdl_seq_SET(orelse, i, value); |
| 5027 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5028 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5029 | } else { |
| 5030 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 5031 | return 1; |
| 5032 | } |
| 5033 | if (_PyObject_HasAttrId(obj, &PyId_finalbody)) { |
| 5034 | int res; |
| 5035 | Py_ssize_t len; |
| 5036 | Py_ssize_t i; |
| 5037 | tmp = _PyObject_GetAttrId(obj, &PyId_finalbody); |
| 5038 | if (tmp == NULL) goto failed; |
| 5039 | if (!PyList_Check(tmp)) { |
| 5040 | PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5041 | goto failed; |
| 5042 | } |
| 5043 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5044 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5045 | if (finalbody == NULL) goto failed; |
| 5046 | for (i = 0; i < len; i++) { |
| 5047 | stmt_ty value; |
| 5048 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5049 | if (res != 0) goto failed; |
| 5050 | asdl_seq_SET(finalbody, i, value); |
| 5051 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5052 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5053 | } else { |
| 5054 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 5055 | return 1; |
| 5056 | } |
| 5057 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
| 5058 | arena); |
| 5059 | if (*out == NULL) goto failed; |
| 5060 | return 0; |
| 5061 | } |
| 5062 | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
| 5063 | if (isinstance == -1) { |
| 5064 | return 1; |
| 5065 | } |
| 5066 | if (isinstance) { |
| 5067 | expr_ty test; |
| 5068 | expr_ty msg; |
| 5069 | |
| 5070 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
| 5071 | int res; |
| 5072 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 5073 | if (tmp == NULL) goto failed; |
| 5074 | res = obj2ast_expr(tmp, &test, arena); |
| 5075 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5076 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5077 | } else { |
| 5078 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 5079 | return 1; |
| 5080 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5081 | if (exists_not_none(obj, &PyId_msg)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5082 | int res; |
| 5083 | tmp = _PyObject_GetAttrId(obj, &PyId_msg); |
| 5084 | if (tmp == NULL) goto failed; |
| 5085 | res = obj2ast_expr(tmp, &msg, arena); |
| 5086 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5087 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5088 | } else { |
| 5089 | msg = NULL; |
| 5090 | } |
| 5091 | *out = Assert(test, msg, lineno, col_offset, arena); |
| 5092 | if (*out == NULL) goto failed; |
| 5093 | return 0; |
| 5094 | } |
| 5095 | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
| 5096 | if (isinstance == -1) { |
| 5097 | return 1; |
| 5098 | } |
| 5099 | if (isinstance) { |
| 5100 | asdl_seq* names; |
| 5101 | |
| 5102 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
| 5103 | int res; |
| 5104 | Py_ssize_t len; |
| 5105 | Py_ssize_t i; |
| 5106 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 5107 | if (tmp == NULL) goto failed; |
| 5108 | if (!PyList_Check(tmp)) { |
| 5109 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5110 | goto failed; |
| 5111 | } |
| 5112 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5113 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5114 | if (names == NULL) goto failed; |
| 5115 | for (i = 0; i < len; i++) { |
| 5116 | alias_ty value; |
| 5117 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5118 | if (res != 0) goto failed; |
| 5119 | asdl_seq_SET(names, i, value); |
| 5120 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5121 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5122 | } else { |
| 5123 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 5124 | return 1; |
| 5125 | } |
| 5126 | *out = Import(names, lineno, col_offset, arena); |
| 5127 | if (*out == NULL) goto failed; |
| 5128 | return 0; |
| 5129 | } |
| 5130 | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
| 5131 | if (isinstance == -1) { |
| 5132 | return 1; |
| 5133 | } |
| 5134 | if (isinstance) { |
| 5135 | identifier module; |
| 5136 | asdl_seq* names; |
| 5137 | int level; |
| 5138 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5139 | if (exists_not_none(obj, &PyId_module)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5140 | int res; |
| 5141 | tmp = _PyObject_GetAttrId(obj, &PyId_module); |
| 5142 | if (tmp == NULL) goto failed; |
| 5143 | res = obj2ast_identifier(tmp, &module, arena); |
| 5144 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5145 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5146 | } else { |
| 5147 | module = NULL; |
| 5148 | } |
| 5149 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
| 5150 | int res; |
| 5151 | Py_ssize_t len; |
| 5152 | Py_ssize_t i; |
| 5153 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 5154 | if (tmp == NULL) goto failed; |
| 5155 | if (!PyList_Check(tmp)) { |
| 5156 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5157 | goto failed; |
| 5158 | } |
| 5159 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5160 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5161 | if (names == NULL) goto failed; |
| 5162 | for (i = 0; i < len; i++) { |
| 5163 | alias_ty value; |
| 5164 | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5165 | if (res != 0) goto failed; |
| 5166 | asdl_seq_SET(names, i, value); |
| 5167 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5168 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5169 | } else { |
| 5170 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 5171 | return 1; |
| 5172 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5173 | if (exists_not_none(obj, &PyId_level)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5174 | int res; |
| 5175 | tmp = _PyObject_GetAttrId(obj, &PyId_level); |
| 5176 | if (tmp == NULL) goto failed; |
| 5177 | res = obj2ast_int(tmp, &level, arena); |
| 5178 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5179 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5180 | } else { |
| 5181 | level = 0; |
| 5182 | } |
| 5183 | *out = ImportFrom(module, names, level, lineno, col_offset, arena); |
| 5184 | if (*out == NULL) goto failed; |
| 5185 | return 0; |
| 5186 | } |
| 5187 | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
| 5188 | if (isinstance == -1) { |
| 5189 | return 1; |
| 5190 | } |
| 5191 | if (isinstance) { |
| 5192 | asdl_seq* names; |
| 5193 | |
| 5194 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
| 5195 | int res; |
| 5196 | Py_ssize_t len; |
| 5197 | Py_ssize_t i; |
| 5198 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 5199 | if (tmp == NULL) goto failed; |
| 5200 | if (!PyList_Check(tmp)) { |
| 5201 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5202 | goto failed; |
| 5203 | } |
| 5204 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5205 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5206 | if (names == NULL) goto failed; |
| 5207 | for (i = 0; i < len; i++) { |
| 5208 | identifier value; |
| 5209 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5210 | if (res != 0) goto failed; |
| 5211 | asdl_seq_SET(names, i, value); |
| 5212 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5213 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5214 | } else { |
| 5215 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 5216 | return 1; |
| 5217 | } |
| 5218 | *out = Global(names, lineno, col_offset, arena); |
| 5219 | if (*out == NULL) goto failed; |
| 5220 | return 0; |
| 5221 | } |
| 5222 | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
| 5223 | if (isinstance == -1) { |
| 5224 | return 1; |
| 5225 | } |
| 5226 | if (isinstance) { |
| 5227 | asdl_seq* names; |
| 5228 | |
| 5229 | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
| 5230 | int res; |
| 5231 | Py_ssize_t len; |
| 5232 | Py_ssize_t i; |
| 5233 | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
| 5234 | if (tmp == NULL) goto failed; |
| 5235 | if (!PyList_Check(tmp)) { |
| 5236 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5237 | goto failed; |
| 5238 | } |
| 5239 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5240 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5241 | if (names == NULL) goto failed; |
| 5242 | for (i = 0; i < len; i++) { |
| 5243 | identifier value; |
| 5244 | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5245 | if (res != 0) goto failed; |
| 5246 | asdl_seq_SET(names, i, value); |
| 5247 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5248 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5249 | } else { |
| 5250 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 5251 | return 1; |
| 5252 | } |
| 5253 | *out = Nonlocal(names, lineno, col_offset, arena); |
| 5254 | if (*out == NULL) goto failed; |
| 5255 | return 0; |
| 5256 | } |
| 5257 | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
| 5258 | if (isinstance == -1) { |
| 5259 | return 1; |
| 5260 | } |
| 5261 | if (isinstance) { |
| 5262 | expr_ty value; |
| 5263 | |
| 5264 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5265 | int res; |
| 5266 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5267 | if (tmp == NULL) goto failed; |
| 5268 | res = obj2ast_expr(tmp, &value, arena); |
| 5269 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5270 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5271 | } else { |
| 5272 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 5273 | return 1; |
| 5274 | } |
| 5275 | *out = Expr(value, lineno, col_offset, arena); |
| 5276 | if (*out == NULL) goto failed; |
| 5277 | return 0; |
| 5278 | } |
| 5279 | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
| 5280 | if (isinstance == -1) { |
| 5281 | return 1; |
| 5282 | } |
| 5283 | if (isinstance) { |
| 5284 | |
| 5285 | *out = Pass(lineno, col_offset, arena); |
| 5286 | if (*out == NULL) goto failed; |
| 5287 | return 0; |
| 5288 | } |
| 5289 | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
| 5290 | if (isinstance == -1) { |
| 5291 | return 1; |
| 5292 | } |
| 5293 | if (isinstance) { |
| 5294 | |
| 5295 | *out = Break(lineno, col_offset, arena); |
| 5296 | if (*out == NULL) goto failed; |
| 5297 | return 0; |
| 5298 | } |
| 5299 | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
| 5300 | if (isinstance == -1) { |
| 5301 | return 1; |
| 5302 | } |
| 5303 | if (isinstance) { |
| 5304 | |
| 5305 | *out = Continue(lineno, col_offset, arena); |
| 5306 | if (*out == NULL) goto failed; |
| 5307 | return 0; |
| 5308 | } |
| 5309 | |
| 5310 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 5311 | failed: |
| 5312 | Py_XDECREF(tmp); |
| 5313 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5314 | } |
| 5315 | |
| 5316 | int |
| 5317 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 5318 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5319 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5320 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5321 | PyObject *tmp = NULL; |
| 5322 | int lineno; |
| 5323 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5324 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5325 | if (obj == Py_None) { |
| 5326 | *out = NULL; |
| 5327 | return 0; |
| 5328 | } |
| 5329 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
| 5330 | int res; |
| 5331 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 5332 | if (tmp == NULL) goto failed; |
| 5333 | res = obj2ast_int(tmp, &lineno, arena); |
| 5334 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5335 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5336 | } else { |
| 5337 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5338 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5339 | } |
| 5340 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
| 5341 | int res; |
| 5342 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 5343 | if (tmp == NULL) goto failed; |
| 5344 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5345 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5346 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5347 | } else { |
| 5348 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 5349 | return 1; |
| 5350 | } |
| 5351 | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
| 5352 | if (isinstance == -1) { |
| 5353 | return 1; |
| 5354 | } |
| 5355 | if (isinstance) { |
| 5356 | boolop_ty op; |
| 5357 | asdl_seq* values; |
| 5358 | |
| 5359 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
| 5360 | int res; |
| 5361 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 5362 | if (tmp == NULL) goto failed; |
| 5363 | res = obj2ast_boolop(tmp, &op, arena); |
| 5364 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5365 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5366 | } else { |
| 5367 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 5368 | return 1; |
| 5369 | } |
| 5370 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
| 5371 | int res; |
| 5372 | Py_ssize_t len; |
| 5373 | Py_ssize_t i; |
| 5374 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
| 5375 | if (tmp == NULL) goto failed; |
| 5376 | if (!PyList_Check(tmp)) { |
| 5377 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5378 | goto failed; |
| 5379 | } |
| 5380 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5381 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5382 | if (values == NULL) goto failed; |
| 5383 | for (i = 0; i < len; i++) { |
| 5384 | expr_ty value; |
| 5385 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5386 | if (res != 0) goto failed; |
| 5387 | asdl_seq_SET(values, i, value); |
| 5388 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5389 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5390 | } else { |
| 5391 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 5392 | return 1; |
| 5393 | } |
| 5394 | *out = BoolOp(op, values, lineno, col_offset, arena); |
| 5395 | if (*out == NULL) goto failed; |
| 5396 | return 0; |
| 5397 | } |
| 5398 | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
| 5399 | if (isinstance == -1) { |
| 5400 | return 1; |
| 5401 | } |
| 5402 | if (isinstance) { |
| 5403 | expr_ty left; |
| 5404 | operator_ty op; |
| 5405 | expr_ty right; |
| 5406 | |
| 5407 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
| 5408 | int res; |
| 5409 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
| 5410 | if (tmp == NULL) goto failed; |
| 5411 | res = obj2ast_expr(tmp, &left, arena); |
| 5412 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5413 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5414 | } else { |
| 5415 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 5416 | return 1; |
| 5417 | } |
| 5418 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
| 5419 | int res; |
| 5420 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 5421 | if (tmp == NULL) goto failed; |
| 5422 | res = obj2ast_operator(tmp, &op, arena); |
| 5423 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5424 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5425 | } else { |
| 5426 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 5427 | return 1; |
| 5428 | } |
| 5429 | if (_PyObject_HasAttrId(obj, &PyId_right)) { |
| 5430 | int res; |
| 5431 | tmp = _PyObject_GetAttrId(obj, &PyId_right); |
| 5432 | if (tmp == NULL) goto failed; |
| 5433 | res = obj2ast_expr(tmp, &right, arena); |
| 5434 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5435 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5436 | } else { |
| 5437 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 5438 | return 1; |
| 5439 | } |
| 5440 | *out = BinOp(left, op, right, lineno, col_offset, arena); |
| 5441 | if (*out == NULL) goto failed; |
| 5442 | return 0; |
| 5443 | } |
| 5444 | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
| 5445 | if (isinstance == -1) { |
| 5446 | return 1; |
| 5447 | } |
| 5448 | if (isinstance) { |
| 5449 | unaryop_ty op; |
| 5450 | expr_ty operand; |
| 5451 | |
| 5452 | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
| 5453 | int res; |
| 5454 | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
| 5455 | if (tmp == NULL) goto failed; |
| 5456 | res = obj2ast_unaryop(tmp, &op, arena); |
| 5457 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5458 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5459 | } else { |
| 5460 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 5461 | return 1; |
| 5462 | } |
| 5463 | if (_PyObject_HasAttrId(obj, &PyId_operand)) { |
| 5464 | int res; |
| 5465 | tmp = _PyObject_GetAttrId(obj, &PyId_operand); |
| 5466 | if (tmp == NULL) goto failed; |
| 5467 | res = obj2ast_expr(tmp, &operand, arena); |
| 5468 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5469 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5470 | } else { |
| 5471 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 5472 | return 1; |
| 5473 | } |
| 5474 | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
| 5475 | if (*out == NULL) goto failed; |
| 5476 | return 0; |
| 5477 | } |
| 5478 | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
| 5479 | if (isinstance == -1) { |
| 5480 | return 1; |
| 5481 | } |
| 5482 | if (isinstance) { |
| 5483 | arguments_ty args; |
| 5484 | expr_ty body; |
| 5485 | |
| 5486 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 5487 | int res; |
| 5488 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 5489 | if (tmp == NULL) goto failed; |
| 5490 | res = obj2ast_arguments(tmp, &args, arena); |
| 5491 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5492 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5493 | } else { |
| 5494 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 5495 | return 1; |
| 5496 | } |
| 5497 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 5498 | int res; |
| 5499 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 5500 | if (tmp == NULL) goto failed; |
| 5501 | res = obj2ast_expr(tmp, &body, arena); |
| 5502 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5503 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5504 | } else { |
| 5505 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 5506 | return 1; |
| 5507 | } |
| 5508 | *out = Lambda(args, body, lineno, col_offset, arena); |
| 5509 | if (*out == NULL) goto failed; |
| 5510 | return 0; |
| 5511 | } |
| 5512 | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
| 5513 | if (isinstance == -1) { |
| 5514 | return 1; |
| 5515 | } |
| 5516 | if (isinstance) { |
| 5517 | expr_ty test; |
| 5518 | expr_ty body; |
| 5519 | expr_ty orelse; |
| 5520 | |
| 5521 | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
| 5522 | int res; |
| 5523 | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
| 5524 | if (tmp == NULL) goto failed; |
| 5525 | res = obj2ast_expr(tmp, &test, arena); |
| 5526 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5527 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5528 | } else { |
| 5529 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 5530 | return 1; |
| 5531 | } |
| 5532 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 5533 | int res; |
| 5534 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 5535 | if (tmp == NULL) goto failed; |
| 5536 | res = obj2ast_expr(tmp, &body, arena); |
| 5537 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5538 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5539 | } else { |
| 5540 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 5541 | return 1; |
| 5542 | } |
| 5543 | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
| 5544 | int res; |
| 5545 | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
| 5546 | if (tmp == NULL) goto failed; |
| 5547 | res = obj2ast_expr(tmp, &orelse, arena); |
| 5548 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5549 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5550 | } else { |
| 5551 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 5552 | return 1; |
| 5553 | } |
| 5554 | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
| 5555 | if (*out == NULL) goto failed; |
| 5556 | return 0; |
| 5557 | } |
| 5558 | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
| 5559 | if (isinstance == -1) { |
| 5560 | return 1; |
| 5561 | } |
| 5562 | if (isinstance) { |
| 5563 | asdl_seq* keys; |
| 5564 | asdl_seq* values; |
| 5565 | |
| 5566 | if (_PyObject_HasAttrId(obj, &PyId_keys)) { |
| 5567 | int res; |
| 5568 | Py_ssize_t len; |
| 5569 | Py_ssize_t i; |
| 5570 | tmp = _PyObject_GetAttrId(obj, &PyId_keys); |
| 5571 | if (tmp == NULL) goto failed; |
| 5572 | if (!PyList_Check(tmp)) { |
| 5573 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5574 | goto failed; |
| 5575 | } |
| 5576 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5577 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5578 | if (keys == NULL) goto failed; |
| 5579 | for (i = 0; i < len; i++) { |
| 5580 | expr_ty value; |
| 5581 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5582 | if (res != 0) goto failed; |
| 5583 | asdl_seq_SET(keys, i, value); |
| 5584 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5585 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5586 | } else { |
| 5587 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 5588 | return 1; |
| 5589 | } |
| 5590 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
| 5591 | int res; |
| 5592 | Py_ssize_t len; |
| 5593 | Py_ssize_t i; |
| 5594 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
| 5595 | if (tmp == NULL) goto failed; |
| 5596 | if (!PyList_Check(tmp)) { |
| 5597 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5598 | goto failed; |
| 5599 | } |
| 5600 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5601 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5602 | if (values == NULL) goto failed; |
| 5603 | for (i = 0; i < len; i++) { |
| 5604 | expr_ty value; |
| 5605 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5606 | if (res != 0) goto failed; |
| 5607 | asdl_seq_SET(values, i, value); |
| 5608 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5609 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5610 | } else { |
| 5611 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 5612 | return 1; |
| 5613 | } |
| 5614 | *out = Dict(keys, values, lineno, col_offset, arena); |
| 5615 | if (*out == NULL) goto failed; |
| 5616 | return 0; |
| 5617 | } |
| 5618 | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
| 5619 | if (isinstance == -1) { |
| 5620 | return 1; |
| 5621 | } |
| 5622 | if (isinstance) { |
| 5623 | asdl_seq* elts; |
| 5624 | |
| 5625 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
| 5626 | int res; |
| 5627 | Py_ssize_t len; |
| 5628 | Py_ssize_t i; |
| 5629 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
| 5630 | if (tmp == NULL) goto failed; |
| 5631 | if (!PyList_Check(tmp)) { |
| 5632 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5633 | goto failed; |
| 5634 | } |
| 5635 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5636 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5637 | if (elts == NULL) goto failed; |
| 5638 | for (i = 0; i < len; i++) { |
| 5639 | expr_ty value; |
| 5640 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5641 | if (res != 0) goto failed; |
| 5642 | asdl_seq_SET(elts, i, value); |
| 5643 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5644 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5645 | } else { |
| 5646 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 5647 | return 1; |
| 5648 | } |
| 5649 | *out = Set(elts, lineno, col_offset, arena); |
| 5650 | if (*out == NULL) goto failed; |
| 5651 | return 0; |
| 5652 | } |
| 5653 | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
| 5654 | if (isinstance == -1) { |
| 5655 | return 1; |
| 5656 | } |
| 5657 | if (isinstance) { |
| 5658 | expr_ty elt; |
| 5659 | asdl_seq* generators; |
| 5660 | |
| 5661 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
| 5662 | int res; |
| 5663 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
| 5664 | if (tmp == NULL) goto failed; |
| 5665 | res = obj2ast_expr(tmp, &elt, arena); |
| 5666 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5667 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5668 | } else { |
| 5669 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 5670 | return 1; |
| 5671 | } |
| 5672 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
| 5673 | int res; |
| 5674 | Py_ssize_t len; |
| 5675 | Py_ssize_t i; |
| 5676 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 5677 | if (tmp == NULL) goto failed; |
| 5678 | if (!PyList_Check(tmp)) { |
| 5679 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5680 | goto failed; |
| 5681 | } |
| 5682 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5683 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5684 | if (generators == NULL) goto failed; |
| 5685 | for (i = 0; i < len; i++) { |
| 5686 | comprehension_ty value; |
| 5687 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5688 | if (res != 0) goto failed; |
| 5689 | asdl_seq_SET(generators, i, value); |
| 5690 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5691 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5692 | } else { |
| 5693 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 5694 | return 1; |
| 5695 | } |
| 5696 | *out = ListComp(elt, generators, lineno, col_offset, arena); |
| 5697 | if (*out == NULL) goto failed; |
| 5698 | return 0; |
| 5699 | } |
| 5700 | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
| 5701 | if (isinstance == -1) { |
| 5702 | return 1; |
| 5703 | } |
| 5704 | if (isinstance) { |
| 5705 | expr_ty elt; |
| 5706 | asdl_seq* generators; |
| 5707 | |
| 5708 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
| 5709 | int res; |
| 5710 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
| 5711 | if (tmp == NULL) goto failed; |
| 5712 | res = obj2ast_expr(tmp, &elt, arena); |
| 5713 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5714 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5715 | } else { |
| 5716 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 5717 | return 1; |
| 5718 | } |
| 5719 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
| 5720 | int res; |
| 5721 | Py_ssize_t len; |
| 5722 | Py_ssize_t i; |
| 5723 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 5724 | if (tmp == NULL) goto failed; |
| 5725 | if (!PyList_Check(tmp)) { |
| 5726 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5727 | goto failed; |
| 5728 | } |
| 5729 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5730 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5731 | if (generators == NULL) goto failed; |
| 5732 | for (i = 0; i < len; i++) { |
| 5733 | comprehension_ty value; |
| 5734 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5735 | if (res != 0) goto failed; |
| 5736 | asdl_seq_SET(generators, i, value); |
| 5737 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5738 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5739 | } else { |
| 5740 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 5741 | return 1; |
| 5742 | } |
| 5743 | *out = SetComp(elt, generators, lineno, col_offset, arena); |
| 5744 | if (*out == NULL) goto failed; |
| 5745 | return 0; |
| 5746 | } |
| 5747 | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
| 5748 | if (isinstance == -1) { |
| 5749 | return 1; |
| 5750 | } |
| 5751 | if (isinstance) { |
| 5752 | expr_ty key; |
| 5753 | expr_ty value; |
| 5754 | asdl_seq* generators; |
| 5755 | |
| 5756 | if (_PyObject_HasAttrId(obj, &PyId_key)) { |
| 5757 | int res; |
| 5758 | tmp = _PyObject_GetAttrId(obj, &PyId_key); |
| 5759 | if (tmp == NULL) goto failed; |
| 5760 | res = obj2ast_expr(tmp, &key, arena); |
| 5761 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5762 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5763 | } else { |
| 5764 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 5765 | return 1; |
| 5766 | } |
| 5767 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5768 | int res; |
| 5769 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5770 | if (tmp == NULL) goto failed; |
| 5771 | res = obj2ast_expr(tmp, &value, arena); |
| 5772 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5773 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5774 | } else { |
| 5775 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 5776 | return 1; |
| 5777 | } |
| 5778 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
| 5779 | int res; |
| 5780 | Py_ssize_t len; |
| 5781 | Py_ssize_t i; |
| 5782 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 5783 | if (tmp == NULL) goto failed; |
| 5784 | if (!PyList_Check(tmp)) { |
| 5785 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5786 | goto failed; |
| 5787 | } |
| 5788 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5789 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5790 | if (generators == NULL) goto failed; |
| 5791 | for (i = 0; i < len; i++) { |
| 5792 | comprehension_ty value; |
| 5793 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5794 | if (res != 0) goto failed; |
| 5795 | asdl_seq_SET(generators, i, value); |
| 5796 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5797 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5798 | } else { |
| 5799 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 5800 | return 1; |
| 5801 | } |
| 5802 | *out = DictComp(key, value, generators, lineno, col_offset, arena); |
| 5803 | if (*out == NULL) goto failed; |
| 5804 | return 0; |
| 5805 | } |
| 5806 | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
| 5807 | if (isinstance == -1) { |
| 5808 | return 1; |
| 5809 | } |
| 5810 | if (isinstance) { |
| 5811 | expr_ty elt; |
| 5812 | asdl_seq* generators; |
| 5813 | |
| 5814 | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
| 5815 | int res; |
| 5816 | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
| 5817 | if (tmp == NULL) goto failed; |
| 5818 | res = obj2ast_expr(tmp, &elt, arena); |
| 5819 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5820 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5821 | } else { |
| 5822 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 5823 | return 1; |
| 5824 | } |
| 5825 | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
| 5826 | int res; |
| 5827 | Py_ssize_t len; |
| 5828 | Py_ssize_t i; |
| 5829 | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
| 5830 | if (tmp == NULL) goto failed; |
| 5831 | if (!PyList_Check(tmp)) { |
| 5832 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5833 | goto failed; |
| 5834 | } |
| 5835 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5836 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5837 | if (generators == NULL) goto failed; |
| 5838 | for (i = 0; i < len; i++) { |
| 5839 | comprehension_ty value; |
| 5840 | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5841 | if (res != 0) goto failed; |
| 5842 | asdl_seq_SET(generators, i, value); |
| 5843 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5844 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5845 | } else { |
| 5846 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 5847 | return 1; |
| 5848 | } |
| 5849 | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
| 5850 | if (*out == NULL) goto failed; |
| 5851 | return 0; |
| 5852 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5853 | isinstance = PyObject_IsInstance(obj, (PyObject*)Await_type); |
| 5854 | if (isinstance == -1) { |
| 5855 | return 1; |
| 5856 | } |
| 5857 | if (isinstance) { |
| 5858 | expr_ty value; |
| 5859 | |
| 5860 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5861 | int res; |
| 5862 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5863 | if (tmp == NULL) goto failed; |
| 5864 | res = obj2ast_expr(tmp, &value, arena); |
| 5865 | if (res != 0) goto failed; |
| 5866 | Py_CLEAR(tmp); |
| 5867 | } else { |
| 5868 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 5869 | return 1; |
| 5870 | } |
| 5871 | *out = Await(value, lineno, col_offset, arena); |
| 5872 | if (*out == NULL) goto failed; |
| 5873 | return 0; |
| 5874 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5875 | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 5876 | if (isinstance == -1) { |
| 5877 | return 1; |
| 5878 | } |
| 5879 | if (isinstance) { |
| 5880 | expr_ty value; |
| 5881 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 5882 | if (exists_not_none(obj, &PyId_value)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5883 | int res; |
| 5884 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5885 | if (tmp == NULL) goto failed; |
| 5886 | res = obj2ast_expr(tmp, &value, arena); |
| 5887 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5888 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5889 | } else { |
| 5890 | value = NULL; |
| 5891 | } |
| 5892 | *out = Yield(value, lineno, col_offset, arena); |
| 5893 | if (*out == NULL) goto failed; |
| 5894 | return 0; |
| 5895 | } |
| 5896 | isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); |
| 5897 | if (isinstance == -1) { |
| 5898 | return 1; |
| 5899 | } |
| 5900 | if (isinstance) { |
| 5901 | expr_ty value; |
| 5902 | |
| 5903 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5904 | int res; |
| 5905 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5906 | if (tmp == NULL) goto failed; |
| 5907 | res = obj2ast_expr(tmp, &value, arena); |
| 5908 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5909 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5910 | } else { |
| 5911 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 5912 | return 1; |
| 5913 | } |
| 5914 | *out = YieldFrom(value, lineno, col_offset, arena); |
| 5915 | if (*out == NULL) goto failed; |
| 5916 | return 0; |
| 5917 | } |
| 5918 | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 5919 | if (isinstance == -1) { |
| 5920 | return 1; |
| 5921 | } |
| 5922 | if (isinstance) { |
| 5923 | expr_ty left; |
| 5924 | asdl_int_seq* ops; |
| 5925 | asdl_seq* comparators; |
| 5926 | |
| 5927 | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
| 5928 | int res; |
| 5929 | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
| 5930 | if (tmp == NULL) goto failed; |
| 5931 | res = obj2ast_expr(tmp, &left, arena); |
| 5932 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5933 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5934 | } else { |
| 5935 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 5936 | return 1; |
| 5937 | } |
| 5938 | if (_PyObject_HasAttrId(obj, &PyId_ops)) { |
| 5939 | int res; |
| 5940 | Py_ssize_t len; |
| 5941 | Py_ssize_t i; |
| 5942 | tmp = _PyObject_GetAttrId(obj, &PyId_ops); |
| 5943 | if (tmp == NULL) goto failed; |
| 5944 | if (!PyList_Check(tmp)) { |
| 5945 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5946 | goto failed; |
| 5947 | } |
| 5948 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5949 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5950 | if (ops == NULL) goto failed; |
| 5951 | for (i = 0; i < len; i++) { |
| 5952 | cmpop_ty value; |
| 5953 | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5954 | if (res != 0) goto failed; |
| 5955 | asdl_seq_SET(ops, i, value); |
| 5956 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5957 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5958 | } else { |
| 5959 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 5960 | return 1; |
| 5961 | } |
| 5962 | if (_PyObject_HasAttrId(obj, &PyId_comparators)) { |
| 5963 | int res; |
| 5964 | Py_ssize_t len; |
| 5965 | Py_ssize_t i; |
| 5966 | tmp = _PyObject_GetAttrId(obj, &PyId_comparators); |
| 5967 | if (tmp == NULL) goto failed; |
| 5968 | if (!PyList_Check(tmp)) { |
| 5969 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 5970 | goto failed; |
| 5971 | } |
| 5972 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5973 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5974 | if (comparators == NULL) goto failed; |
| 5975 | for (i = 0; i < len; i++) { |
| 5976 | expr_ty value; |
| 5977 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 5978 | if (res != 0) goto failed; |
| 5979 | asdl_seq_SET(comparators, i, value); |
| 5980 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5981 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5982 | } else { |
| 5983 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 5984 | return 1; |
| 5985 | } |
| 5986 | *out = Compare(left, ops, comparators, lineno, col_offset, arena); |
| 5987 | if (*out == NULL) goto failed; |
| 5988 | return 0; |
| 5989 | } |
| 5990 | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
| 5991 | if (isinstance == -1) { |
| 5992 | return 1; |
| 5993 | } |
| 5994 | if (isinstance) { |
| 5995 | expr_ty func; |
| 5996 | asdl_seq* args; |
| 5997 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5998 | |
| 5999 | if (_PyObject_HasAttrId(obj, &PyId_func)) { |
| 6000 | int res; |
| 6001 | tmp = _PyObject_GetAttrId(obj, &PyId_func); |
| 6002 | if (tmp == NULL) goto failed; |
| 6003 | res = obj2ast_expr(tmp, &func, arena); |
| 6004 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6005 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6006 | } else { |
| 6007 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 6008 | return 1; |
| 6009 | } |
| 6010 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 6011 | int res; |
| 6012 | Py_ssize_t len; |
| 6013 | Py_ssize_t i; |
| 6014 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 6015 | if (tmp == NULL) goto failed; |
| 6016 | if (!PyList_Check(tmp)) { |
| 6017 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6018 | goto failed; |
| 6019 | } |
| 6020 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6021 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6022 | if (args == NULL) goto failed; |
| 6023 | for (i = 0; i < len; i++) { |
| 6024 | expr_ty value; |
| 6025 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6026 | if (res != 0) goto failed; |
| 6027 | asdl_seq_SET(args, i, value); |
| 6028 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6029 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6030 | } else { |
| 6031 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 6032 | return 1; |
| 6033 | } |
| 6034 | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
| 6035 | int res; |
| 6036 | Py_ssize_t len; |
| 6037 | Py_ssize_t i; |
| 6038 | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
| 6039 | if (tmp == NULL) goto failed; |
| 6040 | if (!PyList_Check(tmp)) { |
| 6041 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6042 | goto failed; |
| 6043 | } |
| 6044 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6045 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6046 | if (keywords == NULL) goto failed; |
| 6047 | for (i = 0; i < len; i++) { |
| 6048 | keyword_ty value; |
| 6049 | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6050 | if (res != 0) goto failed; |
| 6051 | asdl_seq_SET(keywords, i, value); |
| 6052 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6053 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6054 | } else { |
| 6055 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 6056 | return 1; |
| 6057 | } |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 6058 | *out = Call(func, args, keywords, lineno, col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6059 | if (*out == NULL) goto failed; |
| 6060 | return 0; |
| 6061 | } |
| 6062 | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); |
| 6063 | if (isinstance == -1) { |
| 6064 | return 1; |
| 6065 | } |
| 6066 | if (isinstance) { |
| 6067 | object n; |
| 6068 | |
| 6069 | if (_PyObject_HasAttrId(obj, &PyId_n)) { |
| 6070 | int res; |
| 6071 | tmp = _PyObject_GetAttrId(obj, &PyId_n); |
| 6072 | if (tmp == NULL) goto failed; |
| 6073 | res = obj2ast_object(tmp, &n, arena); |
| 6074 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6075 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6076 | } else { |
| 6077 | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
| 6078 | return 1; |
| 6079 | } |
| 6080 | *out = Num(n, lineno, col_offset, arena); |
| 6081 | if (*out == NULL) goto failed; |
| 6082 | return 0; |
| 6083 | } |
| 6084 | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); |
| 6085 | if (isinstance == -1) { |
| 6086 | return 1; |
| 6087 | } |
| 6088 | if (isinstance) { |
| 6089 | string s; |
| 6090 | |
| 6091 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
| 6092 | int res; |
| 6093 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
| 6094 | if (tmp == NULL) goto failed; |
| 6095 | res = obj2ast_string(tmp, &s, arena); |
| 6096 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6097 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6098 | } else { |
| 6099 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
| 6100 | return 1; |
| 6101 | } |
| 6102 | *out = Str(s, lineno, col_offset, arena); |
| 6103 | if (*out == NULL) goto failed; |
| 6104 | return 0; |
| 6105 | } |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame^] | 6106 | isinstance = PyObject_IsInstance(obj, (PyObject*)FormattedValue_type); |
| 6107 | if (isinstance == -1) { |
| 6108 | return 1; |
| 6109 | } |
| 6110 | if (isinstance) { |
| 6111 | expr_ty value; |
| 6112 | int conversion; |
| 6113 | expr_ty format_spec; |
| 6114 | |
| 6115 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6116 | int res; |
| 6117 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6118 | if (tmp == NULL) goto failed; |
| 6119 | res = obj2ast_expr(tmp, &value, arena); |
| 6120 | if (res != 0) goto failed; |
| 6121 | Py_CLEAR(tmp); |
| 6122 | } else { |
| 6123 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 6124 | return 1; |
| 6125 | } |
| 6126 | if (exists_not_none(obj, &PyId_conversion)) { |
| 6127 | int res; |
| 6128 | tmp = _PyObject_GetAttrId(obj, &PyId_conversion); |
| 6129 | if (tmp == NULL) goto failed; |
| 6130 | res = obj2ast_int(tmp, &conversion, arena); |
| 6131 | if (res != 0) goto failed; |
| 6132 | Py_CLEAR(tmp); |
| 6133 | } else { |
| 6134 | conversion = 0; |
| 6135 | } |
| 6136 | if (exists_not_none(obj, &PyId_format_spec)) { |
| 6137 | int res; |
| 6138 | tmp = _PyObject_GetAttrId(obj, &PyId_format_spec); |
| 6139 | if (tmp == NULL) goto failed; |
| 6140 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 6141 | if (res != 0) goto failed; |
| 6142 | Py_CLEAR(tmp); |
| 6143 | } else { |
| 6144 | format_spec = NULL; |
| 6145 | } |
| 6146 | *out = FormattedValue(value, conversion, format_spec, lineno, |
| 6147 | col_offset, arena); |
| 6148 | if (*out == NULL) goto failed; |
| 6149 | return 0; |
| 6150 | } |
| 6151 | isinstance = PyObject_IsInstance(obj, (PyObject*)JoinedStr_type); |
| 6152 | if (isinstance == -1) { |
| 6153 | return 1; |
| 6154 | } |
| 6155 | if (isinstance) { |
| 6156 | asdl_seq* values; |
| 6157 | |
| 6158 | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
| 6159 | int res; |
| 6160 | Py_ssize_t len; |
| 6161 | Py_ssize_t i; |
| 6162 | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
| 6163 | if (tmp == NULL) goto failed; |
| 6164 | if (!PyList_Check(tmp)) { |
| 6165 | PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6166 | goto failed; |
| 6167 | } |
| 6168 | len = PyList_GET_SIZE(tmp); |
| 6169 | values = _Py_asdl_seq_new(len, arena); |
| 6170 | if (values == NULL) goto failed; |
| 6171 | for (i = 0; i < len; i++) { |
| 6172 | expr_ty value; |
| 6173 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6174 | if (res != 0) goto failed; |
| 6175 | asdl_seq_SET(values, i, value); |
| 6176 | } |
| 6177 | Py_CLEAR(tmp); |
| 6178 | } else { |
| 6179 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 6180 | return 1; |
| 6181 | } |
| 6182 | *out = JoinedStr(values, lineno, col_offset, arena); |
| 6183 | if (*out == NULL) goto failed; |
| 6184 | return 0; |
| 6185 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6186 | isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); |
| 6187 | if (isinstance == -1) { |
| 6188 | return 1; |
| 6189 | } |
| 6190 | if (isinstance) { |
| 6191 | bytes s; |
| 6192 | |
| 6193 | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
| 6194 | int res; |
| 6195 | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
| 6196 | if (tmp == NULL) goto failed; |
| 6197 | res = obj2ast_bytes(tmp, &s, arena); |
| 6198 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6199 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6200 | } else { |
| 6201 | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); |
| 6202 | return 1; |
| 6203 | } |
| 6204 | *out = Bytes(s, lineno, col_offset, arena); |
| 6205 | if (*out == NULL) goto failed; |
| 6206 | return 0; |
| 6207 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6208 | isinstance = PyObject_IsInstance(obj, (PyObject*)NameConstant_type); |
| 6209 | if (isinstance == -1) { |
| 6210 | return 1; |
| 6211 | } |
| 6212 | if (isinstance) { |
| 6213 | singleton value; |
| 6214 | |
| 6215 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6216 | int res; |
| 6217 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6218 | if (tmp == NULL) goto failed; |
| 6219 | res = obj2ast_singleton(tmp, &value, arena); |
| 6220 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 6221 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6222 | } else { |
| 6223 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NameConstant"); |
| 6224 | return 1; |
| 6225 | } |
| 6226 | *out = NameConstant(value, lineno, col_offset, arena); |
| 6227 | if (*out == NULL) goto failed; |
| 6228 | return 0; |
| 6229 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6230 | isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); |
| 6231 | if (isinstance == -1) { |
| 6232 | return 1; |
| 6233 | } |
| 6234 | if (isinstance) { |
| 6235 | |
| 6236 | *out = Ellipsis(lineno, col_offset, arena); |
| 6237 | if (*out == NULL) goto failed; |
| 6238 | return 0; |
| 6239 | } |
| 6240 | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
| 6241 | if (isinstance == -1) { |
| 6242 | return 1; |
| 6243 | } |
| 6244 | if (isinstance) { |
| 6245 | expr_ty value; |
| 6246 | identifier attr; |
| 6247 | expr_context_ty ctx; |
| 6248 | |
| 6249 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6250 | int res; |
| 6251 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6252 | if (tmp == NULL) goto failed; |
| 6253 | res = obj2ast_expr(tmp, &value, arena); |
| 6254 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6255 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6256 | } else { |
| 6257 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 6258 | return 1; |
| 6259 | } |
| 6260 | if (_PyObject_HasAttrId(obj, &PyId_attr)) { |
| 6261 | int res; |
| 6262 | tmp = _PyObject_GetAttrId(obj, &PyId_attr); |
| 6263 | if (tmp == NULL) goto failed; |
| 6264 | res = obj2ast_identifier(tmp, &attr, arena); |
| 6265 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6266 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6267 | } else { |
| 6268 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 6269 | return 1; |
| 6270 | } |
| 6271 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6272 | int res; |
| 6273 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6274 | if (tmp == NULL) goto failed; |
| 6275 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6276 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6277 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6278 | } else { |
| 6279 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 6280 | return 1; |
| 6281 | } |
| 6282 | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
| 6283 | if (*out == NULL) goto failed; |
| 6284 | return 0; |
| 6285 | } |
| 6286 | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
| 6287 | if (isinstance == -1) { |
| 6288 | return 1; |
| 6289 | } |
| 6290 | if (isinstance) { |
| 6291 | expr_ty value; |
| 6292 | slice_ty slice; |
| 6293 | expr_context_ty ctx; |
| 6294 | |
| 6295 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6296 | int res; |
| 6297 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6298 | if (tmp == NULL) goto failed; |
| 6299 | res = obj2ast_expr(tmp, &value, arena); |
| 6300 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6301 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6302 | } else { |
| 6303 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 6304 | return 1; |
| 6305 | } |
| 6306 | if (_PyObject_HasAttrId(obj, &PyId_slice)) { |
| 6307 | int res; |
| 6308 | tmp = _PyObject_GetAttrId(obj, &PyId_slice); |
| 6309 | if (tmp == NULL) goto failed; |
| 6310 | res = obj2ast_slice(tmp, &slice, arena); |
| 6311 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6312 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6313 | } else { |
| 6314 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 6315 | return 1; |
| 6316 | } |
| 6317 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6318 | int res; |
| 6319 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6320 | if (tmp == NULL) goto failed; |
| 6321 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6322 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6323 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6324 | } else { |
| 6325 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 6326 | return 1; |
| 6327 | } |
| 6328 | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
| 6329 | if (*out == NULL) goto failed; |
| 6330 | return 0; |
| 6331 | } |
| 6332 | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
| 6333 | if (isinstance == -1) { |
| 6334 | return 1; |
| 6335 | } |
| 6336 | if (isinstance) { |
| 6337 | expr_ty value; |
| 6338 | expr_context_ty ctx; |
| 6339 | |
| 6340 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6341 | int res; |
| 6342 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6343 | if (tmp == NULL) goto failed; |
| 6344 | res = obj2ast_expr(tmp, &value, arena); |
| 6345 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6346 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6347 | } else { |
| 6348 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 6349 | return 1; |
| 6350 | } |
| 6351 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6352 | int res; |
| 6353 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6354 | if (tmp == NULL) goto failed; |
| 6355 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6356 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6357 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6358 | } else { |
| 6359 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 6360 | return 1; |
| 6361 | } |
| 6362 | *out = Starred(value, ctx, lineno, col_offset, arena); |
| 6363 | if (*out == NULL) goto failed; |
| 6364 | return 0; |
| 6365 | } |
| 6366 | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
| 6367 | if (isinstance == -1) { |
| 6368 | return 1; |
| 6369 | } |
| 6370 | if (isinstance) { |
| 6371 | identifier id; |
| 6372 | expr_context_ty ctx; |
| 6373 | |
| 6374 | if (_PyObject_HasAttrId(obj, &PyId_id)) { |
| 6375 | int res; |
| 6376 | tmp = _PyObject_GetAttrId(obj, &PyId_id); |
| 6377 | if (tmp == NULL) goto failed; |
| 6378 | res = obj2ast_identifier(tmp, &id, arena); |
| 6379 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6380 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6381 | } else { |
| 6382 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 6383 | return 1; |
| 6384 | } |
| 6385 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6386 | int res; |
| 6387 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6388 | if (tmp == NULL) goto failed; |
| 6389 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6390 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6391 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6392 | } else { |
| 6393 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 6394 | return 1; |
| 6395 | } |
| 6396 | *out = Name(id, ctx, lineno, col_offset, arena); |
| 6397 | if (*out == NULL) goto failed; |
| 6398 | return 0; |
| 6399 | } |
| 6400 | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
| 6401 | if (isinstance == -1) { |
| 6402 | return 1; |
| 6403 | } |
| 6404 | if (isinstance) { |
| 6405 | asdl_seq* elts; |
| 6406 | expr_context_ty ctx; |
| 6407 | |
| 6408 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
| 6409 | int res; |
| 6410 | Py_ssize_t len; |
| 6411 | Py_ssize_t i; |
| 6412 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
| 6413 | if (tmp == NULL) goto failed; |
| 6414 | if (!PyList_Check(tmp)) { |
| 6415 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6416 | goto failed; |
| 6417 | } |
| 6418 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6419 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6420 | if (elts == NULL) goto failed; |
| 6421 | for (i = 0; i < len; i++) { |
| 6422 | expr_ty value; |
| 6423 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6424 | if (res != 0) goto failed; |
| 6425 | asdl_seq_SET(elts, i, value); |
| 6426 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6427 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6428 | } else { |
| 6429 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 6430 | return 1; |
| 6431 | } |
| 6432 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6433 | int res; |
| 6434 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6435 | if (tmp == NULL) goto failed; |
| 6436 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6437 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6438 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6439 | } else { |
| 6440 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 6441 | return 1; |
| 6442 | } |
| 6443 | *out = List(elts, ctx, lineno, col_offset, arena); |
| 6444 | if (*out == NULL) goto failed; |
| 6445 | return 0; |
| 6446 | } |
| 6447 | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
| 6448 | if (isinstance == -1) { |
| 6449 | return 1; |
| 6450 | } |
| 6451 | if (isinstance) { |
| 6452 | asdl_seq* elts; |
| 6453 | expr_context_ty ctx; |
| 6454 | |
| 6455 | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
| 6456 | int res; |
| 6457 | Py_ssize_t len; |
| 6458 | Py_ssize_t i; |
| 6459 | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
| 6460 | if (tmp == NULL) goto failed; |
| 6461 | if (!PyList_Check(tmp)) { |
| 6462 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6463 | goto failed; |
| 6464 | } |
| 6465 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6466 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6467 | if (elts == NULL) goto failed; |
| 6468 | for (i = 0; i < len; i++) { |
| 6469 | expr_ty value; |
| 6470 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6471 | if (res != 0) goto failed; |
| 6472 | asdl_seq_SET(elts, i, value); |
| 6473 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6474 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6475 | } else { |
| 6476 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 6477 | return 1; |
| 6478 | } |
| 6479 | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
| 6480 | int res; |
| 6481 | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
| 6482 | if (tmp == NULL) goto failed; |
| 6483 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 6484 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6485 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6486 | } else { |
| 6487 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 6488 | return 1; |
| 6489 | } |
| 6490 | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
| 6491 | if (*out == NULL) goto failed; |
| 6492 | return 0; |
| 6493 | } |
| 6494 | |
| 6495 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 6496 | failed: |
| 6497 | Py_XDECREF(tmp); |
| 6498 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6499 | } |
| 6500 | |
| 6501 | int |
| 6502 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 6503 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6504 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6505 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6506 | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
| 6507 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6508 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6509 | } |
| 6510 | if (isinstance) { |
| 6511 | *out = Load; |
| 6512 | return 0; |
| 6513 | } |
| 6514 | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
| 6515 | if (isinstance == -1) { |
| 6516 | return 1; |
| 6517 | } |
| 6518 | if (isinstance) { |
| 6519 | *out = Store; |
| 6520 | return 0; |
| 6521 | } |
| 6522 | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
| 6523 | if (isinstance == -1) { |
| 6524 | return 1; |
| 6525 | } |
| 6526 | if (isinstance) { |
| 6527 | *out = Del; |
| 6528 | return 0; |
| 6529 | } |
| 6530 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
| 6531 | if (isinstance == -1) { |
| 6532 | return 1; |
| 6533 | } |
| 6534 | if (isinstance) { |
| 6535 | *out = AugLoad; |
| 6536 | return 0; |
| 6537 | } |
| 6538 | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
| 6539 | if (isinstance == -1) { |
| 6540 | return 1; |
| 6541 | } |
| 6542 | if (isinstance) { |
| 6543 | *out = AugStore; |
| 6544 | return 0; |
| 6545 | } |
| 6546 | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
| 6547 | if (isinstance == -1) { |
| 6548 | return 1; |
| 6549 | } |
| 6550 | if (isinstance) { |
| 6551 | *out = Param; |
| 6552 | return 0; |
| 6553 | } |
| 6554 | |
| 6555 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 6556 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6557 | } |
| 6558 | |
| 6559 | int |
| 6560 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 6561 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6562 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6563 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6564 | PyObject *tmp = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6565 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6566 | if (obj == Py_None) { |
| 6567 | *out = NULL; |
| 6568 | return 0; |
| 6569 | } |
| 6570 | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
| 6571 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6572 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6573 | } |
| 6574 | if (isinstance) { |
| 6575 | expr_ty lower; |
| 6576 | expr_ty upper; |
| 6577 | expr_ty step; |
| 6578 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6579 | if (exists_not_none(obj, &PyId_lower)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6580 | int res; |
| 6581 | tmp = _PyObject_GetAttrId(obj, &PyId_lower); |
| 6582 | if (tmp == NULL) goto failed; |
| 6583 | res = obj2ast_expr(tmp, &lower, arena); |
| 6584 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6585 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6586 | } else { |
| 6587 | lower = NULL; |
| 6588 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6589 | if (exists_not_none(obj, &PyId_upper)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6590 | int res; |
| 6591 | tmp = _PyObject_GetAttrId(obj, &PyId_upper); |
| 6592 | if (tmp == NULL) goto failed; |
| 6593 | res = obj2ast_expr(tmp, &upper, arena); |
| 6594 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6595 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6596 | } else { |
| 6597 | upper = NULL; |
| 6598 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 6599 | if (exists_not_none(obj, &PyId_step)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6600 | int res; |
| 6601 | tmp = _PyObject_GetAttrId(obj, &PyId_step); |
| 6602 | if (tmp == NULL) goto failed; |
| 6603 | res = obj2ast_expr(tmp, &step, arena); |
| 6604 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6605 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6606 | } else { |
| 6607 | step = NULL; |
| 6608 | } |
| 6609 | *out = Slice(lower, upper, step, arena); |
| 6610 | if (*out == NULL) goto failed; |
| 6611 | return 0; |
| 6612 | } |
| 6613 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
| 6614 | if (isinstance == -1) { |
| 6615 | return 1; |
| 6616 | } |
| 6617 | if (isinstance) { |
| 6618 | asdl_seq* dims; |
| 6619 | |
| 6620 | if (_PyObject_HasAttrId(obj, &PyId_dims)) { |
| 6621 | int res; |
| 6622 | Py_ssize_t len; |
| 6623 | Py_ssize_t i; |
| 6624 | tmp = _PyObject_GetAttrId(obj, &PyId_dims); |
| 6625 | if (tmp == NULL) goto failed; |
| 6626 | if (!PyList_Check(tmp)) { |
| 6627 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6628 | goto failed; |
| 6629 | } |
| 6630 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6631 | dims = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6632 | if (dims == NULL) goto failed; |
| 6633 | for (i = 0; i < len; i++) { |
| 6634 | slice_ty value; |
| 6635 | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6636 | if (res != 0) goto failed; |
| 6637 | asdl_seq_SET(dims, i, value); |
| 6638 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6639 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6640 | } else { |
| 6641 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 6642 | return 1; |
| 6643 | } |
| 6644 | *out = ExtSlice(dims, arena); |
| 6645 | if (*out == NULL) goto failed; |
| 6646 | return 0; |
| 6647 | } |
| 6648 | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
| 6649 | if (isinstance == -1) { |
| 6650 | return 1; |
| 6651 | } |
| 6652 | if (isinstance) { |
| 6653 | expr_ty value; |
| 6654 | |
| 6655 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 6656 | int res; |
| 6657 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 6658 | if (tmp == NULL) goto failed; |
| 6659 | res = obj2ast_expr(tmp, &value, arena); |
| 6660 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6661 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6662 | } else { |
| 6663 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 6664 | return 1; |
| 6665 | } |
| 6666 | *out = Index(value, arena); |
| 6667 | if (*out == NULL) goto failed; |
| 6668 | return 0; |
| 6669 | } |
| 6670 | |
| 6671 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 6672 | failed: |
| 6673 | Py_XDECREF(tmp); |
| 6674 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6675 | } |
| 6676 | |
| 6677 | int |
| 6678 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 6679 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6680 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6681 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6682 | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
| 6683 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6684 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6685 | } |
| 6686 | if (isinstance) { |
| 6687 | *out = And; |
| 6688 | return 0; |
| 6689 | } |
| 6690 | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
| 6691 | if (isinstance == -1) { |
| 6692 | return 1; |
| 6693 | } |
| 6694 | if (isinstance) { |
| 6695 | *out = Or; |
| 6696 | return 0; |
| 6697 | } |
| 6698 | |
| 6699 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 6700 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6701 | } |
| 6702 | |
| 6703 | int |
| 6704 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 6705 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6706 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6707 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6708 | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
| 6709 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6710 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6711 | } |
| 6712 | if (isinstance) { |
| 6713 | *out = Add; |
| 6714 | return 0; |
| 6715 | } |
| 6716 | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
| 6717 | if (isinstance == -1) { |
| 6718 | return 1; |
| 6719 | } |
| 6720 | if (isinstance) { |
| 6721 | *out = Sub; |
| 6722 | return 0; |
| 6723 | } |
| 6724 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
| 6725 | if (isinstance == -1) { |
| 6726 | return 1; |
| 6727 | } |
| 6728 | if (isinstance) { |
| 6729 | *out = Mult; |
| 6730 | return 0; |
| 6731 | } |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 6732 | isinstance = PyObject_IsInstance(obj, (PyObject *)MatMult_type); |
| 6733 | if (isinstance == -1) { |
| 6734 | return 1; |
| 6735 | } |
| 6736 | if (isinstance) { |
| 6737 | *out = MatMult; |
| 6738 | return 0; |
| 6739 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6740 | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
| 6741 | if (isinstance == -1) { |
| 6742 | return 1; |
| 6743 | } |
| 6744 | if (isinstance) { |
| 6745 | *out = Div; |
| 6746 | return 0; |
| 6747 | } |
| 6748 | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
| 6749 | if (isinstance == -1) { |
| 6750 | return 1; |
| 6751 | } |
| 6752 | if (isinstance) { |
| 6753 | *out = Mod; |
| 6754 | return 0; |
| 6755 | } |
| 6756 | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
| 6757 | if (isinstance == -1) { |
| 6758 | return 1; |
| 6759 | } |
| 6760 | if (isinstance) { |
| 6761 | *out = Pow; |
| 6762 | return 0; |
| 6763 | } |
| 6764 | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
| 6765 | if (isinstance == -1) { |
| 6766 | return 1; |
| 6767 | } |
| 6768 | if (isinstance) { |
| 6769 | *out = LShift; |
| 6770 | return 0; |
| 6771 | } |
| 6772 | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
| 6773 | if (isinstance == -1) { |
| 6774 | return 1; |
| 6775 | } |
| 6776 | if (isinstance) { |
| 6777 | *out = RShift; |
| 6778 | return 0; |
| 6779 | } |
| 6780 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
| 6781 | if (isinstance == -1) { |
| 6782 | return 1; |
| 6783 | } |
| 6784 | if (isinstance) { |
| 6785 | *out = BitOr; |
| 6786 | return 0; |
| 6787 | } |
| 6788 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
| 6789 | if (isinstance == -1) { |
| 6790 | return 1; |
| 6791 | } |
| 6792 | if (isinstance) { |
| 6793 | *out = BitXor; |
| 6794 | return 0; |
| 6795 | } |
| 6796 | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
| 6797 | if (isinstance == -1) { |
| 6798 | return 1; |
| 6799 | } |
| 6800 | if (isinstance) { |
| 6801 | *out = BitAnd; |
| 6802 | return 0; |
| 6803 | } |
| 6804 | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
| 6805 | if (isinstance == -1) { |
| 6806 | return 1; |
| 6807 | } |
| 6808 | if (isinstance) { |
| 6809 | *out = FloorDiv; |
| 6810 | return 0; |
| 6811 | } |
| 6812 | |
| 6813 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 6814 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6815 | } |
| 6816 | |
| 6817 | int |
| 6818 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 6819 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6820 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6821 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6822 | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
| 6823 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6824 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6825 | } |
| 6826 | if (isinstance) { |
| 6827 | *out = Invert; |
| 6828 | return 0; |
| 6829 | } |
| 6830 | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
| 6831 | if (isinstance == -1) { |
| 6832 | return 1; |
| 6833 | } |
| 6834 | if (isinstance) { |
| 6835 | *out = Not; |
| 6836 | return 0; |
| 6837 | } |
| 6838 | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
| 6839 | if (isinstance == -1) { |
| 6840 | return 1; |
| 6841 | } |
| 6842 | if (isinstance) { |
| 6843 | *out = UAdd; |
| 6844 | return 0; |
| 6845 | } |
| 6846 | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
| 6847 | if (isinstance == -1) { |
| 6848 | return 1; |
| 6849 | } |
| 6850 | if (isinstance) { |
| 6851 | *out = USub; |
| 6852 | return 0; |
| 6853 | } |
| 6854 | |
| 6855 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 6856 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6857 | } |
| 6858 | |
| 6859 | int |
| 6860 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 6861 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6862 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6863 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6864 | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
| 6865 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6866 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6867 | } |
| 6868 | if (isinstance) { |
| 6869 | *out = Eq; |
| 6870 | return 0; |
| 6871 | } |
| 6872 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
| 6873 | if (isinstance == -1) { |
| 6874 | return 1; |
| 6875 | } |
| 6876 | if (isinstance) { |
| 6877 | *out = NotEq; |
| 6878 | return 0; |
| 6879 | } |
| 6880 | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
| 6881 | if (isinstance == -1) { |
| 6882 | return 1; |
| 6883 | } |
| 6884 | if (isinstance) { |
| 6885 | *out = Lt; |
| 6886 | return 0; |
| 6887 | } |
| 6888 | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
| 6889 | if (isinstance == -1) { |
| 6890 | return 1; |
| 6891 | } |
| 6892 | if (isinstance) { |
| 6893 | *out = LtE; |
| 6894 | return 0; |
| 6895 | } |
| 6896 | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
| 6897 | if (isinstance == -1) { |
| 6898 | return 1; |
| 6899 | } |
| 6900 | if (isinstance) { |
| 6901 | *out = Gt; |
| 6902 | return 0; |
| 6903 | } |
| 6904 | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
| 6905 | if (isinstance == -1) { |
| 6906 | return 1; |
| 6907 | } |
| 6908 | if (isinstance) { |
| 6909 | *out = GtE; |
| 6910 | return 0; |
| 6911 | } |
| 6912 | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
| 6913 | if (isinstance == -1) { |
| 6914 | return 1; |
| 6915 | } |
| 6916 | if (isinstance) { |
| 6917 | *out = Is; |
| 6918 | return 0; |
| 6919 | } |
| 6920 | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
| 6921 | if (isinstance == -1) { |
| 6922 | return 1; |
| 6923 | } |
| 6924 | if (isinstance) { |
| 6925 | *out = IsNot; |
| 6926 | return 0; |
| 6927 | } |
| 6928 | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
| 6929 | if (isinstance == -1) { |
| 6930 | return 1; |
| 6931 | } |
| 6932 | if (isinstance) { |
| 6933 | *out = In; |
| 6934 | return 0; |
| 6935 | } |
| 6936 | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
| 6937 | if (isinstance == -1) { |
| 6938 | return 1; |
| 6939 | } |
| 6940 | if (isinstance) { |
| 6941 | *out = NotIn; |
| 6942 | return 0; |
| 6943 | } |
| 6944 | |
| 6945 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 6946 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6947 | } |
| 6948 | |
| 6949 | int |
| 6950 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 6951 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6952 | PyObject* tmp = NULL; |
| 6953 | expr_ty target; |
| 6954 | expr_ty iter; |
| 6955 | asdl_seq* ifs; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6956 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6957 | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
| 6958 | int res; |
| 6959 | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
| 6960 | if (tmp == NULL) goto failed; |
| 6961 | res = obj2ast_expr(tmp, &target, arena); |
| 6962 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6963 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6964 | } else { |
| 6965 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 6966 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6967 | } |
| 6968 | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
| 6969 | int res; |
| 6970 | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
| 6971 | if (tmp == NULL) goto failed; |
| 6972 | res = obj2ast_expr(tmp, &iter, arena); |
| 6973 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6974 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6975 | } else { |
| 6976 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 6977 | return 1; |
| 6978 | } |
| 6979 | if (_PyObject_HasAttrId(obj, &PyId_ifs)) { |
| 6980 | int res; |
| 6981 | Py_ssize_t len; |
| 6982 | Py_ssize_t i; |
| 6983 | tmp = _PyObject_GetAttrId(obj, &PyId_ifs); |
| 6984 | if (tmp == NULL) goto failed; |
| 6985 | if (!PyList_Check(tmp)) { |
| 6986 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 6987 | goto failed; |
| 6988 | } |
| 6989 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6990 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6991 | if (ifs == NULL) goto failed; |
| 6992 | for (i = 0; i < len; i++) { |
| 6993 | expr_ty value; |
| 6994 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 6995 | if (res != 0) goto failed; |
| 6996 | asdl_seq_SET(ifs, i, value); |
| 6997 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6998 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6999 | } else { |
| 7000 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 7001 | return 1; |
| 7002 | } |
| 7003 | *out = comprehension(target, iter, ifs, arena); |
| 7004 | return 0; |
| 7005 | failed: |
| 7006 | Py_XDECREF(tmp); |
| 7007 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7008 | } |
| 7009 | |
| 7010 | int |
| 7011 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 7012 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7013 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 7014 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7015 | PyObject *tmp = NULL; |
| 7016 | int lineno; |
| 7017 | int col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7018 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7019 | if (obj == Py_None) { |
| 7020 | *out = NULL; |
| 7021 | return 0; |
| 7022 | } |
| 7023 | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
| 7024 | int res; |
| 7025 | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
| 7026 | if (tmp == NULL) goto failed; |
| 7027 | res = obj2ast_int(tmp, &lineno, arena); |
| 7028 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7029 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7030 | } else { |
| 7031 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7032 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7033 | } |
| 7034 | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
| 7035 | int res; |
| 7036 | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
| 7037 | if (tmp == NULL) goto failed; |
| 7038 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7039 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7040 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7041 | } else { |
| 7042 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 7043 | return 1; |
| 7044 | } |
| 7045 | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
| 7046 | if (isinstance == -1) { |
| 7047 | return 1; |
| 7048 | } |
| 7049 | if (isinstance) { |
| 7050 | expr_ty type; |
| 7051 | identifier name; |
| 7052 | asdl_seq* body; |
| 7053 | |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7054 | if (exists_not_none(obj, &PyId_type)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7055 | int res; |
| 7056 | tmp = _PyObject_GetAttrId(obj, &PyId_type); |
| 7057 | if (tmp == NULL) goto failed; |
| 7058 | res = obj2ast_expr(tmp, &type, arena); |
| 7059 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7060 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7061 | } else { |
| 7062 | type = NULL; |
| 7063 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7064 | if (exists_not_none(obj, &PyId_name)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7065 | int res; |
| 7066 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 7067 | if (tmp == NULL) goto failed; |
| 7068 | res = obj2ast_identifier(tmp, &name, arena); |
| 7069 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7070 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7071 | } else { |
| 7072 | name = NULL; |
| 7073 | } |
| 7074 | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
| 7075 | int res; |
| 7076 | Py_ssize_t len; |
| 7077 | Py_ssize_t i; |
| 7078 | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
| 7079 | if (tmp == NULL) goto failed; |
| 7080 | if (!PyList_Check(tmp)) { |
| 7081 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7082 | goto failed; |
| 7083 | } |
| 7084 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7085 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7086 | if (body == NULL) goto failed; |
| 7087 | for (i = 0; i < len; i++) { |
| 7088 | stmt_ty value; |
| 7089 | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
| 7090 | if (res != 0) goto failed; |
| 7091 | asdl_seq_SET(body, i, value); |
| 7092 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7093 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7094 | } else { |
| 7095 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 7096 | return 1; |
| 7097 | } |
| 7098 | *out = ExceptHandler(type, name, body, lineno, col_offset, arena); |
| 7099 | if (*out == NULL) goto failed; |
| 7100 | return 0; |
| 7101 | } |
| 7102 | |
| 7103 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 7104 | failed: |
| 7105 | Py_XDECREF(tmp); |
| 7106 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7107 | } |
| 7108 | |
| 7109 | int |
| 7110 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 7111 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7112 | PyObject* tmp = NULL; |
| 7113 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7114 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7115 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7116 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7117 | arg_ty kwarg; |
| 7118 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7119 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7120 | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
| 7121 | int res; |
| 7122 | Py_ssize_t len; |
| 7123 | Py_ssize_t i; |
| 7124 | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
| 7125 | if (tmp == NULL) goto failed; |
| 7126 | if (!PyList_Check(tmp)) { |
| 7127 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7128 | goto failed; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7129 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7130 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7131 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7132 | if (args == NULL) goto failed; |
| 7133 | for (i = 0; i < len; i++) { |
| 7134 | arg_ty value; |
| 7135 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 7136 | if (res != 0) goto failed; |
| 7137 | asdl_seq_SET(args, i, value); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7138 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7139 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7140 | } else { |
| 7141 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7142 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7143 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7144 | if (exists_not_none(obj, &PyId_vararg)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7145 | int res; |
| 7146 | tmp = _PyObject_GetAttrId(obj, &PyId_vararg); |
| 7147 | if (tmp == NULL) goto failed; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7148 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7149 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7150 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7151 | } else { |
| 7152 | vararg = NULL; |
| 7153 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7154 | if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) { |
| 7155 | int res; |
| 7156 | Py_ssize_t len; |
| 7157 | Py_ssize_t i; |
| 7158 | tmp = _PyObject_GetAttrId(obj, &PyId_kwonlyargs); |
| 7159 | if (tmp == NULL) goto failed; |
| 7160 | if (!PyList_Check(tmp)) { |
| 7161 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7162 | goto failed; |
| 7163 | } |
| 7164 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7165 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7166 | if (kwonlyargs == NULL) goto failed; |
| 7167 | for (i = 0; i < len; i++) { |
| 7168 | arg_ty value; |
| 7169 | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
| 7170 | if (res != 0) goto failed; |
| 7171 | asdl_seq_SET(kwonlyargs, i, value); |
| 7172 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7173 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7174 | } else { |
| 7175 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 7176 | return 1; |
| 7177 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7178 | if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) { |
| 7179 | int res; |
| 7180 | Py_ssize_t len; |
| 7181 | Py_ssize_t i; |
| 7182 | tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults); |
| 7183 | if (tmp == NULL) goto failed; |
| 7184 | if (!PyList_Check(tmp)) { |
| 7185 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7186 | goto failed; |
| 7187 | } |
| 7188 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7189 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7190 | if (kw_defaults == NULL) goto failed; |
| 7191 | for (i = 0; i < len; i++) { |
| 7192 | expr_ty value; |
| 7193 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 7194 | if (res != 0) goto failed; |
| 7195 | asdl_seq_SET(kw_defaults, i, value); |
| 7196 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7197 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7198 | } else { |
| 7199 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 7200 | return 1; |
| 7201 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7202 | if (exists_not_none(obj, &PyId_kwarg)) { |
| 7203 | int res; |
| 7204 | tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); |
| 7205 | if (tmp == NULL) goto failed; |
| 7206 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 7207 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 7208 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7209 | } else { |
| 7210 | kwarg = NULL; |
| 7211 | } |
| 7212 | if (_PyObject_HasAttrId(obj, &PyId_defaults)) { |
| 7213 | int res; |
| 7214 | Py_ssize_t len; |
| 7215 | Py_ssize_t i; |
| 7216 | tmp = _PyObject_GetAttrId(obj, &PyId_defaults); |
| 7217 | if (tmp == NULL) goto failed; |
| 7218 | if (!PyList_Check(tmp)) { |
| 7219 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
| 7220 | goto failed; |
| 7221 | } |
| 7222 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7223 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7224 | if (defaults == NULL) goto failed; |
| 7225 | for (i = 0; i < len; i++) { |
| 7226 | expr_ty value; |
| 7227 | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
| 7228 | if (res != 0) goto failed; |
| 7229 | asdl_seq_SET(defaults, i, value); |
| 7230 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 7231 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7232 | } else { |
| 7233 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 7234 | return 1; |
| 7235 | } |
| 7236 | *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg, defaults, |
| 7237 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7238 | return 0; |
| 7239 | failed: |
| 7240 | Py_XDECREF(tmp); |
| 7241 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7242 | } |
| 7243 | |
| 7244 | int |
| 7245 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 7246 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7247 | PyObject* tmp = NULL; |
| 7248 | identifier arg; |
| 7249 | expr_ty annotation; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7250 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7251 | if (_PyObject_HasAttrId(obj, &PyId_arg)) { |
| 7252 | int res; |
| 7253 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
| 7254 | if (tmp == NULL) goto failed; |
| 7255 | res = obj2ast_identifier(tmp, &arg, arena); |
| 7256 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7257 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7258 | } else { |
| 7259 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7260 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7261 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7262 | if (exists_not_none(obj, &PyId_annotation)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7263 | int res; |
| 7264 | tmp = _PyObject_GetAttrId(obj, &PyId_annotation); |
| 7265 | if (tmp == NULL) goto failed; |
| 7266 | res = obj2ast_expr(tmp, &annotation, arena); |
| 7267 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7268 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7269 | } else { |
| 7270 | annotation = NULL; |
| 7271 | } |
| 7272 | *out = arg(arg, annotation, arena); |
| 7273 | return 0; |
| 7274 | failed: |
| 7275 | Py_XDECREF(tmp); |
| 7276 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7277 | } |
| 7278 | |
| 7279 | int |
| 7280 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 7281 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7282 | PyObject* tmp = NULL; |
| 7283 | identifier arg; |
| 7284 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7285 | |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 7286 | if (exists_not_none(obj, &PyId_arg)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7287 | int res; |
| 7288 | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
| 7289 | if (tmp == NULL) goto failed; |
| 7290 | res = obj2ast_identifier(tmp, &arg, arena); |
| 7291 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7292 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7293 | } else { |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 7294 | arg = NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7295 | } |
| 7296 | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 7297 | int res; |
| 7298 | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 7299 | if (tmp == NULL) goto failed; |
| 7300 | res = obj2ast_expr(tmp, &value, arena); |
| 7301 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7302 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7303 | } else { |
| 7304 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 7305 | return 1; |
| 7306 | } |
| 7307 | *out = keyword(arg, value, arena); |
| 7308 | return 0; |
| 7309 | failed: |
| 7310 | Py_XDECREF(tmp); |
| 7311 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7312 | } |
| 7313 | |
| 7314 | int |
| 7315 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 7316 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7317 | PyObject* tmp = NULL; |
| 7318 | identifier name; |
| 7319 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7320 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7321 | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
| 7322 | int res; |
| 7323 | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
| 7324 | if (tmp == NULL) goto failed; |
| 7325 | res = obj2ast_identifier(tmp, &name, arena); |
| 7326 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7327 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7328 | } else { |
| 7329 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7330 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7331 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7332 | if (exists_not_none(obj, &PyId_asname)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7333 | int res; |
| 7334 | tmp = _PyObject_GetAttrId(obj, &PyId_asname); |
| 7335 | if (tmp == NULL) goto failed; |
| 7336 | res = obj2ast_identifier(tmp, &asname, arena); |
| 7337 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7338 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7339 | } else { |
| 7340 | asname = NULL; |
| 7341 | } |
| 7342 | *out = alias(name, asname, arena); |
| 7343 | return 0; |
| 7344 | failed: |
| 7345 | Py_XDECREF(tmp); |
| 7346 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7347 | } |
| 7348 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7349 | int |
| 7350 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 7351 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7352 | PyObject* tmp = NULL; |
| 7353 | expr_ty context_expr; |
| 7354 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7355 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7356 | if (_PyObject_HasAttrId(obj, &PyId_context_expr)) { |
| 7357 | int res; |
| 7358 | tmp = _PyObject_GetAttrId(obj, &PyId_context_expr); |
| 7359 | if (tmp == NULL) goto failed; |
| 7360 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 7361 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7362 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7363 | } else { |
| 7364 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7365 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7366 | } |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7367 | if (exists_not_none(obj, &PyId_optional_vars)) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7368 | int res; |
| 7369 | tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars); |
| 7370 | if (tmp == NULL) goto failed; |
| 7371 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 7372 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7373 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7374 | } else { |
| 7375 | optional_vars = NULL; |
| 7376 | } |
| 7377 | *out = withitem(context_expr, optional_vars, arena); |
| 7378 | return 0; |
| 7379 | failed: |
| 7380 | Py_XDECREF(tmp); |
| 7381 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 7382 | } |
| 7383 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7384 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7385 | static struct PyModuleDef _astmodule = { |
| 7386 | PyModuleDef_HEAD_INIT, "_ast" |
| 7387 | }; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 7388 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 7389 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 7390 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7391 | PyObject *m, *d; |
| 7392 | if (!init_types()) return NULL; |
| 7393 | m = PyModule_Create(&_astmodule); |
| 7394 | if (!m) return NULL; |
| 7395 | d = PyModule_GetDict(m); |
| 7396 | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7397 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7398 | return NULL; |
| 7399 | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; |
| 7400 | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return |
| 7401 | NULL; |
| 7402 | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) < |
| 7403 | 0) return NULL; |
| 7404 | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0) |
| 7405 | return NULL; |
| 7406 | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
| 7407 | NULL; |
| 7408 | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL; |
| 7409 | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) < |
| 7410 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7411 | if (PyDict_SetItemString(d, "AsyncFunctionDef", |
| 7412 | (PyObject*)AsyncFunctionDef_type) < 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7413 | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
| 7414 | return NULL; |
| 7415 | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return |
| 7416 | NULL; |
| 7417 | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return |
| 7418 | NULL; |
| 7419 | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return |
| 7420 | NULL; |
| 7421 | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0) |
| 7422 | return NULL; |
| 7423 | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7424 | if (PyDict_SetItemString(d, "AsyncFor", (PyObject*)AsyncFor_type) < 0) |
| 7425 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7426 | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
| 7427 | NULL; |
| 7428 | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
| 7429 | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7430 | if (PyDict_SetItemString(d, "AsyncWith", (PyObject*)AsyncWith_type) < 0) |
| 7431 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7432 | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
| 7433 | NULL; |
| 7434 | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL; |
| 7435 | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return |
| 7436 | NULL; |
| 7437 | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return |
| 7438 | NULL; |
| 7439 | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0) |
| 7440 | return NULL; |
| 7441 | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return |
| 7442 | NULL; |
| 7443 | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
| 7444 | return NULL; |
| 7445 | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL; |
| 7446 | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL; |
| 7447 | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
| 7448 | NULL; |
| 7449 | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
| 7450 | return NULL; |
| 7451 | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL; |
| 7452 | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return |
| 7453 | NULL; |
| 7454 | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
| 7455 | NULL; |
| 7456 | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return |
| 7457 | NULL; |
| 7458 | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return |
| 7459 | NULL; |
| 7460 | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
| 7461 | NULL; |
| 7462 | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL; |
| 7463 | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL; |
| 7464 | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 7465 | return NULL; |
| 7466 | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return |
| 7467 | NULL; |
| 7468 | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
| 7469 | return NULL; |
| 7470 | if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) < |
| 7471 | 0) return NULL; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7472 | if (PyDict_SetItemString(d, "Await", (PyObject*)Await_type) < 0) return |
| 7473 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7474 | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 7475 | NULL; |
| 7476 | if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0) |
| 7477 | return NULL; |
| 7478 | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return |
| 7479 | NULL; |
| 7480 | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL; |
| 7481 | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return NULL; |
| 7482 | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return NULL; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame^] | 7483 | if (PyDict_SetItemString(d, "FormattedValue", |
| 7484 | (PyObject*)FormattedValue_type) < 0) return NULL; |
| 7485 | if (PyDict_SetItemString(d, "JoinedStr", (PyObject*)JoinedStr_type) < 0) |
| 7486 | return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7487 | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return |
| 7488 | NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 7489 | if (PyDict_SetItemString(d, "NameConstant", (PyObject*)NameConstant_type) < |
| 7490 | 0) return NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7491 | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
| 7492 | return NULL; |
| 7493 | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0) |
| 7494 | return NULL; |
| 7495 | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0) |
| 7496 | return NULL; |
| 7497 | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return |
| 7498 | NULL; |
| 7499 | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL; |
| 7500 | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL; |
| 7501 | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
| 7502 | NULL; |
| 7503 | if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) < |
| 7504 | 0) return NULL; |
| 7505 | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL; |
| 7506 | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
| 7507 | NULL; |
| 7508 | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL; |
| 7509 | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return |
| 7510 | NULL; |
| 7511 | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
| 7512 | return NULL; |
| 7513 | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
| 7514 | NULL; |
| 7515 | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
| 7516 | NULL; |
| 7517 | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
| 7518 | NULL; |
| 7519 | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
| 7520 | return NULL; |
| 7521 | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
| 7522 | NULL; |
| 7523 | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return |
| 7524 | NULL; |
| 7525 | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL; |
| 7526 | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
| 7527 | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
| 7528 | return NULL; |
| 7529 | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL; |
| 7530 | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL; |
| 7531 | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 7532 | if (PyDict_SetItemString(d, "MatMult", (PyObject*)MatMult_type) < 0) return |
| 7533 | NULL; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7534 | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL; |
| 7535 | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL; |
| 7536 | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL; |
| 7537 | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return |
| 7538 | NULL; |
| 7539 | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return |
| 7540 | NULL; |
| 7541 | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
| 7542 | NULL; |
| 7543 | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return |
| 7544 | NULL; |
| 7545 | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return |
| 7546 | NULL; |
| 7547 | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
| 7548 | return NULL; |
| 7549 | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return |
| 7550 | NULL; |
| 7551 | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return |
| 7552 | NULL; |
| 7553 | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL; |
| 7554 | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL; |
| 7555 | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL; |
| 7556 | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
| 7557 | NULL; |
| 7558 | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
| 7559 | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
| 7560 | NULL; |
| 7561 | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
| 7562 | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL; |
| 7563 | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
| 7564 | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL; |
| 7565 | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
| 7566 | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
| 7567 | NULL; |
| 7568 | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
| 7569 | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
| 7570 | NULL; |
| 7571 | if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type) |
| 7572 | < 0) return NULL; |
| 7573 | if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type) |
| 7574 | < 0) return NULL; |
| 7575 | if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type) |
| 7576 | < 0) return NULL; |
| 7577 | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0) |
| 7578 | return NULL; |
| 7579 | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL; |
| 7580 | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return |
| 7581 | NULL; |
| 7582 | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
| 7583 | NULL; |
| 7584 | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
| 7585 | return NULL; |
| 7586 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 7587 | } |
| 7588 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7589 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7590 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7591 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 7592 | if (!init_types()) |
| 7593 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 7594 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 7595 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7596 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7597 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 7598 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7599 | { |
| 7600 | mod_ty res; |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 7601 | PyObject *req_type[3]; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7602 | char *req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7603 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 7604 | |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 7605 | req_type[0] = (PyObject*)Module_type; |
| 7606 | req_type[1] = (PyObject*)Expression_type; |
| 7607 | req_type[2] = (PyObject*)Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 7608 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7609 | assert(0 <= mode && mode <= 2); |
| 7610 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 7611 | if (!init_types()) |
| 7612 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7613 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 7614 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 7615 | if (isinstance == -1) |
| 7616 | return NULL; |
| 7617 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 7618 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 7619 | req_name[mode], Py_TYPE(ast)->tp_name); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7620 | return NULL; |
| 7621 | } |
| 7622 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 7623 | return NULL; |
| 7624 | else |
| 7625 | return res; |
| 7626 | } |
| 7627 | |
| 7628 | int PyAST_Check(PyObject* obj) |
| 7629 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 7630 | if (!init_types()) |
| 7631 | return -1; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 7632 | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7633 | } |
| 7634 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 7635 | |