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" |
Victor Stinner | 4a21e57 | 2020-04-15 02:35:41 +0200 | [diff] [blame] | 7 | #include "structmember.h" // PyMemberDef |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9 | typedef struct { |
| 10 | int initialized; |
| 11 | PyObject *AST_type; |
| 12 | PyObject *Add_singleton; |
| 13 | PyObject *Add_type; |
| 14 | PyObject *And_singleton; |
| 15 | PyObject *And_type; |
| 16 | PyObject *AnnAssign_type; |
| 17 | PyObject *Assert_type; |
| 18 | PyObject *Assign_type; |
| 19 | PyObject *AsyncFor_type; |
| 20 | PyObject *AsyncFunctionDef_type; |
| 21 | PyObject *AsyncWith_type; |
| 22 | PyObject *Attribute_type; |
| 23 | PyObject *AugAssign_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 24 | PyObject *Await_type; |
| 25 | PyObject *BinOp_type; |
| 26 | PyObject *BitAnd_singleton; |
| 27 | PyObject *BitAnd_type; |
| 28 | PyObject *BitOr_singleton; |
| 29 | PyObject *BitOr_type; |
| 30 | PyObject *BitXor_singleton; |
| 31 | PyObject *BitXor_type; |
| 32 | PyObject *BoolOp_type; |
| 33 | PyObject *Break_type; |
| 34 | PyObject *Call_type; |
| 35 | PyObject *ClassDef_type; |
| 36 | PyObject *Compare_type; |
| 37 | PyObject *Constant_type; |
| 38 | PyObject *Continue_type; |
| 39 | PyObject *Del_singleton; |
| 40 | PyObject *Del_type; |
| 41 | PyObject *Delete_type; |
| 42 | PyObject *DictComp_type; |
| 43 | PyObject *Dict_type; |
| 44 | PyObject *Div_singleton; |
| 45 | PyObject *Div_type; |
| 46 | PyObject *Eq_singleton; |
| 47 | PyObject *Eq_type; |
| 48 | PyObject *ExceptHandler_type; |
| 49 | PyObject *Expr_type; |
| 50 | PyObject *Expression_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 51 | PyObject *FloorDiv_singleton; |
| 52 | PyObject *FloorDiv_type; |
| 53 | PyObject *For_type; |
| 54 | PyObject *FormattedValue_type; |
| 55 | PyObject *FunctionDef_type; |
| 56 | PyObject *FunctionType_type; |
| 57 | PyObject *GeneratorExp_type; |
| 58 | PyObject *Global_type; |
| 59 | PyObject *GtE_singleton; |
| 60 | PyObject *GtE_type; |
| 61 | PyObject *Gt_singleton; |
| 62 | PyObject *Gt_type; |
| 63 | PyObject *IfExp_type; |
| 64 | PyObject *If_type; |
| 65 | PyObject *ImportFrom_type; |
| 66 | PyObject *Import_type; |
| 67 | PyObject *In_singleton; |
| 68 | PyObject *In_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 69 | PyObject *Interactive_type; |
| 70 | PyObject *Invert_singleton; |
| 71 | PyObject *Invert_type; |
| 72 | PyObject *IsNot_singleton; |
| 73 | PyObject *IsNot_type; |
| 74 | PyObject *Is_singleton; |
| 75 | PyObject *Is_type; |
| 76 | PyObject *JoinedStr_type; |
| 77 | PyObject *LShift_singleton; |
| 78 | PyObject *LShift_type; |
| 79 | PyObject *Lambda_type; |
| 80 | PyObject *ListComp_type; |
| 81 | PyObject *List_type; |
| 82 | PyObject *Load_singleton; |
| 83 | PyObject *Load_type; |
| 84 | PyObject *LtE_singleton; |
| 85 | PyObject *LtE_type; |
| 86 | PyObject *Lt_singleton; |
| 87 | PyObject *Lt_type; |
| 88 | PyObject *MatMult_singleton; |
| 89 | PyObject *MatMult_type; |
| 90 | PyObject *Mod_singleton; |
| 91 | PyObject *Mod_type; |
| 92 | PyObject *Module_type; |
| 93 | PyObject *Mult_singleton; |
| 94 | PyObject *Mult_type; |
| 95 | PyObject *Name_type; |
| 96 | PyObject *NamedExpr_type; |
| 97 | PyObject *Nonlocal_type; |
| 98 | PyObject *NotEq_singleton; |
| 99 | PyObject *NotEq_type; |
| 100 | PyObject *NotIn_singleton; |
| 101 | PyObject *NotIn_type; |
| 102 | PyObject *Not_singleton; |
| 103 | PyObject *Not_type; |
| 104 | PyObject *Or_singleton; |
| 105 | PyObject *Or_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 106 | PyObject *Pass_type; |
| 107 | PyObject *Pow_singleton; |
| 108 | PyObject *Pow_type; |
| 109 | PyObject *RShift_singleton; |
| 110 | PyObject *RShift_type; |
| 111 | PyObject *Raise_type; |
| 112 | PyObject *Return_type; |
| 113 | PyObject *SetComp_type; |
| 114 | PyObject *Set_type; |
| 115 | PyObject *Slice_type; |
| 116 | PyObject *Starred_type; |
| 117 | PyObject *Store_singleton; |
| 118 | PyObject *Store_type; |
| 119 | PyObject *Sub_singleton; |
| 120 | PyObject *Sub_type; |
| 121 | PyObject *Subscript_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 122 | PyObject *Try_type; |
| 123 | PyObject *Tuple_type; |
| 124 | PyObject *TypeIgnore_type; |
| 125 | PyObject *UAdd_singleton; |
| 126 | PyObject *UAdd_type; |
| 127 | PyObject *USub_singleton; |
| 128 | PyObject *USub_type; |
| 129 | PyObject *UnaryOp_type; |
| 130 | PyObject *While_type; |
| 131 | PyObject *With_type; |
| 132 | PyObject *YieldFrom_type; |
| 133 | PyObject *Yield_type; |
| 134 | PyObject *__dict__; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 135 | PyObject *__doc__; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 136 | PyObject *__module__; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 137 | PyObject *_attributes; |
| 138 | PyObject *_fields; |
| 139 | PyObject *alias_type; |
| 140 | PyObject *annotation; |
| 141 | PyObject *arg; |
| 142 | PyObject *arg_type; |
| 143 | PyObject *args; |
| 144 | PyObject *argtypes; |
| 145 | PyObject *arguments_type; |
| 146 | PyObject *asname; |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 147 | PyObject *ast; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 148 | PyObject *attr; |
| 149 | PyObject *bases; |
| 150 | PyObject *body; |
| 151 | PyObject *boolop_type; |
| 152 | PyObject *cause; |
| 153 | PyObject *cmpop_type; |
| 154 | PyObject *col_offset; |
| 155 | PyObject *comparators; |
| 156 | PyObject *comprehension_type; |
| 157 | PyObject *context_expr; |
| 158 | PyObject *conversion; |
| 159 | PyObject *ctx; |
| 160 | PyObject *decorator_list; |
| 161 | PyObject *defaults; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 162 | PyObject *elt; |
| 163 | PyObject *elts; |
| 164 | PyObject *end_col_offset; |
| 165 | PyObject *end_lineno; |
| 166 | PyObject *exc; |
| 167 | PyObject *excepthandler_type; |
| 168 | PyObject *expr_context_type; |
| 169 | PyObject *expr_type; |
| 170 | PyObject *finalbody; |
| 171 | PyObject *format_spec; |
| 172 | PyObject *func; |
| 173 | PyObject *generators; |
| 174 | PyObject *handlers; |
| 175 | PyObject *id; |
| 176 | PyObject *ifs; |
| 177 | PyObject *is_async; |
| 178 | PyObject *items; |
| 179 | PyObject *iter; |
| 180 | PyObject *key; |
| 181 | PyObject *keys; |
| 182 | PyObject *keyword_type; |
| 183 | PyObject *keywords; |
| 184 | PyObject *kind; |
| 185 | PyObject *kw_defaults; |
| 186 | PyObject *kwarg; |
| 187 | PyObject *kwonlyargs; |
| 188 | PyObject *left; |
| 189 | PyObject *level; |
| 190 | PyObject *lineno; |
| 191 | PyObject *lower; |
| 192 | PyObject *mod_type; |
| 193 | PyObject *module; |
| 194 | PyObject *msg; |
| 195 | PyObject *name; |
| 196 | PyObject *names; |
| 197 | PyObject *op; |
| 198 | PyObject *operand; |
| 199 | PyObject *operator_type; |
| 200 | PyObject *ops; |
| 201 | PyObject *optional_vars; |
| 202 | PyObject *orelse; |
| 203 | PyObject *posonlyargs; |
| 204 | PyObject *returns; |
| 205 | PyObject *right; |
| 206 | PyObject *simple; |
| 207 | PyObject *slice; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 208 | PyObject *step; |
| 209 | PyObject *stmt_type; |
| 210 | PyObject *tag; |
| 211 | PyObject *target; |
| 212 | PyObject *targets; |
| 213 | PyObject *test; |
| 214 | PyObject *type; |
| 215 | PyObject *type_comment; |
| 216 | PyObject *type_ignore_type; |
| 217 | PyObject *type_ignores; |
| 218 | PyObject *unaryop_type; |
| 219 | PyObject *upper; |
| 220 | PyObject *value; |
| 221 | PyObject *values; |
| 222 | PyObject *vararg; |
| 223 | PyObject *withitem_type; |
| 224 | } astmodulestate; |
| 225 | |
| 226 | |
| 227 | #define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o)) |
| 228 | |
| 229 | static int astmodule_clear(PyObject *module) |
| 230 | { |
| 231 | Py_CLEAR(astmodulestate(module)->AST_type); |
| 232 | Py_CLEAR(astmodulestate(module)->Add_singleton); |
| 233 | Py_CLEAR(astmodulestate(module)->Add_type); |
| 234 | Py_CLEAR(astmodulestate(module)->And_singleton); |
| 235 | Py_CLEAR(astmodulestate(module)->And_type); |
| 236 | Py_CLEAR(astmodulestate(module)->AnnAssign_type); |
| 237 | Py_CLEAR(astmodulestate(module)->Assert_type); |
| 238 | Py_CLEAR(astmodulestate(module)->Assign_type); |
| 239 | Py_CLEAR(astmodulestate(module)->AsyncFor_type); |
| 240 | Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type); |
| 241 | Py_CLEAR(astmodulestate(module)->AsyncWith_type); |
| 242 | Py_CLEAR(astmodulestate(module)->Attribute_type); |
| 243 | Py_CLEAR(astmodulestate(module)->AugAssign_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 244 | Py_CLEAR(astmodulestate(module)->Await_type); |
| 245 | Py_CLEAR(astmodulestate(module)->BinOp_type); |
| 246 | Py_CLEAR(astmodulestate(module)->BitAnd_singleton); |
| 247 | Py_CLEAR(astmodulestate(module)->BitAnd_type); |
| 248 | Py_CLEAR(astmodulestate(module)->BitOr_singleton); |
| 249 | Py_CLEAR(astmodulestate(module)->BitOr_type); |
| 250 | Py_CLEAR(astmodulestate(module)->BitXor_singleton); |
| 251 | Py_CLEAR(astmodulestate(module)->BitXor_type); |
| 252 | Py_CLEAR(astmodulestate(module)->BoolOp_type); |
| 253 | Py_CLEAR(astmodulestate(module)->Break_type); |
| 254 | Py_CLEAR(astmodulestate(module)->Call_type); |
| 255 | Py_CLEAR(astmodulestate(module)->ClassDef_type); |
| 256 | Py_CLEAR(astmodulestate(module)->Compare_type); |
| 257 | Py_CLEAR(astmodulestate(module)->Constant_type); |
| 258 | Py_CLEAR(astmodulestate(module)->Continue_type); |
| 259 | Py_CLEAR(astmodulestate(module)->Del_singleton); |
| 260 | Py_CLEAR(astmodulestate(module)->Del_type); |
| 261 | Py_CLEAR(astmodulestate(module)->Delete_type); |
| 262 | Py_CLEAR(astmodulestate(module)->DictComp_type); |
| 263 | Py_CLEAR(astmodulestate(module)->Dict_type); |
| 264 | Py_CLEAR(astmodulestate(module)->Div_singleton); |
| 265 | Py_CLEAR(astmodulestate(module)->Div_type); |
| 266 | Py_CLEAR(astmodulestate(module)->Eq_singleton); |
| 267 | Py_CLEAR(astmodulestate(module)->Eq_type); |
| 268 | Py_CLEAR(astmodulestate(module)->ExceptHandler_type); |
| 269 | Py_CLEAR(astmodulestate(module)->Expr_type); |
| 270 | Py_CLEAR(astmodulestate(module)->Expression_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 271 | Py_CLEAR(astmodulestate(module)->FloorDiv_singleton); |
| 272 | Py_CLEAR(astmodulestate(module)->FloorDiv_type); |
| 273 | Py_CLEAR(astmodulestate(module)->For_type); |
| 274 | Py_CLEAR(astmodulestate(module)->FormattedValue_type); |
| 275 | Py_CLEAR(astmodulestate(module)->FunctionDef_type); |
| 276 | Py_CLEAR(astmodulestate(module)->FunctionType_type); |
| 277 | Py_CLEAR(astmodulestate(module)->GeneratorExp_type); |
| 278 | Py_CLEAR(astmodulestate(module)->Global_type); |
| 279 | Py_CLEAR(astmodulestate(module)->GtE_singleton); |
| 280 | Py_CLEAR(astmodulestate(module)->GtE_type); |
| 281 | Py_CLEAR(astmodulestate(module)->Gt_singleton); |
| 282 | Py_CLEAR(astmodulestate(module)->Gt_type); |
| 283 | Py_CLEAR(astmodulestate(module)->IfExp_type); |
| 284 | Py_CLEAR(astmodulestate(module)->If_type); |
| 285 | Py_CLEAR(astmodulestate(module)->ImportFrom_type); |
| 286 | Py_CLEAR(astmodulestate(module)->Import_type); |
| 287 | Py_CLEAR(astmodulestate(module)->In_singleton); |
| 288 | Py_CLEAR(astmodulestate(module)->In_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 289 | Py_CLEAR(astmodulestate(module)->Interactive_type); |
| 290 | Py_CLEAR(astmodulestate(module)->Invert_singleton); |
| 291 | Py_CLEAR(astmodulestate(module)->Invert_type); |
| 292 | Py_CLEAR(astmodulestate(module)->IsNot_singleton); |
| 293 | Py_CLEAR(astmodulestate(module)->IsNot_type); |
| 294 | Py_CLEAR(astmodulestate(module)->Is_singleton); |
| 295 | Py_CLEAR(astmodulestate(module)->Is_type); |
| 296 | Py_CLEAR(astmodulestate(module)->JoinedStr_type); |
| 297 | Py_CLEAR(astmodulestate(module)->LShift_singleton); |
| 298 | Py_CLEAR(astmodulestate(module)->LShift_type); |
| 299 | Py_CLEAR(astmodulestate(module)->Lambda_type); |
| 300 | Py_CLEAR(astmodulestate(module)->ListComp_type); |
| 301 | Py_CLEAR(astmodulestate(module)->List_type); |
| 302 | Py_CLEAR(astmodulestate(module)->Load_singleton); |
| 303 | Py_CLEAR(astmodulestate(module)->Load_type); |
| 304 | Py_CLEAR(astmodulestate(module)->LtE_singleton); |
| 305 | Py_CLEAR(astmodulestate(module)->LtE_type); |
| 306 | Py_CLEAR(astmodulestate(module)->Lt_singleton); |
| 307 | Py_CLEAR(astmodulestate(module)->Lt_type); |
| 308 | Py_CLEAR(astmodulestate(module)->MatMult_singleton); |
| 309 | Py_CLEAR(astmodulestate(module)->MatMult_type); |
| 310 | Py_CLEAR(astmodulestate(module)->Mod_singleton); |
| 311 | Py_CLEAR(astmodulestate(module)->Mod_type); |
| 312 | Py_CLEAR(astmodulestate(module)->Module_type); |
| 313 | Py_CLEAR(astmodulestate(module)->Mult_singleton); |
| 314 | Py_CLEAR(astmodulestate(module)->Mult_type); |
| 315 | Py_CLEAR(astmodulestate(module)->Name_type); |
| 316 | Py_CLEAR(astmodulestate(module)->NamedExpr_type); |
| 317 | Py_CLEAR(astmodulestate(module)->Nonlocal_type); |
| 318 | Py_CLEAR(astmodulestate(module)->NotEq_singleton); |
| 319 | Py_CLEAR(astmodulestate(module)->NotEq_type); |
| 320 | Py_CLEAR(astmodulestate(module)->NotIn_singleton); |
| 321 | Py_CLEAR(astmodulestate(module)->NotIn_type); |
| 322 | Py_CLEAR(astmodulestate(module)->Not_singleton); |
| 323 | Py_CLEAR(astmodulestate(module)->Not_type); |
| 324 | Py_CLEAR(astmodulestate(module)->Or_singleton); |
| 325 | Py_CLEAR(astmodulestate(module)->Or_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 326 | Py_CLEAR(astmodulestate(module)->Pass_type); |
| 327 | Py_CLEAR(astmodulestate(module)->Pow_singleton); |
| 328 | Py_CLEAR(astmodulestate(module)->Pow_type); |
| 329 | Py_CLEAR(astmodulestate(module)->RShift_singleton); |
| 330 | Py_CLEAR(astmodulestate(module)->RShift_type); |
| 331 | Py_CLEAR(astmodulestate(module)->Raise_type); |
| 332 | Py_CLEAR(astmodulestate(module)->Return_type); |
| 333 | Py_CLEAR(astmodulestate(module)->SetComp_type); |
| 334 | Py_CLEAR(astmodulestate(module)->Set_type); |
| 335 | Py_CLEAR(astmodulestate(module)->Slice_type); |
| 336 | Py_CLEAR(astmodulestate(module)->Starred_type); |
| 337 | Py_CLEAR(astmodulestate(module)->Store_singleton); |
| 338 | Py_CLEAR(astmodulestate(module)->Store_type); |
| 339 | Py_CLEAR(astmodulestate(module)->Sub_singleton); |
| 340 | Py_CLEAR(astmodulestate(module)->Sub_type); |
| 341 | Py_CLEAR(astmodulestate(module)->Subscript_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 342 | Py_CLEAR(astmodulestate(module)->Try_type); |
| 343 | Py_CLEAR(astmodulestate(module)->Tuple_type); |
| 344 | Py_CLEAR(astmodulestate(module)->TypeIgnore_type); |
| 345 | Py_CLEAR(astmodulestate(module)->UAdd_singleton); |
| 346 | Py_CLEAR(astmodulestate(module)->UAdd_type); |
| 347 | Py_CLEAR(astmodulestate(module)->USub_singleton); |
| 348 | Py_CLEAR(astmodulestate(module)->USub_type); |
| 349 | Py_CLEAR(astmodulestate(module)->UnaryOp_type); |
| 350 | Py_CLEAR(astmodulestate(module)->While_type); |
| 351 | Py_CLEAR(astmodulestate(module)->With_type); |
| 352 | Py_CLEAR(astmodulestate(module)->YieldFrom_type); |
| 353 | Py_CLEAR(astmodulestate(module)->Yield_type); |
| 354 | Py_CLEAR(astmodulestate(module)->__dict__); |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 355 | Py_CLEAR(astmodulestate(module)->__doc__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 356 | Py_CLEAR(astmodulestate(module)->__module__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 357 | Py_CLEAR(astmodulestate(module)->_attributes); |
| 358 | Py_CLEAR(astmodulestate(module)->_fields); |
| 359 | Py_CLEAR(astmodulestate(module)->alias_type); |
| 360 | Py_CLEAR(astmodulestate(module)->annotation); |
| 361 | Py_CLEAR(astmodulestate(module)->arg); |
| 362 | Py_CLEAR(astmodulestate(module)->arg_type); |
| 363 | Py_CLEAR(astmodulestate(module)->args); |
| 364 | Py_CLEAR(astmodulestate(module)->argtypes); |
| 365 | Py_CLEAR(astmodulestate(module)->arguments_type); |
| 366 | Py_CLEAR(astmodulestate(module)->asname); |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 367 | Py_CLEAR(astmodulestate(module)->ast); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 368 | Py_CLEAR(astmodulestate(module)->attr); |
| 369 | Py_CLEAR(astmodulestate(module)->bases); |
| 370 | Py_CLEAR(astmodulestate(module)->body); |
| 371 | Py_CLEAR(astmodulestate(module)->boolop_type); |
| 372 | Py_CLEAR(astmodulestate(module)->cause); |
| 373 | Py_CLEAR(astmodulestate(module)->cmpop_type); |
| 374 | Py_CLEAR(astmodulestate(module)->col_offset); |
| 375 | Py_CLEAR(astmodulestate(module)->comparators); |
| 376 | Py_CLEAR(astmodulestate(module)->comprehension_type); |
| 377 | Py_CLEAR(astmodulestate(module)->context_expr); |
| 378 | Py_CLEAR(astmodulestate(module)->conversion); |
| 379 | Py_CLEAR(astmodulestate(module)->ctx); |
| 380 | Py_CLEAR(astmodulestate(module)->decorator_list); |
| 381 | Py_CLEAR(astmodulestate(module)->defaults); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 382 | Py_CLEAR(astmodulestate(module)->elt); |
| 383 | Py_CLEAR(astmodulestate(module)->elts); |
| 384 | Py_CLEAR(astmodulestate(module)->end_col_offset); |
| 385 | Py_CLEAR(astmodulestate(module)->end_lineno); |
| 386 | Py_CLEAR(astmodulestate(module)->exc); |
| 387 | Py_CLEAR(astmodulestate(module)->excepthandler_type); |
| 388 | Py_CLEAR(astmodulestate(module)->expr_context_type); |
| 389 | Py_CLEAR(astmodulestate(module)->expr_type); |
| 390 | Py_CLEAR(astmodulestate(module)->finalbody); |
| 391 | Py_CLEAR(astmodulestate(module)->format_spec); |
| 392 | Py_CLEAR(astmodulestate(module)->func); |
| 393 | Py_CLEAR(astmodulestate(module)->generators); |
| 394 | Py_CLEAR(astmodulestate(module)->handlers); |
| 395 | Py_CLEAR(astmodulestate(module)->id); |
| 396 | Py_CLEAR(astmodulestate(module)->ifs); |
| 397 | Py_CLEAR(astmodulestate(module)->is_async); |
| 398 | Py_CLEAR(astmodulestate(module)->items); |
| 399 | Py_CLEAR(astmodulestate(module)->iter); |
| 400 | Py_CLEAR(astmodulestate(module)->key); |
| 401 | Py_CLEAR(astmodulestate(module)->keys); |
| 402 | Py_CLEAR(astmodulestate(module)->keyword_type); |
| 403 | Py_CLEAR(astmodulestate(module)->keywords); |
| 404 | Py_CLEAR(astmodulestate(module)->kind); |
| 405 | Py_CLEAR(astmodulestate(module)->kw_defaults); |
| 406 | Py_CLEAR(astmodulestate(module)->kwarg); |
| 407 | Py_CLEAR(astmodulestate(module)->kwonlyargs); |
| 408 | Py_CLEAR(astmodulestate(module)->left); |
| 409 | Py_CLEAR(astmodulestate(module)->level); |
| 410 | Py_CLEAR(astmodulestate(module)->lineno); |
| 411 | Py_CLEAR(astmodulestate(module)->lower); |
| 412 | Py_CLEAR(astmodulestate(module)->mod_type); |
| 413 | Py_CLEAR(astmodulestate(module)->module); |
| 414 | Py_CLEAR(astmodulestate(module)->msg); |
| 415 | Py_CLEAR(astmodulestate(module)->name); |
| 416 | Py_CLEAR(astmodulestate(module)->names); |
| 417 | Py_CLEAR(astmodulestate(module)->op); |
| 418 | Py_CLEAR(astmodulestate(module)->operand); |
| 419 | Py_CLEAR(astmodulestate(module)->operator_type); |
| 420 | Py_CLEAR(astmodulestate(module)->ops); |
| 421 | Py_CLEAR(astmodulestate(module)->optional_vars); |
| 422 | Py_CLEAR(astmodulestate(module)->orelse); |
| 423 | Py_CLEAR(astmodulestate(module)->posonlyargs); |
| 424 | Py_CLEAR(astmodulestate(module)->returns); |
| 425 | Py_CLEAR(astmodulestate(module)->right); |
| 426 | Py_CLEAR(astmodulestate(module)->simple); |
| 427 | Py_CLEAR(astmodulestate(module)->slice); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 428 | Py_CLEAR(astmodulestate(module)->step); |
| 429 | Py_CLEAR(astmodulestate(module)->stmt_type); |
| 430 | Py_CLEAR(astmodulestate(module)->tag); |
| 431 | Py_CLEAR(astmodulestate(module)->target); |
| 432 | Py_CLEAR(astmodulestate(module)->targets); |
| 433 | Py_CLEAR(astmodulestate(module)->test); |
| 434 | Py_CLEAR(astmodulestate(module)->type); |
| 435 | Py_CLEAR(astmodulestate(module)->type_comment); |
| 436 | Py_CLEAR(astmodulestate(module)->type_ignore_type); |
| 437 | Py_CLEAR(astmodulestate(module)->type_ignores); |
| 438 | Py_CLEAR(astmodulestate(module)->unaryop_type); |
| 439 | Py_CLEAR(astmodulestate(module)->upper); |
| 440 | Py_CLEAR(astmodulestate(module)->value); |
| 441 | Py_CLEAR(astmodulestate(module)->values); |
| 442 | Py_CLEAR(astmodulestate(module)->vararg); |
| 443 | Py_CLEAR(astmodulestate(module)->withitem_type); |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static int astmodule_traverse(PyObject *module, visitproc visit, void* arg) |
| 449 | { |
| 450 | Py_VISIT(astmodulestate(module)->AST_type); |
| 451 | Py_VISIT(astmodulestate(module)->Add_singleton); |
| 452 | Py_VISIT(astmodulestate(module)->Add_type); |
| 453 | Py_VISIT(astmodulestate(module)->And_singleton); |
| 454 | Py_VISIT(astmodulestate(module)->And_type); |
| 455 | Py_VISIT(astmodulestate(module)->AnnAssign_type); |
| 456 | Py_VISIT(astmodulestate(module)->Assert_type); |
| 457 | Py_VISIT(astmodulestate(module)->Assign_type); |
| 458 | Py_VISIT(astmodulestate(module)->AsyncFor_type); |
| 459 | Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type); |
| 460 | Py_VISIT(astmodulestate(module)->AsyncWith_type); |
| 461 | Py_VISIT(astmodulestate(module)->Attribute_type); |
| 462 | Py_VISIT(astmodulestate(module)->AugAssign_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 463 | Py_VISIT(astmodulestate(module)->Await_type); |
| 464 | Py_VISIT(astmodulestate(module)->BinOp_type); |
| 465 | Py_VISIT(astmodulestate(module)->BitAnd_singleton); |
| 466 | Py_VISIT(astmodulestate(module)->BitAnd_type); |
| 467 | Py_VISIT(astmodulestate(module)->BitOr_singleton); |
| 468 | Py_VISIT(astmodulestate(module)->BitOr_type); |
| 469 | Py_VISIT(astmodulestate(module)->BitXor_singleton); |
| 470 | Py_VISIT(astmodulestate(module)->BitXor_type); |
| 471 | Py_VISIT(astmodulestate(module)->BoolOp_type); |
| 472 | Py_VISIT(astmodulestate(module)->Break_type); |
| 473 | Py_VISIT(astmodulestate(module)->Call_type); |
| 474 | Py_VISIT(astmodulestate(module)->ClassDef_type); |
| 475 | Py_VISIT(astmodulestate(module)->Compare_type); |
| 476 | Py_VISIT(astmodulestate(module)->Constant_type); |
| 477 | Py_VISIT(astmodulestate(module)->Continue_type); |
| 478 | Py_VISIT(astmodulestate(module)->Del_singleton); |
| 479 | Py_VISIT(astmodulestate(module)->Del_type); |
| 480 | Py_VISIT(astmodulestate(module)->Delete_type); |
| 481 | Py_VISIT(astmodulestate(module)->DictComp_type); |
| 482 | Py_VISIT(astmodulestate(module)->Dict_type); |
| 483 | Py_VISIT(astmodulestate(module)->Div_singleton); |
| 484 | Py_VISIT(astmodulestate(module)->Div_type); |
| 485 | Py_VISIT(astmodulestate(module)->Eq_singleton); |
| 486 | Py_VISIT(astmodulestate(module)->Eq_type); |
| 487 | Py_VISIT(astmodulestate(module)->ExceptHandler_type); |
| 488 | Py_VISIT(astmodulestate(module)->Expr_type); |
| 489 | Py_VISIT(astmodulestate(module)->Expression_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 490 | Py_VISIT(astmodulestate(module)->FloorDiv_singleton); |
| 491 | Py_VISIT(astmodulestate(module)->FloorDiv_type); |
| 492 | Py_VISIT(astmodulestate(module)->For_type); |
| 493 | Py_VISIT(astmodulestate(module)->FormattedValue_type); |
| 494 | Py_VISIT(astmodulestate(module)->FunctionDef_type); |
| 495 | Py_VISIT(astmodulestate(module)->FunctionType_type); |
| 496 | Py_VISIT(astmodulestate(module)->GeneratorExp_type); |
| 497 | Py_VISIT(astmodulestate(module)->Global_type); |
| 498 | Py_VISIT(astmodulestate(module)->GtE_singleton); |
| 499 | Py_VISIT(astmodulestate(module)->GtE_type); |
| 500 | Py_VISIT(astmodulestate(module)->Gt_singleton); |
| 501 | Py_VISIT(astmodulestate(module)->Gt_type); |
| 502 | Py_VISIT(astmodulestate(module)->IfExp_type); |
| 503 | Py_VISIT(astmodulestate(module)->If_type); |
| 504 | Py_VISIT(astmodulestate(module)->ImportFrom_type); |
| 505 | Py_VISIT(astmodulestate(module)->Import_type); |
| 506 | Py_VISIT(astmodulestate(module)->In_singleton); |
| 507 | Py_VISIT(astmodulestate(module)->In_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 508 | Py_VISIT(astmodulestate(module)->Interactive_type); |
| 509 | Py_VISIT(astmodulestate(module)->Invert_singleton); |
| 510 | Py_VISIT(astmodulestate(module)->Invert_type); |
| 511 | Py_VISIT(astmodulestate(module)->IsNot_singleton); |
| 512 | Py_VISIT(astmodulestate(module)->IsNot_type); |
| 513 | Py_VISIT(astmodulestate(module)->Is_singleton); |
| 514 | Py_VISIT(astmodulestate(module)->Is_type); |
| 515 | Py_VISIT(astmodulestate(module)->JoinedStr_type); |
| 516 | Py_VISIT(astmodulestate(module)->LShift_singleton); |
| 517 | Py_VISIT(astmodulestate(module)->LShift_type); |
| 518 | Py_VISIT(astmodulestate(module)->Lambda_type); |
| 519 | Py_VISIT(astmodulestate(module)->ListComp_type); |
| 520 | Py_VISIT(astmodulestate(module)->List_type); |
| 521 | Py_VISIT(astmodulestate(module)->Load_singleton); |
| 522 | Py_VISIT(astmodulestate(module)->Load_type); |
| 523 | Py_VISIT(astmodulestate(module)->LtE_singleton); |
| 524 | Py_VISIT(astmodulestate(module)->LtE_type); |
| 525 | Py_VISIT(astmodulestate(module)->Lt_singleton); |
| 526 | Py_VISIT(astmodulestate(module)->Lt_type); |
| 527 | Py_VISIT(astmodulestate(module)->MatMult_singleton); |
| 528 | Py_VISIT(astmodulestate(module)->MatMult_type); |
| 529 | Py_VISIT(astmodulestate(module)->Mod_singleton); |
| 530 | Py_VISIT(astmodulestate(module)->Mod_type); |
| 531 | Py_VISIT(astmodulestate(module)->Module_type); |
| 532 | Py_VISIT(astmodulestate(module)->Mult_singleton); |
| 533 | Py_VISIT(astmodulestate(module)->Mult_type); |
| 534 | Py_VISIT(astmodulestate(module)->Name_type); |
| 535 | Py_VISIT(astmodulestate(module)->NamedExpr_type); |
| 536 | Py_VISIT(astmodulestate(module)->Nonlocal_type); |
| 537 | Py_VISIT(astmodulestate(module)->NotEq_singleton); |
| 538 | Py_VISIT(astmodulestate(module)->NotEq_type); |
| 539 | Py_VISIT(astmodulestate(module)->NotIn_singleton); |
| 540 | Py_VISIT(astmodulestate(module)->NotIn_type); |
| 541 | Py_VISIT(astmodulestate(module)->Not_singleton); |
| 542 | Py_VISIT(astmodulestate(module)->Not_type); |
| 543 | Py_VISIT(astmodulestate(module)->Or_singleton); |
| 544 | Py_VISIT(astmodulestate(module)->Or_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 545 | Py_VISIT(astmodulestate(module)->Pass_type); |
| 546 | Py_VISIT(astmodulestate(module)->Pow_singleton); |
| 547 | Py_VISIT(astmodulestate(module)->Pow_type); |
| 548 | Py_VISIT(astmodulestate(module)->RShift_singleton); |
| 549 | Py_VISIT(astmodulestate(module)->RShift_type); |
| 550 | Py_VISIT(astmodulestate(module)->Raise_type); |
| 551 | Py_VISIT(astmodulestate(module)->Return_type); |
| 552 | Py_VISIT(astmodulestate(module)->SetComp_type); |
| 553 | Py_VISIT(astmodulestate(module)->Set_type); |
| 554 | Py_VISIT(astmodulestate(module)->Slice_type); |
| 555 | Py_VISIT(astmodulestate(module)->Starred_type); |
| 556 | Py_VISIT(astmodulestate(module)->Store_singleton); |
| 557 | Py_VISIT(astmodulestate(module)->Store_type); |
| 558 | Py_VISIT(astmodulestate(module)->Sub_singleton); |
| 559 | Py_VISIT(astmodulestate(module)->Sub_type); |
| 560 | Py_VISIT(astmodulestate(module)->Subscript_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 561 | Py_VISIT(astmodulestate(module)->Try_type); |
| 562 | Py_VISIT(astmodulestate(module)->Tuple_type); |
| 563 | Py_VISIT(astmodulestate(module)->TypeIgnore_type); |
| 564 | Py_VISIT(astmodulestate(module)->UAdd_singleton); |
| 565 | Py_VISIT(astmodulestate(module)->UAdd_type); |
| 566 | Py_VISIT(astmodulestate(module)->USub_singleton); |
| 567 | Py_VISIT(astmodulestate(module)->USub_type); |
| 568 | Py_VISIT(astmodulestate(module)->UnaryOp_type); |
| 569 | Py_VISIT(astmodulestate(module)->While_type); |
| 570 | Py_VISIT(astmodulestate(module)->With_type); |
| 571 | Py_VISIT(astmodulestate(module)->YieldFrom_type); |
| 572 | Py_VISIT(astmodulestate(module)->Yield_type); |
| 573 | Py_VISIT(astmodulestate(module)->__dict__); |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 574 | Py_VISIT(astmodulestate(module)->__doc__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 575 | Py_VISIT(astmodulestate(module)->__module__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 576 | Py_VISIT(astmodulestate(module)->_attributes); |
| 577 | Py_VISIT(astmodulestate(module)->_fields); |
| 578 | Py_VISIT(astmodulestate(module)->alias_type); |
| 579 | Py_VISIT(astmodulestate(module)->annotation); |
| 580 | Py_VISIT(astmodulestate(module)->arg); |
| 581 | Py_VISIT(astmodulestate(module)->arg_type); |
| 582 | Py_VISIT(astmodulestate(module)->args); |
| 583 | Py_VISIT(astmodulestate(module)->argtypes); |
| 584 | Py_VISIT(astmodulestate(module)->arguments_type); |
| 585 | Py_VISIT(astmodulestate(module)->asname); |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 586 | Py_VISIT(astmodulestate(module)->ast); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 587 | Py_VISIT(astmodulestate(module)->attr); |
| 588 | Py_VISIT(astmodulestate(module)->bases); |
| 589 | Py_VISIT(astmodulestate(module)->body); |
| 590 | Py_VISIT(astmodulestate(module)->boolop_type); |
| 591 | Py_VISIT(astmodulestate(module)->cause); |
| 592 | Py_VISIT(astmodulestate(module)->cmpop_type); |
| 593 | Py_VISIT(astmodulestate(module)->col_offset); |
| 594 | Py_VISIT(astmodulestate(module)->comparators); |
| 595 | Py_VISIT(astmodulestate(module)->comprehension_type); |
| 596 | Py_VISIT(astmodulestate(module)->context_expr); |
| 597 | Py_VISIT(astmodulestate(module)->conversion); |
| 598 | Py_VISIT(astmodulestate(module)->ctx); |
| 599 | Py_VISIT(astmodulestate(module)->decorator_list); |
| 600 | Py_VISIT(astmodulestate(module)->defaults); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 601 | Py_VISIT(astmodulestate(module)->elt); |
| 602 | Py_VISIT(astmodulestate(module)->elts); |
| 603 | Py_VISIT(astmodulestate(module)->end_col_offset); |
| 604 | Py_VISIT(astmodulestate(module)->end_lineno); |
| 605 | Py_VISIT(astmodulestate(module)->exc); |
| 606 | Py_VISIT(astmodulestate(module)->excepthandler_type); |
| 607 | Py_VISIT(astmodulestate(module)->expr_context_type); |
| 608 | Py_VISIT(astmodulestate(module)->expr_type); |
| 609 | Py_VISIT(astmodulestate(module)->finalbody); |
| 610 | Py_VISIT(astmodulestate(module)->format_spec); |
| 611 | Py_VISIT(astmodulestate(module)->func); |
| 612 | Py_VISIT(astmodulestate(module)->generators); |
| 613 | Py_VISIT(astmodulestate(module)->handlers); |
| 614 | Py_VISIT(astmodulestate(module)->id); |
| 615 | Py_VISIT(astmodulestate(module)->ifs); |
| 616 | Py_VISIT(astmodulestate(module)->is_async); |
| 617 | Py_VISIT(astmodulestate(module)->items); |
| 618 | Py_VISIT(astmodulestate(module)->iter); |
| 619 | Py_VISIT(astmodulestate(module)->key); |
| 620 | Py_VISIT(astmodulestate(module)->keys); |
| 621 | Py_VISIT(astmodulestate(module)->keyword_type); |
| 622 | Py_VISIT(astmodulestate(module)->keywords); |
| 623 | Py_VISIT(astmodulestate(module)->kind); |
| 624 | Py_VISIT(astmodulestate(module)->kw_defaults); |
| 625 | Py_VISIT(astmodulestate(module)->kwarg); |
| 626 | Py_VISIT(astmodulestate(module)->kwonlyargs); |
| 627 | Py_VISIT(astmodulestate(module)->left); |
| 628 | Py_VISIT(astmodulestate(module)->level); |
| 629 | Py_VISIT(astmodulestate(module)->lineno); |
| 630 | Py_VISIT(astmodulestate(module)->lower); |
| 631 | Py_VISIT(astmodulestate(module)->mod_type); |
| 632 | Py_VISIT(astmodulestate(module)->module); |
| 633 | Py_VISIT(astmodulestate(module)->msg); |
| 634 | Py_VISIT(astmodulestate(module)->name); |
| 635 | Py_VISIT(astmodulestate(module)->names); |
| 636 | Py_VISIT(astmodulestate(module)->op); |
| 637 | Py_VISIT(astmodulestate(module)->operand); |
| 638 | Py_VISIT(astmodulestate(module)->operator_type); |
| 639 | Py_VISIT(astmodulestate(module)->ops); |
| 640 | Py_VISIT(astmodulestate(module)->optional_vars); |
| 641 | Py_VISIT(astmodulestate(module)->orelse); |
| 642 | Py_VISIT(astmodulestate(module)->posonlyargs); |
| 643 | Py_VISIT(astmodulestate(module)->returns); |
| 644 | Py_VISIT(astmodulestate(module)->right); |
| 645 | Py_VISIT(astmodulestate(module)->simple); |
| 646 | Py_VISIT(astmodulestate(module)->slice); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 647 | Py_VISIT(astmodulestate(module)->step); |
| 648 | Py_VISIT(astmodulestate(module)->stmt_type); |
| 649 | Py_VISIT(astmodulestate(module)->tag); |
| 650 | Py_VISIT(astmodulestate(module)->target); |
| 651 | Py_VISIT(astmodulestate(module)->targets); |
| 652 | Py_VISIT(astmodulestate(module)->test); |
| 653 | Py_VISIT(astmodulestate(module)->type); |
| 654 | Py_VISIT(astmodulestate(module)->type_comment); |
| 655 | Py_VISIT(astmodulestate(module)->type_ignore_type); |
| 656 | Py_VISIT(astmodulestate(module)->type_ignores); |
| 657 | Py_VISIT(astmodulestate(module)->unaryop_type); |
| 658 | Py_VISIT(astmodulestate(module)->upper); |
| 659 | Py_VISIT(astmodulestate(module)->value); |
| 660 | Py_VISIT(astmodulestate(module)->values); |
| 661 | Py_VISIT(astmodulestate(module)->vararg); |
| 662 | Py_VISIT(astmodulestate(module)->withitem_type); |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static void astmodule_free(void* module) { |
| 668 | astmodule_clear((PyObject*)module); |
| 669 | } |
| 670 | |
| 671 | static struct PyModuleDef _astmodule = { |
| 672 | PyModuleDef_HEAD_INIT, |
| 673 | "_ast", |
| 674 | NULL, |
| 675 | sizeof(astmodulestate), |
| 676 | NULL, |
| 677 | NULL, |
| 678 | astmodule_traverse, |
| 679 | astmodule_clear, |
| 680 | astmodule_free, |
| 681 | }; |
| 682 | |
| 683 | #define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule))) |
| 684 | |
| 685 | static int init_identifiers(void) |
| 686 | { |
| 687 | astmodulestate *state = astmodulestate_global; |
| 688 | if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 689 | if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 690 | if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 691 | if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0; |
| 692 | if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0; |
| 693 | if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0; |
| 694 | if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0; |
| 695 | if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0; |
| 696 | if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0; |
| 697 | if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0; |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 698 | if ((state->ast = PyUnicode_InternFromString("ast")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 699 | if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0; |
| 700 | if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0; |
| 701 | if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0; |
| 702 | if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0; |
| 703 | if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0; |
| 704 | if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0; |
| 705 | if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0; |
| 706 | if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0; |
| 707 | if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0; |
| 708 | if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0; |
| 709 | if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 710 | if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0; |
| 711 | if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0; |
| 712 | if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0; |
| 713 | if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0; |
| 714 | if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0; |
| 715 | if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0; |
| 716 | if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0; |
| 717 | if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0; |
| 718 | if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0; |
| 719 | if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0; |
| 720 | if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0; |
| 721 | if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0; |
| 722 | if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0; |
| 723 | if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0; |
| 724 | if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0; |
| 725 | if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0; |
| 726 | if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0; |
| 727 | if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0; |
| 728 | if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0; |
| 729 | if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0; |
| 730 | if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0; |
| 731 | if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0; |
| 732 | if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0; |
| 733 | if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0; |
| 734 | if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0; |
| 735 | if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0; |
| 736 | if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0; |
| 737 | if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0; |
| 738 | if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0; |
| 739 | if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0; |
| 740 | if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0; |
| 741 | if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0; |
| 742 | if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0; |
| 743 | if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0; |
| 744 | if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0; |
| 745 | if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0; |
| 746 | if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0; |
| 747 | if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0; |
| 748 | if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0; |
| 749 | if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0; |
| 750 | if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0; |
| 751 | if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0; |
| 752 | if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0; |
| 753 | if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0; |
| 754 | if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0; |
| 755 | if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0; |
| 756 | if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0; |
| 757 | if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0; |
| 758 | if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0; |
| 759 | if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0; |
| 760 | if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0; |
| 761 | if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0; |
| 762 | return 1; |
| 763 | }; |
| 764 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 765 | static PyObject* ast2obj_mod(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 766 | static const char * const Module_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 767 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 768 | "type_ignores", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 769 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 770 | static const char * const Interactive_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 771 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 772 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 773 | static const char * const Expression_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 774 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 775 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 776 | static const char * const FunctionType_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 777 | "argtypes", |
| 778 | "returns", |
| 779 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 780 | static const char * const stmt_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 781 | "lineno", |
| 782 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 783 | "end_lineno", |
| 784 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 785 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 786 | static PyObject* ast2obj_stmt(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 787 | static const char * const FunctionDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 788 | "name", |
| 789 | "args", |
| 790 | "body", |
| 791 | "decorator_list", |
| 792 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 793 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 794 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 795 | static const char * const AsyncFunctionDef_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 796 | "name", |
| 797 | "args", |
| 798 | "body", |
| 799 | "decorator_list", |
| 800 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 801 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 802 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 803 | static const char * const ClassDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 804 | "name", |
| 805 | "bases", |
| 806 | "keywords", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 807 | "body", |
| 808 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 809 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 810 | static const char * const Return_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 811 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 812 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 813 | static const char * const Delete_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 814 | "targets", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 815 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 816 | static const char * const Assign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 817 | "targets", |
| 818 | "value", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 819 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 820 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 821 | static const char * const AugAssign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 822 | "target", |
| 823 | "op", |
| 824 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 825 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 826 | static const char * const AnnAssign_fields[]={ |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 827 | "target", |
| 828 | "annotation", |
| 829 | "value", |
| 830 | "simple", |
| 831 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 832 | static const char * const For_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 833 | "target", |
| 834 | "iter", |
| 835 | "body", |
| 836 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 837 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 838 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 839 | static const char * const AsyncFor_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 840 | "target", |
| 841 | "iter", |
| 842 | "body", |
| 843 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 844 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 845 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 846 | static const char * const While_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 847 | "test", |
| 848 | "body", |
| 849 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 850 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 851 | static const char * const If_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 852 | "test", |
| 853 | "body", |
| 854 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 855 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 856 | static const char * const With_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 857 | "items", |
| 858 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 859 | "type_comment", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 860 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 861 | static const char * const AsyncWith_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 862 | "items", |
| 863 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 864 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 865 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 866 | static const char * const Raise_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 867 | "exc", |
| 868 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 869 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 870 | static const char * const Try_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 871 | "body", |
| 872 | "handlers", |
| 873 | "orelse", |
| 874 | "finalbody", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 875 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 876 | static const char * const Assert_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 877 | "test", |
| 878 | "msg", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 879 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 880 | static const char * const Import_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 881 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 882 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 883 | static const char * const ImportFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 884 | "module", |
| 885 | "names", |
| 886 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 887 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 888 | static const char * const Global_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 889 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 890 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 891 | static const char * const Nonlocal_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 892 | "names", |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 893 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 894 | static const char * const Expr_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 895 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 896 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 897 | static const char * const expr_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 898 | "lineno", |
| 899 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 900 | "end_lineno", |
| 901 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 902 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 903 | static PyObject* ast2obj_expr(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 904 | static const char * const BoolOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 905 | "op", |
| 906 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 907 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 908 | static const char * const NamedExpr_fields[]={ |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 909 | "target", |
| 910 | "value", |
| 911 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 912 | static const char * const BinOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 913 | "left", |
| 914 | "op", |
| 915 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 916 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 917 | static const char * const UnaryOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 918 | "op", |
| 919 | "operand", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 920 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 921 | static const char * const Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 922 | "args", |
| 923 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 924 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 925 | static const char * const IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 926 | "test", |
| 927 | "body", |
| 928 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 929 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 930 | static const char * const Dict_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 931 | "keys", |
| 932 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 933 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 934 | static const char * const Set_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 935 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 936 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 937 | static const char * const ListComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 938 | "elt", |
| 939 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 940 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 941 | static const char * const SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 942 | "elt", |
| 943 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 944 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 945 | static const char * const DictComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 946 | "key", |
| 947 | "value", |
| 948 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 949 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 950 | static const char * const GeneratorExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 951 | "elt", |
| 952 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 953 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 954 | static const char * const Await_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 955 | "value", |
| 956 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 957 | static const char * const Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 958 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 959 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 960 | static const char * const YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 961 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 962 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 963 | static const char * const Compare_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 964 | "left", |
| 965 | "ops", |
| 966 | "comparators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 967 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 968 | static const char * const Call_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 969 | "func", |
| 970 | "args", |
| 971 | "keywords", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 972 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 973 | static const char * const FormattedValue_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 974 | "value", |
| 975 | "conversion", |
| 976 | "format_spec", |
| 977 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 978 | static const char * const JoinedStr_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 979 | "values", |
| 980 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 981 | static const char * const Constant_fields[]={ |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 982 | "value", |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 983 | "kind", |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 984 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 985 | static const char * const Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 986 | "value", |
| 987 | "attr", |
| 988 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 989 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 990 | static const char * const Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 991 | "value", |
| 992 | "slice", |
| 993 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 994 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 995 | static const char * const Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 996 | "value", |
| 997 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 998 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 999 | static const char * const Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1000 | "id", |
| 1001 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1002 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1003 | static const char * const List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1004 | "elts", |
| 1005 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1006 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1007 | static const char * const Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1008 | "elts", |
| 1009 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1010 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1011 | static const char * const Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1012 | "lower", |
| 1013 | "upper", |
| 1014 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1015 | }; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 1016 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1017 | static PyObject* ast2obj_boolop(boolop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1018 | static PyObject* ast2obj_operator(operator_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1019 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1020 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1021 | static PyObject* ast2obj_comprehension(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1022 | static const char * const comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1023 | "target", |
| 1024 | "iter", |
| 1025 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 1026 | "is_async", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1027 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1028 | static const char * const excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1029 | "lineno", |
| 1030 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1031 | "end_lineno", |
| 1032 | "end_col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1033 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1034 | static PyObject* ast2obj_excepthandler(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1035 | static const char * const ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1036 | "type", |
| 1037 | "name", |
| 1038 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1039 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1040 | static PyObject* ast2obj_arguments(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1041 | static const char * const arguments_fields[]={ |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 1042 | "posonlyargs", |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 1043 | "args", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1044 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1045 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1046 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1047 | "kwarg", |
| 1048 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1049 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1050 | static PyObject* ast2obj_arg(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1051 | static const char * const arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1052 | "lineno", |
| 1053 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1054 | "end_lineno", |
| 1055 | "end_col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1056 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1057 | static const char * const arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1058 | "arg", |
| 1059 | "annotation", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1060 | "type_comment", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1061 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1062 | static PyObject* ast2obj_keyword(void*); |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 1063 | static const char * const keyword_attributes[] = { |
| 1064 | "lineno", |
| 1065 | "col_offset", |
| 1066 | "end_lineno", |
| 1067 | "end_col_offset", |
| 1068 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1069 | static const char * const keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1070 | "arg", |
| 1071 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1072 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1073 | static PyObject* ast2obj_alias(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1074 | static const char * const alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1075 | "name", |
| 1076 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1077 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1078 | static PyObject* ast2obj_withitem(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1079 | static const char * const withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1080 | "context_expr", |
| 1081 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1082 | }; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1083 | static PyObject* ast2obj_type_ignore(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1084 | static const char * const TypeIgnore_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1085 | "lineno", |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 1086 | "tag", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1087 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1088 | |
| 1089 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1090 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1091 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 1092 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1093 | PyObject *dict; |
| 1094 | } AST_object; |
| 1095 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1096 | static void |
| 1097 | ast_dealloc(AST_object *self) |
| 1098 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1099 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1100 | PyTypeObject *tp = Py_TYPE(self); |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1101 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1102 | Py_CLEAR(self->dict); |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1103 | freefunc free_func = PyType_GetSlot(tp, Py_tp_free); |
| 1104 | assert(free_func != NULL); |
| 1105 | free_func(self); |
| 1106 | Py_DECREF(tp); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1107 | } |
| 1108 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1109 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1110 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 1111 | { |
| 1112 | Py_VISIT(self->dict); |
| 1113 | return 0; |
| 1114 | } |
| 1115 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1116 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1117 | ast_clear(AST_object *self) |
| 1118 | { |
| 1119 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1120 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1124 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 1125 | { |
| 1126 | Py_ssize_t i, numfields = 0; |
| 1127 | int res = -1; |
| 1128 | PyObject *key, *value, *fields; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1129 | if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1130 | goto cleanup; |
| 1131 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1132 | if (fields) { |
| 1133 | numfields = PySequence_Size(fields); |
Miss Islington (bot) | 1a4e9e6 | 2020-05-24 14:32:32 -0700 | [diff] [blame] | 1134 | if (numfields == -1) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1135 | goto cleanup; |
Miss Islington (bot) | 1a4e9e6 | 2020-05-24 14:32:32 -0700 | [diff] [blame] | 1136 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1137 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1138 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1139 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1140 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 1141 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 1142 | "%zd positional argument%s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1143 | _PyType_Name(Py_TYPE(self)), |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1144 | numfields, numfields == 1 ? "" : "s"); |
| 1145 | res = -1; |
| 1146 | goto cleanup; |
| 1147 | } |
| 1148 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 1149 | /* cannot be reached when fields is NULL */ |
| 1150 | PyObject *name = PySequence_GetItem(fields, i); |
| 1151 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1152 | res = -1; |
| 1153 | goto cleanup; |
| 1154 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1155 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 1156 | Py_DECREF(name); |
Miss Islington (bot) | 1a4e9e6 | 2020-05-24 14:32:32 -0700 | [diff] [blame] | 1157 | if (res < 0) { |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1158 | goto cleanup; |
Miss Islington (bot) | 1a4e9e6 | 2020-05-24 14:32:32 -0700 | [diff] [blame] | 1159 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1160 | } |
| 1161 | if (kw) { |
| 1162 | i = 0; /* needed by PyDict_Next */ |
| 1163 | while (PyDict_Next(kw, &i, &key, &value)) { |
Miss Islington (bot) | 1a4e9e6 | 2020-05-24 14:32:32 -0700 | [diff] [blame] | 1164 | int contains = PySequence_Contains(fields, key); |
| 1165 | if (contains == -1) { |
| 1166 | res = -1; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1167 | goto cleanup; |
Miss Islington (bot) | 1a4e9e6 | 2020-05-24 14:32:32 -0700 | [diff] [blame] | 1168 | } else if (contains == 1) { |
| 1169 | Py_ssize_t p = PySequence_Index(fields, key); |
| 1170 | if (p == -1) { |
| 1171 | res = -1; |
| 1172 | goto cleanup; |
| 1173 | } |
| 1174 | if (p < PyTuple_GET_SIZE(args)) { |
| 1175 | PyErr_Format(PyExc_TypeError, |
| 1176 | "%.400s got multiple values for argument '%U'", |
| 1177 | Py_TYPE(self)->tp_name, key); |
| 1178 | res = -1; |
| 1179 | goto cleanup; |
| 1180 | } |
| 1181 | } |
| 1182 | res = PyObject_SetAttr(self, key, value); |
| 1183 | if (res < 0) { |
| 1184 | goto cleanup; |
| 1185 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1186 | } |
| 1187 | } |
| 1188 | cleanup: |
| 1189 | Py_XDECREF(fields); |
| 1190 | return res; |
| 1191 | } |
| 1192 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1193 | /* Pickling support */ |
| 1194 | static PyObject * |
| 1195 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 1196 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1197 | PyObject *dict; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1198 | if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1199 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1200 | } |
| 1201 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1202 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1203 | } |
| 1204 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 1205 | } |
| 1206 | |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1207 | static PyMemberDef ast_type_members[] = { |
| 1208 | {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY}, |
| 1209 | {NULL} /* Sentinel */ |
| 1210 | }; |
| 1211 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1212 | static PyMethodDef ast_type_methods[] = { |
| 1213 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 1214 | {NULL} |
| 1215 | }; |
| 1216 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1217 | static PyGetSetDef ast_type_getsets[] = { |
| 1218 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 1219 | {NULL} |
| 1220 | }; |
| 1221 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1222 | static PyType_Slot AST_type_slots[] = { |
| 1223 | {Py_tp_dealloc, ast_dealloc}, |
| 1224 | {Py_tp_getattro, PyObject_GenericGetAttr}, |
| 1225 | {Py_tp_setattro, PyObject_GenericSetAttr}, |
| 1226 | {Py_tp_traverse, ast_traverse}, |
| 1227 | {Py_tp_clear, ast_clear}, |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1228 | {Py_tp_members, ast_type_members}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1229 | {Py_tp_methods, ast_type_methods}, |
| 1230 | {Py_tp_getset, ast_type_getsets}, |
| 1231 | {Py_tp_init, ast_type_init}, |
| 1232 | {Py_tp_alloc, PyType_GenericAlloc}, |
| 1233 | {Py_tp_new, PyType_GenericNew}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1234 | {Py_tp_free, PyObject_GC_Del}, |
| 1235 | {0, 0}, |
| 1236 | }; |
| 1237 | |
| 1238 | static PyType_Spec AST_type_spec = { |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 1239 | "ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1240 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1241 | 0, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1242 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
| 1243 | AST_type_slots |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1244 | }; |
| 1245 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1246 | static PyObject * |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1247 | make_type(const char *type, PyObject* base, const char* const* fields, int num_fields, const char *doc) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1248 | { |
| 1249 | PyObject *fnames, *result; |
| 1250 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1251 | fnames = PyTuple_New(num_fields); |
| 1252 | if (!fnames) return NULL; |
| 1253 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1254 | PyObject *field = PyUnicode_InternFromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1255 | if (!field) { |
| 1256 | Py_DECREF(fnames); |
| 1257 | return NULL; |
| 1258 | } |
| 1259 | PyTuple_SET_ITEM(fnames, i, field); |
| 1260 | } |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1261 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOs}", |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1262 | type, base, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1263 | astmodulestate_global->_fields, fnames, |
| 1264 | astmodulestate_global->__module__, |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 1265 | astmodulestate_global->ast, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1266 | astmodulestate_global->__doc__, doc); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1267 | Py_DECREF(fnames); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1268 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1271 | static int |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1272 | add_attributes(PyObject *type, const char * const *attrs, int num_fields) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1273 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1274 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1275 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 1276 | if (!l) |
| 1277 | return 0; |
| 1278 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1279 | s = PyUnicode_InternFromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1280 | if (!s) { |
| 1281 | Py_DECREF(l); |
| 1282 | return 0; |
| 1283 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1284 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1285 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1286 | result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1287 | Py_DECREF(l); |
| 1288 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1291 | /* Conversion AST -> Python */ |
| 1292 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1293 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 1294 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 1295 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1296 | PyObject *result = PyList_New(n); |
| 1297 | PyObject *value; |
| 1298 | if (!result) |
| 1299 | return NULL; |
| 1300 | for (i = 0; i < n; i++) { |
| 1301 | value = func(asdl_seq_GET(seq, i)); |
| 1302 | if (!value) { |
| 1303 | Py_DECREF(result); |
| 1304 | return NULL; |
| 1305 | } |
| 1306 | PyList_SET_ITEM(result, i, value); |
| 1307 | } |
| 1308 | return result; |
| 1309 | } |
| 1310 | |
| 1311 | static PyObject* ast2obj_object(void *o) |
| 1312 | { |
| 1313 | if (!o) |
| 1314 | o = Py_None; |
| 1315 | Py_INCREF((PyObject*)o); |
| 1316 | return (PyObject*)o; |
| 1317 | } |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1318 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1319 | #define ast2obj_identifier ast2obj_object |
| 1320 | #define ast2obj_string ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1321 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1322 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1323 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 1324 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1325 | } |
| 1326 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1327 | /* Conversion Python -> AST */ |
| 1328 | |
| 1329 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 1330 | { |
| 1331 | if (obj == Py_None) |
| 1332 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 1333 | if (obj) { |
| 1334 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1335 | *out = NULL; |
| 1336 | return -1; |
| 1337 | } |
| 1338 | Py_INCREF(obj); |
| 1339 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1340 | *out = obj; |
| 1341 | return 0; |
| 1342 | } |
| 1343 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1344 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 1345 | { |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1346 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1347 | *out = NULL; |
| 1348 | return -1; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1349 | } |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1350 | Py_INCREF(obj); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1351 | *out = obj; |
| 1352 | return 0; |
| 1353 | } |
| 1354 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1355 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1356 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1357 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 1358 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1359 | return 1; |
| 1360 | } |
| 1361 | return obj2ast_object(obj, out, arena); |
| 1362 | } |
| 1363 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1364 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 1365 | { |
| 1366 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
| 1367 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 1368 | return 1; |
| 1369 | } |
| 1370 | return obj2ast_object(obj, out, arena); |
| 1371 | } |
| 1372 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1373 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 1374 | { |
| 1375 | int i; |
| 1376 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 1377 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1378 | return 1; |
| 1379 | } |
| 1380 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 1381 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1382 | if (i == -1 && PyErr_Occurred()) |
| 1383 | return 1; |
| 1384 | *out = i; |
| 1385 | return 0; |
| 1386 | } |
| 1387 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 1388 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1389 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1390 | PyObject *empty_tuple; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1391 | empty_tuple = PyTuple_New(0); |
| 1392 | if (!empty_tuple || |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1393 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 || |
| 1394 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) { |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1395 | Py_XDECREF(empty_tuple); |
| 1396 | return -1; |
| 1397 | } |
| 1398 | Py_DECREF(empty_tuple); |
| 1399 | return 0; |
| 1400 | } |
| 1401 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1402 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1403 | static int init_types(void) |
| 1404 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1405 | PyObject *m; |
| 1406 | if (PyState_FindModule(&_astmodule) == NULL) { |
| 1407 | m = PyModule_Create(&_astmodule); |
| 1408 | if (!m) return 0; |
| 1409 | PyState_AddModule(m, &_astmodule); |
| 1410 | } |
| 1411 | astmodulestate *state = astmodulestate_global; |
| 1412 | if (state->initialized) return 1; |
| 1413 | if (init_identifiers() < 0) return 0; |
| 1414 | state->AST_type = PyType_FromSpec(&AST_type_spec); |
| 1415 | if (!state->AST_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1416 | if (add_ast_fields() < 0) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1417 | state->mod_type = make_type("mod", state->AST_type, NULL, 0, |
| 1418 | "mod = Module(stmt* body, type_ignore* type_ignores)\n" |
| 1419 | " | Interactive(stmt* body)\n" |
| 1420 | " | Expression(expr body)\n" |
| 1421 | " | FunctionType(expr* argtypes, expr returns)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1422 | if (!state->mod_type) return 0; |
| 1423 | if (!add_attributes(state->mod_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1424 | state->Module_type = make_type("Module", state->mod_type, Module_fields, 2, |
| 1425 | "Module(stmt* body, type_ignore* type_ignores)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1426 | if (!state->Module_type) return 0; |
| 1427 | state->Interactive_type = make_type("Interactive", state->mod_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1428 | Interactive_fields, 1, |
| 1429 | "Interactive(stmt* body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1430 | if (!state->Interactive_type) return 0; |
| 1431 | state->Expression_type = make_type("Expression", state->mod_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1432 | Expression_fields, 1, |
| 1433 | "Expression(expr body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1434 | if (!state->Expression_type) return 0; |
| 1435 | state->FunctionType_type = make_type("FunctionType", state->mod_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1436 | FunctionType_fields, 2, |
| 1437 | "FunctionType(expr* argtypes, expr returns)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1438 | if (!state->FunctionType_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1439 | state->stmt_type = make_type("stmt", state->AST_type, NULL, 0, |
| 1440 | "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" |
| 1441 | " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" |
| 1442 | " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n" |
| 1443 | " | Return(expr? value)\n" |
| 1444 | " | Delete(expr* targets)\n" |
| 1445 | " | Assign(expr* targets, expr value, string? type_comment)\n" |
| 1446 | " | AugAssign(expr target, operator op, expr value)\n" |
| 1447 | " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n" |
| 1448 | " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n" |
| 1449 | " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n" |
| 1450 | " | While(expr test, stmt* body, stmt* orelse)\n" |
| 1451 | " | If(expr test, stmt* body, stmt* orelse)\n" |
| 1452 | " | With(withitem* items, stmt* body, string? type_comment)\n" |
| 1453 | " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n" |
| 1454 | " | Raise(expr? exc, expr? cause)\n" |
| 1455 | " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n" |
| 1456 | " | Assert(expr test, expr? msg)\n" |
| 1457 | " | Import(alias* names)\n" |
| 1458 | " | ImportFrom(identifier? module, alias* names, int? level)\n" |
| 1459 | " | Global(identifier* names)\n" |
| 1460 | " | Nonlocal(identifier* names)\n" |
| 1461 | " | Expr(expr value)\n" |
| 1462 | " | Pass\n" |
| 1463 | " | Break\n" |
| 1464 | " | Continue"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1465 | if (!state->stmt_type) return 0; |
| 1466 | if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1467 | if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1) |
| 1468 | return 0; |
| 1469 | if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) == |
| 1470 | -1) |
| 1471 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1472 | state->FunctionDef_type = make_type("FunctionDef", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1473 | FunctionDef_fields, 6, |
| 1474 | "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1475 | if (!state->FunctionDef_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1476 | if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) == |
| 1477 | -1) |
| 1478 | return 0; |
| 1479 | if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None) |
| 1480 | == -1) |
| 1481 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1482 | state->AsyncFunctionDef_type = make_type("AsyncFunctionDef", |
| 1483 | state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1484 | AsyncFunctionDef_fields, 6, |
| 1485 | "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1486 | if (!state->AsyncFunctionDef_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1487 | if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None) |
| 1488 | == -1) |
| 1489 | return 0; |
| 1490 | if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment, |
| 1491 | Py_None) == -1) |
| 1492 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1493 | state->ClassDef_type = make_type("ClassDef", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1494 | ClassDef_fields, 5, |
| 1495 | "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1496 | if (!state->ClassDef_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1497 | state->Return_type = make_type("Return", state->stmt_type, Return_fields, 1, |
| 1498 | "Return(expr? value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1499 | if (!state->Return_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1500 | if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1) |
| 1501 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1502 | state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, 1, |
| 1503 | "Delete(expr* targets)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1504 | if (!state->Delete_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1505 | state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, 3, |
| 1506 | "Assign(expr* targets, expr value, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1507 | if (!state->Assign_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1508 | if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) == |
| 1509 | -1) |
| 1510 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1511 | state->AugAssign_type = make_type("AugAssign", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1512 | AugAssign_fields, 3, |
| 1513 | "AugAssign(expr target, operator op, expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1514 | if (!state->AugAssign_type) return 0; |
| 1515 | state->AnnAssign_type = make_type("AnnAssign", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1516 | AnnAssign_fields, 4, |
| 1517 | "AnnAssign(expr target, expr annotation, expr? value, int simple)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1518 | if (!state->AnnAssign_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1519 | if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1) |
| 1520 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1521 | state->For_type = make_type("For", state->stmt_type, For_fields, 5, |
| 1522 | "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1523 | if (!state->For_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1524 | if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1) |
| 1525 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1526 | state->AsyncFor_type = make_type("AsyncFor", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1527 | AsyncFor_fields, 5, |
| 1528 | "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1529 | if (!state->AsyncFor_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1530 | if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) == |
| 1531 | -1) |
| 1532 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1533 | state->While_type = make_type("While", state->stmt_type, While_fields, 3, |
| 1534 | "While(expr test, stmt* body, stmt* orelse)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1535 | if (!state->While_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1536 | state->If_type = make_type("If", state->stmt_type, If_fields, 3, |
| 1537 | "If(expr test, stmt* body, stmt* orelse)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1538 | if (!state->If_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1539 | state->With_type = make_type("With", state->stmt_type, With_fields, 3, |
| 1540 | "With(withitem* items, stmt* body, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1541 | if (!state->With_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1542 | if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1) |
| 1543 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1544 | state->AsyncWith_type = make_type("AsyncWith", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1545 | AsyncWith_fields, 3, |
| 1546 | "AsyncWith(withitem* items, stmt* body, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1547 | if (!state->AsyncWith_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1548 | if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None) |
| 1549 | == -1) |
| 1550 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1551 | state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2, |
| 1552 | "Raise(expr? exc, expr? cause)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1553 | if (!state->Raise_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1554 | if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1) |
| 1555 | return 0; |
| 1556 | if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1) |
| 1557 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1558 | state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4, |
| 1559 | "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1560 | if (!state->Try_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1561 | state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, 2, |
| 1562 | "Assert(expr test, expr? msg)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1563 | if (!state->Assert_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1564 | if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1) |
| 1565 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1566 | state->Import_type = make_type("Import", state->stmt_type, Import_fields, 1, |
| 1567 | "Import(alias* names)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1568 | if (!state->Import_type) return 0; |
| 1569 | state->ImportFrom_type = make_type("ImportFrom", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1570 | ImportFrom_fields, 3, |
| 1571 | "ImportFrom(identifier? module, alias* names, int? level)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1572 | if (!state->ImportFrom_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1573 | if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1) |
| 1574 | return 0; |
| 1575 | if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1) |
| 1576 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1577 | state->Global_type = make_type("Global", state->stmt_type, Global_fields, 1, |
| 1578 | "Global(identifier* names)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1579 | if (!state->Global_type) return 0; |
| 1580 | state->Nonlocal_type = make_type("Nonlocal", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1581 | Nonlocal_fields, 1, |
| 1582 | "Nonlocal(identifier* names)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1583 | if (!state->Nonlocal_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1584 | state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1, |
| 1585 | "Expr(expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1586 | if (!state->Expr_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1587 | state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0, |
| 1588 | "Pass"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1589 | if (!state->Pass_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1590 | state->Break_type = make_type("Break", state->stmt_type, NULL, 0, |
| 1591 | "Break"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1592 | if (!state->Break_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1593 | state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0, |
| 1594 | "Continue"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1595 | if (!state->Continue_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1596 | state->expr_type = make_type("expr", state->AST_type, NULL, 0, |
| 1597 | "expr = BoolOp(boolop op, expr* values)\n" |
| 1598 | " | NamedExpr(expr target, expr value)\n" |
| 1599 | " | BinOp(expr left, operator op, expr right)\n" |
| 1600 | " | UnaryOp(unaryop op, expr operand)\n" |
| 1601 | " | Lambda(arguments args, expr body)\n" |
| 1602 | " | IfExp(expr test, expr body, expr orelse)\n" |
| 1603 | " | Dict(expr* keys, expr* values)\n" |
| 1604 | " | Set(expr* elts)\n" |
| 1605 | " | ListComp(expr elt, comprehension* generators)\n" |
| 1606 | " | SetComp(expr elt, comprehension* generators)\n" |
| 1607 | " | DictComp(expr key, expr value, comprehension* generators)\n" |
| 1608 | " | GeneratorExp(expr elt, comprehension* generators)\n" |
| 1609 | " | Await(expr value)\n" |
| 1610 | " | Yield(expr? value)\n" |
| 1611 | " | YieldFrom(expr value)\n" |
| 1612 | " | Compare(expr left, cmpop* ops, expr* comparators)\n" |
| 1613 | " | Call(expr func, expr* args, keyword* keywords)\n" |
| 1614 | " | FormattedValue(expr value, int? conversion, expr? format_spec)\n" |
| 1615 | " | JoinedStr(expr* values)\n" |
| 1616 | " | Constant(constant value, string? kind)\n" |
| 1617 | " | Attribute(expr value, identifier attr, expr_context ctx)\n" |
| 1618 | " | Subscript(expr value, expr slice, expr_context ctx)\n" |
| 1619 | " | Starred(expr value, expr_context ctx)\n" |
| 1620 | " | Name(identifier id, expr_context ctx)\n" |
| 1621 | " | List(expr* elts, expr_context ctx)\n" |
| 1622 | " | Tuple(expr* elts, expr_context ctx)\n" |
| 1623 | " | Slice(expr? lower, expr? upper, expr? step)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1624 | if (!state->expr_type) return 0; |
| 1625 | if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1626 | if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1) |
| 1627 | return 0; |
| 1628 | if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) == |
| 1629 | -1) |
| 1630 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1631 | state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, 2, |
| 1632 | "BoolOp(boolop op, expr* values)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1633 | if (!state->BoolOp_type) return 0; |
| 1634 | state->NamedExpr_type = make_type("NamedExpr", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1635 | NamedExpr_fields, 2, |
| 1636 | "NamedExpr(expr target, expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1637 | if (!state->NamedExpr_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1638 | state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3, |
| 1639 | "BinOp(expr left, operator op, expr right)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1640 | if (!state->BinOp_type) return 0; |
| 1641 | state->UnaryOp_type = make_type("UnaryOp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1642 | UnaryOp_fields, 2, |
| 1643 | "UnaryOp(unaryop op, expr operand)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1644 | if (!state->UnaryOp_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1645 | state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, 2, |
| 1646 | "Lambda(arguments args, expr body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1647 | if (!state->Lambda_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1648 | state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3, |
| 1649 | "IfExp(expr test, expr body, expr orelse)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1650 | if (!state->IfExp_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1651 | state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2, |
| 1652 | "Dict(expr* keys, expr* values)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1653 | if (!state->Dict_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1654 | state->Set_type = make_type("Set", state->expr_type, Set_fields, 1, |
| 1655 | "Set(expr* elts)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1656 | if (!state->Set_type) return 0; |
| 1657 | state->ListComp_type = make_type("ListComp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1658 | ListComp_fields, 2, |
| 1659 | "ListComp(expr elt, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1660 | if (!state->ListComp_type) return 0; |
| 1661 | state->SetComp_type = make_type("SetComp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1662 | SetComp_fields, 2, |
| 1663 | "SetComp(expr elt, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1664 | if (!state->SetComp_type) return 0; |
| 1665 | state->DictComp_type = make_type("DictComp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1666 | DictComp_fields, 3, |
| 1667 | "DictComp(expr key, expr value, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1668 | if (!state->DictComp_type) return 0; |
| 1669 | state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1670 | GeneratorExp_fields, 2, |
| 1671 | "GeneratorExp(expr elt, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1672 | if (!state->GeneratorExp_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1673 | state->Await_type = make_type("Await", state->expr_type, Await_fields, 1, |
| 1674 | "Await(expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1675 | if (!state->Await_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1676 | state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1, |
| 1677 | "Yield(expr? value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1678 | if (!state->Yield_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1679 | if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1) |
| 1680 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1681 | state->YieldFrom_type = make_type("YieldFrom", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1682 | YieldFrom_fields, 1, |
| 1683 | "YieldFrom(expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1684 | if (!state->YieldFrom_type) return 0; |
| 1685 | state->Compare_type = make_type("Compare", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1686 | Compare_fields, 3, |
| 1687 | "Compare(expr left, cmpop* ops, expr* comparators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1688 | if (!state->Compare_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1689 | state->Call_type = make_type("Call", state->expr_type, Call_fields, 3, |
| 1690 | "Call(expr func, expr* args, keyword* keywords)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1691 | if (!state->Call_type) return 0; |
| 1692 | state->FormattedValue_type = make_type("FormattedValue", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1693 | FormattedValue_fields, 3, |
| 1694 | "FormattedValue(expr value, int? conversion, expr? format_spec)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1695 | if (!state->FormattedValue_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1696 | if (PyObject_SetAttr(state->FormattedValue_type, state->conversion, |
| 1697 | Py_None) == -1) |
| 1698 | return 0; |
| 1699 | if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec, |
| 1700 | Py_None) == -1) |
| 1701 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1702 | state->JoinedStr_type = make_type("JoinedStr", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1703 | JoinedStr_fields, 1, |
| 1704 | "JoinedStr(expr* values)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1705 | if (!state->JoinedStr_type) return 0; |
| 1706 | state->Constant_type = make_type("Constant", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1707 | Constant_fields, 2, |
| 1708 | "Constant(constant value, string? kind)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1709 | if (!state->Constant_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1710 | if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1) |
| 1711 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1712 | state->Attribute_type = make_type("Attribute", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1713 | Attribute_fields, 3, |
| 1714 | "Attribute(expr value, identifier attr, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1715 | if (!state->Attribute_type) return 0; |
| 1716 | state->Subscript_type = make_type("Subscript", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1717 | Subscript_fields, 3, |
| 1718 | "Subscript(expr value, expr slice, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1719 | if (!state->Subscript_type) return 0; |
| 1720 | state->Starred_type = make_type("Starred", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1721 | Starred_fields, 2, |
| 1722 | "Starred(expr value, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1723 | if (!state->Starred_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1724 | state->Name_type = make_type("Name", state->expr_type, Name_fields, 2, |
| 1725 | "Name(identifier id, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1726 | if (!state->Name_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1727 | state->List_type = make_type("List", state->expr_type, List_fields, 2, |
| 1728 | "List(expr* elts, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1729 | if (!state->List_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1730 | state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2, |
| 1731 | "Tuple(expr* elts, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1732 | if (!state->Tuple_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1733 | state->Slice_type = make_type("Slice", state->expr_type, Slice_fields, 3, |
| 1734 | "Slice(expr? lower, expr? upper, expr? step)"); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 1735 | if (!state->Slice_type) return 0; |
| 1736 | if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1) |
| 1737 | return 0; |
| 1738 | if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1) |
| 1739 | return 0; |
| 1740 | if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1) |
| 1741 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1742 | state->expr_context_type = make_type("expr_context", state->AST_type, NULL, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1743 | 0, |
Serhiy Storchaka | 6b97598 | 2020-03-17 23:41:08 +0200 | [diff] [blame] | 1744 | "expr_context = Load | Store | Del"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1745 | if (!state->expr_context_type) return 0; |
| 1746 | if (!add_attributes(state->expr_context_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1747 | state->Load_type = make_type("Load", state->expr_context_type, NULL, 0, |
| 1748 | "Load"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1749 | if (!state->Load_type) return 0; |
| 1750 | state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type, |
| 1751 | NULL, NULL); |
| 1752 | if (!state->Load_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1753 | state->Store_type = make_type("Store", state->expr_context_type, NULL, 0, |
| 1754 | "Store"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1755 | if (!state->Store_type) return 0; |
| 1756 | state->Store_singleton = PyType_GenericNew((PyTypeObject |
| 1757 | *)state->Store_type, NULL, NULL); |
| 1758 | if (!state->Store_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1759 | state->Del_type = make_type("Del", state->expr_context_type, NULL, 0, |
| 1760 | "Del"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1761 | if (!state->Del_type) return 0; |
| 1762 | state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type, |
| 1763 | NULL, NULL); |
| 1764 | if (!state->Del_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1765 | state->boolop_type = make_type("boolop", state->AST_type, NULL, 0, |
| 1766 | "boolop = And | Or"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1767 | if (!state->boolop_type) return 0; |
| 1768 | if (!add_attributes(state->boolop_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1769 | state->And_type = make_type("And", state->boolop_type, NULL, 0, |
| 1770 | "And"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1771 | if (!state->And_type) return 0; |
| 1772 | state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type, |
| 1773 | NULL, NULL); |
| 1774 | if (!state->And_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1775 | state->Or_type = make_type("Or", state->boolop_type, NULL, 0, |
| 1776 | "Or"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1777 | if (!state->Or_type) return 0; |
| 1778 | state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type, |
| 1779 | NULL, NULL); |
| 1780 | if (!state->Or_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1781 | state->operator_type = make_type("operator", state->AST_type, NULL, 0, |
| 1782 | "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1783 | if (!state->operator_type) return 0; |
| 1784 | if (!add_attributes(state->operator_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1785 | state->Add_type = make_type("Add", state->operator_type, NULL, 0, |
| 1786 | "Add"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1787 | if (!state->Add_type) return 0; |
| 1788 | state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type, |
| 1789 | NULL, NULL); |
| 1790 | if (!state->Add_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1791 | state->Sub_type = make_type("Sub", state->operator_type, NULL, 0, |
| 1792 | "Sub"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1793 | if (!state->Sub_type) return 0; |
| 1794 | state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type, |
| 1795 | NULL, NULL); |
| 1796 | if (!state->Sub_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1797 | state->Mult_type = make_type("Mult", state->operator_type, NULL, 0, |
| 1798 | "Mult"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1799 | if (!state->Mult_type) return 0; |
| 1800 | state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type, |
| 1801 | NULL, NULL); |
| 1802 | if (!state->Mult_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1803 | state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0, |
| 1804 | "MatMult"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1805 | if (!state->MatMult_type) return 0; |
| 1806 | state->MatMult_singleton = PyType_GenericNew((PyTypeObject |
| 1807 | *)state->MatMult_type, NULL, |
| 1808 | NULL); |
| 1809 | if (!state->MatMult_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1810 | state->Div_type = make_type("Div", state->operator_type, NULL, 0, |
| 1811 | "Div"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1812 | if (!state->Div_type) return 0; |
| 1813 | state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type, |
| 1814 | NULL, NULL); |
| 1815 | if (!state->Div_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1816 | state->Mod_type = make_type("Mod", state->operator_type, NULL, 0, |
| 1817 | "Mod"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1818 | if (!state->Mod_type) return 0; |
| 1819 | state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type, |
| 1820 | NULL, NULL); |
| 1821 | if (!state->Mod_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1822 | state->Pow_type = make_type("Pow", state->operator_type, NULL, 0, |
| 1823 | "Pow"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1824 | if (!state->Pow_type) return 0; |
| 1825 | state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type, |
| 1826 | NULL, NULL); |
| 1827 | if (!state->Pow_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1828 | state->LShift_type = make_type("LShift", state->operator_type, NULL, 0, |
| 1829 | "LShift"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1830 | if (!state->LShift_type) return 0; |
| 1831 | state->LShift_singleton = PyType_GenericNew((PyTypeObject |
| 1832 | *)state->LShift_type, NULL, |
| 1833 | NULL); |
| 1834 | if (!state->LShift_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1835 | state->RShift_type = make_type("RShift", state->operator_type, NULL, 0, |
| 1836 | "RShift"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1837 | if (!state->RShift_type) return 0; |
| 1838 | state->RShift_singleton = PyType_GenericNew((PyTypeObject |
| 1839 | *)state->RShift_type, NULL, |
| 1840 | NULL); |
| 1841 | if (!state->RShift_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1842 | state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0, |
| 1843 | "BitOr"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1844 | if (!state->BitOr_type) return 0; |
| 1845 | state->BitOr_singleton = PyType_GenericNew((PyTypeObject |
| 1846 | *)state->BitOr_type, NULL, NULL); |
| 1847 | if (!state->BitOr_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1848 | state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0, |
| 1849 | "BitXor"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1850 | if (!state->BitXor_type) return 0; |
| 1851 | state->BitXor_singleton = PyType_GenericNew((PyTypeObject |
| 1852 | *)state->BitXor_type, NULL, |
| 1853 | NULL); |
| 1854 | if (!state->BitXor_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1855 | state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0, |
| 1856 | "BitAnd"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1857 | if (!state->BitAnd_type) return 0; |
| 1858 | state->BitAnd_singleton = PyType_GenericNew((PyTypeObject |
| 1859 | *)state->BitAnd_type, NULL, |
| 1860 | NULL); |
| 1861 | if (!state->BitAnd_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1862 | state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0, |
| 1863 | "FloorDiv"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1864 | if (!state->FloorDiv_type) return 0; |
| 1865 | state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject |
| 1866 | *)state->FloorDiv_type, NULL, |
| 1867 | NULL); |
| 1868 | if (!state->FloorDiv_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1869 | state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0, |
| 1870 | "unaryop = Invert | Not | UAdd | USub"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1871 | if (!state->unaryop_type) return 0; |
| 1872 | if (!add_attributes(state->unaryop_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1873 | state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0, |
| 1874 | "Invert"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1875 | if (!state->Invert_type) return 0; |
| 1876 | state->Invert_singleton = PyType_GenericNew((PyTypeObject |
| 1877 | *)state->Invert_type, NULL, |
| 1878 | NULL); |
| 1879 | if (!state->Invert_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1880 | state->Not_type = make_type("Not", state->unaryop_type, NULL, 0, |
| 1881 | "Not"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1882 | if (!state->Not_type) return 0; |
| 1883 | state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type, |
| 1884 | NULL, NULL); |
| 1885 | if (!state->Not_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1886 | state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0, |
| 1887 | "UAdd"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1888 | if (!state->UAdd_type) return 0; |
| 1889 | state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type, |
| 1890 | NULL, NULL); |
| 1891 | if (!state->UAdd_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1892 | state->USub_type = make_type("USub", state->unaryop_type, NULL, 0, |
| 1893 | "USub"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1894 | if (!state->USub_type) return 0; |
| 1895 | state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type, |
| 1896 | NULL, NULL); |
| 1897 | if (!state->USub_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1898 | state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0, |
| 1899 | "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1900 | if (!state->cmpop_type) return 0; |
| 1901 | if (!add_attributes(state->cmpop_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1902 | state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0, |
| 1903 | "Eq"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1904 | if (!state->Eq_type) return 0; |
| 1905 | state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type, |
| 1906 | NULL, NULL); |
| 1907 | if (!state->Eq_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1908 | state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0, |
| 1909 | "NotEq"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1910 | if (!state->NotEq_type) return 0; |
| 1911 | state->NotEq_singleton = PyType_GenericNew((PyTypeObject |
| 1912 | *)state->NotEq_type, NULL, NULL); |
| 1913 | if (!state->NotEq_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1914 | state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0, |
| 1915 | "Lt"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1916 | if (!state->Lt_type) return 0; |
| 1917 | state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type, |
| 1918 | NULL, NULL); |
| 1919 | if (!state->Lt_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1920 | state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0, |
| 1921 | "LtE"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1922 | if (!state->LtE_type) return 0; |
| 1923 | state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type, |
| 1924 | NULL, NULL); |
| 1925 | if (!state->LtE_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1926 | state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0, |
| 1927 | "Gt"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1928 | if (!state->Gt_type) return 0; |
| 1929 | state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type, |
| 1930 | NULL, NULL); |
| 1931 | if (!state->Gt_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1932 | state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0, |
| 1933 | "GtE"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1934 | if (!state->GtE_type) return 0; |
| 1935 | state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type, |
| 1936 | NULL, NULL); |
| 1937 | if (!state->GtE_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1938 | state->Is_type = make_type("Is", state->cmpop_type, NULL, 0, |
| 1939 | "Is"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1940 | if (!state->Is_type) return 0; |
| 1941 | state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type, |
| 1942 | NULL, NULL); |
| 1943 | if (!state->Is_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1944 | state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0, |
| 1945 | "IsNot"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1946 | if (!state->IsNot_type) return 0; |
| 1947 | state->IsNot_singleton = PyType_GenericNew((PyTypeObject |
| 1948 | *)state->IsNot_type, NULL, NULL); |
| 1949 | if (!state->IsNot_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1950 | state->In_type = make_type("In", state->cmpop_type, NULL, 0, |
| 1951 | "In"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1952 | if (!state->In_type) return 0; |
| 1953 | state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type, |
| 1954 | NULL, NULL); |
| 1955 | if (!state->In_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1956 | state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0, |
| 1957 | "NotIn"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1958 | if (!state->NotIn_type) return 0; |
| 1959 | state->NotIn_singleton = PyType_GenericNew((PyTypeObject |
| 1960 | *)state->NotIn_type, NULL, NULL); |
| 1961 | if (!state->NotIn_singleton) return 0; |
| 1962 | state->comprehension_type = make_type("comprehension", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1963 | comprehension_fields, 4, |
| 1964 | "comprehension(expr target, expr iter, expr* ifs, int is_async)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1965 | if (!state->comprehension_type) return 0; |
| 1966 | if (!add_attributes(state->comprehension_type, NULL, 0)) return 0; |
| 1967 | state->excepthandler_type = make_type("excepthandler", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1968 | NULL, 0, |
| 1969 | "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1970 | if (!state->excepthandler_type) return 0; |
| 1971 | if (!add_attributes(state->excepthandler_type, excepthandler_attributes, |
| 1972 | 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1973 | if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None) |
| 1974 | == -1) |
| 1975 | return 0; |
| 1976 | if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset, |
| 1977 | Py_None) == -1) |
| 1978 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1979 | state->ExceptHandler_type = make_type("ExceptHandler", |
| 1980 | state->excepthandler_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1981 | ExceptHandler_fields, 3, |
| 1982 | "ExceptHandler(expr? type, identifier? name, stmt* body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1983 | if (!state->ExceptHandler_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1984 | if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1) |
| 1985 | return 0; |
| 1986 | if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1) |
| 1987 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1988 | state->arguments_type = make_type("arguments", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1989 | arguments_fields, 7, |
| 1990 | "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1991 | if (!state->arguments_type) return 0; |
| 1992 | if (!add_attributes(state->arguments_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1993 | if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1) |
| 1994 | return 0; |
| 1995 | if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1) |
| 1996 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1997 | state->arg_type = make_type("arg", state->AST_type, arg_fields, 3, |
| 1998 | "arg(identifier arg, expr? annotation, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1999 | if (!state->arg_type) return 0; |
| 2000 | if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 2001 | if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1) |
| 2002 | return 0; |
| 2003 | if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1) |
| 2004 | return 0; |
| 2005 | if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1) |
| 2006 | return 0; |
| 2007 | if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1) |
| 2008 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2009 | state->keyword_type = make_type("keyword", state->AST_type, keyword_fields, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2010 | 2, |
| 2011 | "keyword(identifier? arg, expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2012 | if (!state->keyword_type) return 0; |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 2013 | if (!add_attributes(state->keyword_type, keyword_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 2014 | if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1) |
| 2015 | return 0; |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 2016 | if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1) |
| 2017 | return 0; |
| 2018 | if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None) |
| 2019 | == -1) |
| 2020 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2021 | state->alias_type = make_type("alias", state->AST_type, alias_fields, 2, |
| 2022 | "alias(identifier name, identifier? asname)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2023 | if (!state->alias_type) return 0; |
| 2024 | if (!add_attributes(state->alias_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 2025 | if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1) |
| 2026 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2027 | state->withitem_type = make_type("withitem", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2028 | withitem_fields, 2, |
| 2029 | "withitem(expr context_expr, expr? optional_vars)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2030 | if (!state->withitem_type) return 0; |
| 2031 | if (!add_attributes(state->withitem_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 2032 | if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None) |
| 2033 | == -1) |
| 2034 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2035 | state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, 0, |
| 2036 | "type_ignore = TypeIgnore(int lineno, string tag)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2037 | if (!state->type_ignore_type) return 0; |
| 2038 | if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0; |
| 2039 | state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2040 | TypeIgnore_fields, 2, |
| 2041 | "TypeIgnore(int lineno, string tag)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2042 | if (!state->TypeIgnore_type) return 0; |
| 2043 | state->initialized = 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2044 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2045 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2046 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2047 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 2048 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 2049 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 2050 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 2051 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2052 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 2053 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 2054 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 2055 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 2056 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 2057 | arena); |
| 2058 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 2059 | arena); |
| 2060 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 2061 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 2062 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 2063 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2064 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2065 | static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* |
| 2066 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2067 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2068 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2069 | Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2070 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2071 | mod_ty p; |
| 2072 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2073 | if (!p) |
| 2074 | return NULL; |
| 2075 | p->kind = Module_kind; |
| 2076 | p->v.Module.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2077 | p->v.Module.type_ignores = type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2078 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2082 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2083 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2084 | mod_ty p; |
| 2085 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2086 | if (!p) |
| 2087 | return NULL; |
| 2088 | p->kind = Interactive_kind; |
| 2089 | p->v.Interactive.body = body; |
| 2090 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2094 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2095 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2096 | mod_ty p; |
| 2097 | if (!body) { |
| 2098 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2099 | "field 'body' is required for Expression"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2100 | return NULL; |
| 2101 | } |
| 2102 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2103 | if (!p) |
| 2104 | return NULL; |
| 2105 | p->kind = Expression_kind; |
| 2106 | p->v.Expression.body = body; |
| 2107 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2111 | FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena) |
| 2112 | { |
| 2113 | mod_ty p; |
| 2114 | if (!returns) { |
| 2115 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2116 | "field 'returns' is required for FunctionType"); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2117 | return NULL; |
| 2118 | } |
| 2119 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2120 | if (!p) |
| 2121 | return NULL; |
| 2122 | p->kind = FunctionType_kind; |
| 2123 | p->v.FunctionType.argtypes = argtypes; |
| 2124 | p->v.FunctionType.returns = returns; |
| 2125 | return p; |
| 2126 | } |
| 2127 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2128 | stmt_ty |
| 2129 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2130 | decorator_list, expr_ty returns, string type_comment, int lineno, |
| 2131 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2132 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2133 | stmt_ty p; |
| 2134 | if (!name) { |
| 2135 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2136 | "field 'name' is required for FunctionDef"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2137 | return NULL; |
| 2138 | } |
| 2139 | if (!args) { |
| 2140 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2141 | "field 'args' is required for FunctionDef"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2142 | return NULL; |
| 2143 | } |
| 2144 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2145 | if (!p) |
| 2146 | return NULL; |
| 2147 | p->kind = FunctionDef_kind; |
| 2148 | p->v.FunctionDef.name = name; |
| 2149 | p->v.FunctionDef.args = args; |
| 2150 | p->v.FunctionDef.body = body; |
| 2151 | p->v.FunctionDef.decorator_list = decorator_list; |
| 2152 | p->v.FunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2153 | p->v.FunctionDef.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2154 | p->lineno = lineno; |
| 2155 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2156 | p->end_lineno = end_lineno; |
| 2157 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2158 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2162 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2163 | * decorator_list, expr_ty returns, string type_comment, int |
| 2164 | lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2165 | PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2166 | { |
| 2167 | stmt_ty p; |
| 2168 | if (!name) { |
| 2169 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2170 | "field 'name' is required for AsyncFunctionDef"); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2171 | return NULL; |
| 2172 | } |
| 2173 | if (!args) { |
| 2174 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2175 | "field 'args' is required for AsyncFunctionDef"); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2176 | return NULL; |
| 2177 | } |
| 2178 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2179 | if (!p) |
| 2180 | return NULL; |
| 2181 | p->kind = AsyncFunctionDef_kind; |
| 2182 | p->v.AsyncFunctionDef.name = name; |
| 2183 | p->v.AsyncFunctionDef.args = args; |
| 2184 | p->v.AsyncFunctionDef.body = body; |
| 2185 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 2186 | p->v.AsyncFunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2187 | p->v.AsyncFunctionDef.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2188 | p->lineno = lineno; |
| 2189 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2190 | p->end_lineno = end_lineno; |
| 2191 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2192 | return p; |
| 2193 | } |
| 2194 | |
| 2195 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2196 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2197 | body, asdl_seq * decorator_list, int lineno, int col_offset, int |
| 2198 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2199 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2200 | stmt_ty p; |
| 2201 | if (!name) { |
| 2202 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2203 | "field 'name' is required for ClassDef"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2204 | return NULL; |
| 2205 | } |
| 2206 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2207 | if (!p) |
| 2208 | return NULL; |
| 2209 | p->kind = ClassDef_kind; |
| 2210 | p->v.ClassDef.name = name; |
| 2211 | p->v.ClassDef.bases = bases; |
| 2212 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2213 | p->v.ClassDef.body = body; |
| 2214 | p->v.ClassDef.decorator_list = decorator_list; |
| 2215 | p->lineno = lineno; |
| 2216 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2217 | p->end_lineno = end_lineno; |
| 2218 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2219 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2220 | } |
| 2221 | |
| 2222 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2223 | Return(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2224 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2225 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2226 | stmt_ty p; |
| 2227 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2228 | if (!p) |
| 2229 | return NULL; |
| 2230 | p->kind = Return_kind; |
| 2231 | p->v.Return.value = value; |
| 2232 | p->lineno = lineno; |
| 2233 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2234 | p->end_lineno = end_lineno; |
| 2235 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2236 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2240 | Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int |
| 2241 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2242 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2243 | stmt_ty p; |
| 2244 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2245 | if (!p) |
| 2246 | return NULL; |
| 2247 | p->kind = Delete_kind; |
| 2248 | p->v.Delete.targets = targets; |
| 2249 | p->lineno = lineno; |
| 2250 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2251 | p->end_lineno = end_lineno; |
| 2252 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2253 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2254 | } |
| 2255 | |
| 2256 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2257 | Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int |
| 2258 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2259 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2260 | stmt_ty p; |
| 2261 | if (!value) { |
| 2262 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2263 | "field 'value' is required for Assign"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2264 | return NULL; |
| 2265 | } |
| 2266 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2267 | if (!p) |
| 2268 | return NULL; |
| 2269 | p->kind = Assign_kind; |
| 2270 | p->v.Assign.targets = targets; |
| 2271 | p->v.Assign.value = value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2272 | p->v.Assign.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2273 | p->lineno = lineno; |
| 2274 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2275 | p->end_lineno = end_lineno; |
| 2276 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2277 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2281 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2282 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2283 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2284 | stmt_ty p; |
| 2285 | if (!target) { |
| 2286 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2287 | "field 'target' is required for AugAssign"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2288 | return NULL; |
| 2289 | } |
| 2290 | if (!op) { |
| 2291 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2292 | "field 'op' is required for AugAssign"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2293 | return NULL; |
| 2294 | } |
| 2295 | if (!value) { |
| 2296 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2297 | "field 'value' is required for AugAssign"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2298 | return NULL; |
| 2299 | } |
| 2300 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2301 | if (!p) |
| 2302 | return NULL; |
| 2303 | p->kind = AugAssign_kind; |
| 2304 | p->v.AugAssign.target = target; |
| 2305 | p->v.AugAssign.op = op; |
| 2306 | p->v.AugAssign.value = value; |
| 2307 | p->lineno = lineno; |
| 2308 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2309 | p->end_lineno = end_lineno; |
| 2310 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2311 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2315 | AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2316 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2317 | *arena) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2318 | { |
| 2319 | stmt_ty p; |
| 2320 | if (!target) { |
| 2321 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2322 | "field 'target' is required for AnnAssign"); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2323 | return NULL; |
| 2324 | } |
| 2325 | if (!annotation) { |
| 2326 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2327 | "field 'annotation' is required for AnnAssign"); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2328 | return NULL; |
| 2329 | } |
| 2330 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2331 | if (!p) |
| 2332 | return NULL; |
| 2333 | p->kind = AnnAssign_kind; |
| 2334 | p->v.AnnAssign.target = target; |
| 2335 | p->v.AnnAssign.annotation = annotation; |
| 2336 | p->v.AnnAssign.value = value; |
| 2337 | p->v.AnnAssign.simple = simple; |
| 2338 | p->lineno = lineno; |
| 2339 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2340 | p->end_lineno = end_lineno; |
| 2341 | p->end_col_offset = end_col_offset; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2342 | return p; |
| 2343 | } |
| 2344 | |
| 2345 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2346 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string |
| 2347 | type_comment, int lineno, int col_offset, int end_lineno, int |
| 2348 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2349 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2350 | stmt_ty p; |
| 2351 | if (!target) { |
| 2352 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2353 | "field 'target' is required for For"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2354 | return NULL; |
| 2355 | } |
| 2356 | if (!iter) { |
| 2357 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2358 | "field 'iter' is required for For"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2359 | return NULL; |
| 2360 | } |
| 2361 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2362 | if (!p) |
| 2363 | return NULL; |
| 2364 | p->kind = For_kind; |
| 2365 | p->v.For.target = target; |
| 2366 | p->v.For.iter = iter; |
| 2367 | p->v.For.body = body; |
| 2368 | p->v.For.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2369 | p->v.For.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2370 | p->lineno = lineno; |
| 2371 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2372 | p->end_lineno = end_lineno; |
| 2373 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2374 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2378 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, |
| 2379 | string type_comment, int lineno, int col_offset, int end_lineno, int |
| 2380 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2381 | { |
| 2382 | stmt_ty p; |
| 2383 | if (!target) { |
| 2384 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2385 | "field 'target' is required for AsyncFor"); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2386 | return NULL; |
| 2387 | } |
| 2388 | if (!iter) { |
| 2389 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2390 | "field 'iter' is required for AsyncFor"); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2391 | return NULL; |
| 2392 | } |
| 2393 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2394 | if (!p) |
| 2395 | return NULL; |
| 2396 | p->kind = AsyncFor_kind; |
| 2397 | p->v.AsyncFor.target = target; |
| 2398 | p->v.AsyncFor.iter = iter; |
| 2399 | p->v.AsyncFor.body = body; |
| 2400 | p->v.AsyncFor.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2401 | p->v.AsyncFor.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2402 | p->lineno = lineno; |
| 2403 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2404 | p->end_lineno = end_lineno; |
| 2405 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2406 | return p; |
| 2407 | } |
| 2408 | |
| 2409 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2410 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2411 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2412 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2413 | stmt_ty p; |
| 2414 | if (!test) { |
| 2415 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2416 | "field 'test' is required for While"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2417 | return NULL; |
| 2418 | } |
| 2419 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2420 | if (!p) |
| 2421 | return NULL; |
| 2422 | p->kind = While_kind; |
| 2423 | p->v.While.test = test; |
| 2424 | p->v.While.body = body; |
| 2425 | p->v.While.orelse = orelse; |
| 2426 | p->lineno = lineno; |
| 2427 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2428 | p->end_lineno = end_lineno; |
| 2429 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2430 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2434 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2435 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2436 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2437 | stmt_ty p; |
| 2438 | if (!test) { |
| 2439 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2440 | "field 'test' is required for If"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2441 | return NULL; |
| 2442 | } |
| 2443 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2444 | if (!p) |
| 2445 | return NULL; |
| 2446 | p->kind = If_kind; |
| 2447 | p->v.If.test = test; |
| 2448 | p->v.If.body = body; |
| 2449 | p->v.If.orelse = orelse; |
| 2450 | p->lineno = lineno; |
| 2451 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2452 | p->end_lineno = end_lineno; |
| 2453 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2454 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2458 | With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int |
| 2459 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2460 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2461 | stmt_ty p; |
| 2462 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2463 | if (!p) |
| 2464 | return NULL; |
| 2465 | p->kind = With_kind; |
| 2466 | p->v.With.items = items; |
| 2467 | p->v.With.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2468 | p->v.With.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2469 | p->lineno = lineno; |
| 2470 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2471 | p->end_lineno = end_lineno; |
| 2472 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2473 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2474 | } |
| 2475 | |
| 2476 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2477 | AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, |
| 2478 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2479 | { |
| 2480 | stmt_ty p; |
| 2481 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2482 | if (!p) |
| 2483 | return NULL; |
| 2484 | p->kind = AsyncWith_kind; |
| 2485 | p->v.AsyncWith.items = items; |
| 2486 | p->v.AsyncWith.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2487 | p->v.AsyncWith.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2488 | p->lineno = lineno; |
| 2489 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2490 | p->end_lineno = end_lineno; |
| 2491 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2492 | return p; |
| 2493 | } |
| 2494 | |
| 2495 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2496 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, |
| 2497 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2498 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2499 | stmt_ty p; |
| 2500 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2501 | if (!p) |
| 2502 | return NULL; |
| 2503 | p->kind = Raise_kind; |
| 2504 | p->v.Raise.exc = exc; |
| 2505 | p->v.Raise.cause = cause; |
| 2506 | p->lineno = lineno; |
| 2507 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2508 | p->end_lineno = end_lineno; |
| 2509 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2510 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2514 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2515 | finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2516 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2517 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2518 | stmt_ty p; |
| 2519 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2520 | if (!p) |
| 2521 | return NULL; |
| 2522 | p->kind = Try_kind; |
| 2523 | p->v.Try.body = body; |
| 2524 | p->v.Try.handlers = handlers; |
| 2525 | p->v.Try.orelse = orelse; |
| 2526 | p->v.Try.finalbody = finalbody; |
| 2527 | p->lineno = lineno; |
| 2528 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2529 | p->end_lineno = end_lineno; |
| 2530 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2531 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2535 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, |
| 2536 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2537 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2538 | stmt_ty p; |
| 2539 | if (!test) { |
| 2540 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2541 | "field 'test' is required for Assert"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2542 | return NULL; |
| 2543 | } |
| 2544 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2545 | if (!p) |
| 2546 | return NULL; |
| 2547 | p->kind = Assert_kind; |
| 2548 | p->v.Assert.test = test; |
| 2549 | p->v.Assert.msg = msg; |
| 2550 | p->lineno = lineno; |
| 2551 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2552 | p->end_lineno = end_lineno; |
| 2553 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2554 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2558 | Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2559 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2560 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2561 | stmt_ty p; |
| 2562 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2563 | if (!p) |
| 2564 | return NULL; |
| 2565 | p->kind = Import_kind; |
| 2566 | p->v.Import.names = names; |
| 2567 | p->lineno = lineno; |
| 2568 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2569 | p->end_lineno = end_lineno; |
| 2570 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2571 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2575 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2576 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2577 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2578 | stmt_ty p; |
| 2579 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2580 | if (!p) |
| 2581 | return NULL; |
| 2582 | p->kind = ImportFrom_kind; |
| 2583 | p->v.ImportFrom.module = module; |
| 2584 | p->v.ImportFrom.names = names; |
| 2585 | p->v.ImportFrom.level = level; |
| 2586 | p->lineno = lineno; |
| 2587 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2588 | p->end_lineno = end_lineno; |
| 2589 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2590 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2591 | } |
| 2592 | |
| 2593 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2594 | Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2595 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2596 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2597 | stmt_ty p; |
| 2598 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2599 | if (!p) |
| 2600 | return NULL; |
| 2601 | p->kind = Global_kind; |
| 2602 | p->v.Global.names = names; |
| 2603 | p->lineno = lineno; |
| 2604 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2605 | p->end_lineno = end_lineno; |
| 2606 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2607 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2611 | Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2612 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2613 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2614 | stmt_ty p; |
| 2615 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2616 | if (!p) |
| 2617 | return NULL; |
| 2618 | p->kind = Nonlocal_kind; |
| 2619 | p->v.Nonlocal.names = names; |
| 2620 | p->lineno = lineno; |
| 2621 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2622 | p->end_lineno = end_lineno; |
| 2623 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2624 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2628 | Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2629 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2630 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2631 | stmt_ty p; |
| 2632 | if (!value) { |
| 2633 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2634 | "field 'value' is required for Expr"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2635 | return NULL; |
| 2636 | } |
| 2637 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2638 | if (!p) |
| 2639 | return NULL; |
| 2640 | p->kind = Expr_kind; |
| 2641 | p->v.Expr.value = value; |
| 2642 | p->lineno = lineno; |
| 2643 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2644 | p->end_lineno = end_lineno; |
| 2645 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2646 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2647 | } |
| 2648 | |
| 2649 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2650 | Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2651 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2652 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2653 | stmt_ty p; |
| 2654 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2655 | if (!p) |
| 2656 | return NULL; |
| 2657 | p->kind = Pass_kind; |
| 2658 | p->lineno = lineno; |
| 2659 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2660 | p->end_lineno = end_lineno; |
| 2661 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2662 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2663 | } |
| 2664 | |
| 2665 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2666 | Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2667 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2668 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2669 | stmt_ty p; |
| 2670 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2671 | if (!p) |
| 2672 | return NULL; |
| 2673 | p->kind = Break_kind; |
| 2674 | p->lineno = lineno; |
| 2675 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2676 | p->end_lineno = end_lineno; |
| 2677 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2678 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2679 | } |
| 2680 | |
| 2681 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2682 | Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2683 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2684 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2685 | stmt_ty p; |
| 2686 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2687 | if (!p) |
| 2688 | return NULL; |
| 2689 | p->kind = Continue_kind; |
| 2690 | p->lineno = lineno; |
| 2691 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2692 | p->end_lineno = end_lineno; |
| 2693 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2694 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2698 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int |
| 2699 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2700 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2701 | expr_ty p; |
| 2702 | if (!op) { |
| 2703 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2704 | "field 'op' is required for BoolOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2705 | return NULL; |
| 2706 | } |
| 2707 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2708 | if (!p) |
| 2709 | return NULL; |
| 2710 | p->kind = BoolOp_kind; |
| 2711 | p->v.BoolOp.op = op; |
| 2712 | p->v.BoolOp.values = values; |
| 2713 | p->lineno = lineno; |
| 2714 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2715 | p->end_lineno = end_lineno; |
| 2716 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2717 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | expr_ty |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2721 | NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int |
| 2722 | end_lineno, int end_col_offset, PyArena *arena) |
| 2723 | { |
| 2724 | expr_ty p; |
| 2725 | if (!target) { |
| 2726 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2727 | "field 'target' is required for NamedExpr"); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2728 | return NULL; |
| 2729 | } |
| 2730 | if (!value) { |
| 2731 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2732 | "field 'value' is required for NamedExpr"); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2733 | return NULL; |
| 2734 | } |
| 2735 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2736 | if (!p) |
| 2737 | return NULL; |
| 2738 | p->kind = NamedExpr_kind; |
| 2739 | p->v.NamedExpr.target = target; |
| 2740 | p->v.NamedExpr.value = value; |
| 2741 | p->lineno = lineno; |
| 2742 | p->col_offset = col_offset; |
| 2743 | p->end_lineno = end_lineno; |
| 2744 | p->end_col_offset = end_col_offset; |
| 2745 | return p; |
| 2746 | } |
| 2747 | |
| 2748 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2749 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2750 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2751 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2752 | expr_ty p; |
| 2753 | if (!left) { |
| 2754 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2755 | "field 'left' is required for BinOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2756 | return NULL; |
| 2757 | } |
| 2758 | if (!op) { |
| 2759 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2760 | "field 'op' is required for BinOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2761 | return NULL; |
| 2762 | } |
| 2763 | if (!right) { |
| 2764 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2765 | "field 'right' is required for BinOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2766 | return NULL; |
| 2767 | } |
| 2768 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2769 | if (!p) |
| 2770 | return NULL; |
| 2771 | p->kind = BinOp_kind; |
| 2772 | p->v.BinOp.left = left; |
| 2773 | p->v.BinOp.op = op; |
| 2774 | p->v.BinOp.right = right; |
| 2775 | p->lineno = lineno; |
| 2776 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2777 | p->end_lineno = end_lineno; |
| 2778 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2779 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2780 | } |
| 2781 | |
| 2782 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2783 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int |
| 2784 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2785 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2786 | expr_ty p; |
| 2787 | if (!op) { |
| 2788 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2789 | "field 'op' is required for UnaryOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2790 | return NULL; |
| 2791 | } |
| 2792 | if (!operand) { |
| 2793 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2794 | "field 'operand' is required for UnaryOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2795 | return NULL; |
| 2796 | } |
| 2797 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2798 | if (!p) |
| 2799 | return NULL; |
| 2800 | p->kind = UnaryOp_kind; |
| 2801 | p->v.UnaryOp.op = op; |
| 2802 | p->v.UnaryOp.operand = operand; |
| 2803 | p->lineno = lineno; |
| 2804 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2805 | p->end_lineno = end_lineno; |
| 2806 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2807 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2808 | } |
| 2809 | |
| 2810 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2811 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int |
| 2812 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2813 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2814 | expr_ty p; |
| 2815 | if (!args) { |
| 2816 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2817 | "field 'args' is required for Lambda"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2818 | return NULL; |
| 2819 | } |
| 2820 | if (!body) { |
| 2821 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2822 | "field 'body' is required for Lambda"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2823 | return NULL; |
| 2824 | } |
| 2825 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2826 | if (!p) |
| 2827 | return NULL; |
| 2828 | p->kind = Lambda_kind; |
| 2829 | p->v.Lambda.args = args; |
| 2830 | p->v.Lambda.body = body; |
| 2831 | p->lineno = lineno; |
| 2832 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2833 | p->end_lineno = end_lineno; |
| 2834 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2835 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2839 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2840 | int end_lineno, int end_col_offset, PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2841 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2842 | expr_ty p; |
| 2843 | if (!test) { |
| 2844 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2845 | "field 'test' is required for IfExp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2846 | return NULL; |
| 2847 | } |
| 2848 | if (!body) { |
| 2849 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2850 | "field 'body' is required for IfExp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2851 | return NULL; |
| 2852 | } |
| 2853 | if (!orelse) { |
| 2854 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2855 | "field 'orelse' is required for IfExp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2856 | return NULL; |
| 2857 | } |
| 2858 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2859 | if (!p) |
| 2860 | return NULL; |
| 2861 | p->kind = IfExp_kind; |
| 2862 | p->v.IfExp.test = test; |
| 2863 | p->v.IfExp.body = body; |
| 2864 | p->v.IfExp.orelse = orelse; |
| 2865 | p->lineno = lineno; |
| 2866 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2867 | p->end_lineno = end_lineno; |
| 2868 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2869 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2870 | } |
| 2871 | |
| 2872 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2873 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int |
| 2874 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2875 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2876 | expr_ty p; |
| 2877 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2878 | if (!p) |
| 2879 | return NULL; |
| 2880 | p->kind = Dict_kind; |
| 2881 | p->v.Dict.keys = keys; |
| 2882 | p->v.Dict.values = values; |
| 2883 | p->lineno = lineno; |
| 2884 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2885 | p->end_lineno = end_lineno; |
| 2886 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2887 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2891 | Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int |
| 2892 | end_col_offset, PyArena *arena) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2893 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2894 | expr_ty p; |
| 2895 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2896 | if (!p) |
| 2897 | return NULL; |
| 2898 | p->kind = Set_kind; |
| 2899 | p->v.Set.elts = elts; |
| 2900 | p->lineno = lineno; |
| 2901 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2902 | p->end_lineno = end_lineno; |
| 2903 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2904 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2908 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2909 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2910 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2911 | expr_ty p; |
| 2912 | if (!elt) { |
| 2913 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2914 | "field 'elt' is required for ListComp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2915 | return NULL; |
| 2916 | } |
| 2917 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2918 | if (!p) |
| 2919 | return NULL; |
| 2920 | p->kind = ListComp_kind; |
| 2921 | p->v.ListComp.elt = elt; |
| 2922 | p->v.ListComp.generators = generators; |
| 2923 | p->lineno = lineno; |
| 2924 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2925 | p->end_lineno = end_lineno; |
| 2926 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2927 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2928 | } |
| 2929 | |
| 2930 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2931 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2932 | end_lineno, int end_col_offset, PyArena *arena) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2933 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2934 | expr_ty p; |
| 2935 | if (!elt) { |
| 2936 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2937 | "field 'elt' is required for SetComp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2938 | return NULL; |
| 2939 | } |
| 2940 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2941 | if (!p) |
| 2942 | return NULL; |
| 2943 | p->kind = SetComp_kind; |
| 2944 | p->v.SetComp.elt = elt; |
| 2945 | p->v.SetComp.generators = generators; |
| 2946 | p->lineno = lineno; |
| 2947 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2948 | p->end_lineno = end_lineno; |
| 2949 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2950 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2951 | } |
| 2952 | |
| 2953 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2954 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2955 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2956 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2957 | expr_ty p; |
| 2958 | if (!key) { |
| 2959 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2960 | "field 'key' is required for DictComp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2961 | return NULL; |
| 2962 | } |
| 2963 | if (!value) { |
| 2964 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2965 | "field 'value' is required for DictComp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2966 | return NULL; |
| 2967 | } |
| 2968 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2969 | if (!p) |
| 2970 | return NULL; |
| 2971 | p->kind = DictComp_kind; |
| 2972 | p->v.DictComp.key = key; |
| 2973 | p->v.DictComp.value = value; |
| 2974 | p->v.DictComp.generators = generators; |
| 2975 | p->lineno = lineno; |
| 2976 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2977 | p->end_lineno = end_lineno; |
| 2978 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2979 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2980 | } |
| 2981 | |
| 2982 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2983 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2984 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2985 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2986 | expr_ty p; |
| 2987 | if (!elt) { |
| 2988 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2989 | "field 'elt' is required for GeneratorExp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2990 | return NULL; |
| 2991 | } |
| 2992 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2993 | if (!p) |
| 2994 | return NULL; |
| 2995 | p->kind = GeneratorExp_kind; |
| 2996 | p->v.GeneratorExp.elt = elt; |
| 2997 | p->v.GeneratorExp.generators = generators; |
| 2998 | p->lineno = lineno; |
| 2999 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3000 | p->end_lineno = end_lineno; |
| 3001 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3002 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3003 | } |
| 3004 | |
| 3005 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3006 | Await(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 3007 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3008 | { |
| 3009 | expr_ty p; |
| 3010 | if (!value) { |
| 3011 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3012 | "field 'value' is required for Await"); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3013 | return NULL; |
| 3014 | } |
| 3015 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3016 | if (!p) |
| 3017 | return NULL; |
| 3018 | p->kind = Await_kind; |
| 3019 | p->v.Await.value = value; |
| 3020 | p->lineno = lineno; |
| 3021 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3022 | p->end_lineno = end_lineno; |
| 3023 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3024 | return p; |
| 3025 | } |
| 3026 | |
| 3027 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3028 | Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 3029 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3030 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3031 | expr_ty p; |
| 3032 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3033 | if (!p) |
| 3034 | return NULL; |
| 3035 | p->kind = Yield_kind; |
| 3036 | p->v.Yield.value = value; |
| 3037 | p->lineno = lineno; |
| 3038 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3039 | p->end_lineno = end_lineno; |
| 3040 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3041 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3042 | } |
| 3043 | |
| 3044 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3045 | YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 3046 | end_col_offset, PyArena *arena) |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 3047 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3048 | expr_ty p; |
| 3049 | if (!value) { |
| 3050 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3051 | "field 'value' is required for YieldFrom"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3052 | return NULL; |
| 3053 | } |
| 3054 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3055 | if (!p) |
| 3056 | return NULL; |
| 3057 | p->kind = YieldFrom_kind; |
| 3058 | p->v.YieldFrom.value = value; |
| 3059 | p->lineno = lineno; |
| 3060 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3061 | p->end_lineno = end_lineno; |
| 3062 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3063 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 3064 | } |
| 3065 | |
| 3066 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3067 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3068 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3069 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3070 | expr_ty p; |
| 3071 | if (!left) { |
| 3072 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3073 | "field 'left' is required for Compare"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3074 | return NULL; |
| 3075 | } |
| 3076 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3077 | if (!p) |
| 3078 | return NULL; |
| 3079 | p->kind = Compare_kind; |
| 3080 | p->v.Compare.left = left; |
| 3081 | p->v.Compare.ops = ops; |
| 3082 | p->v.Compare.comparators = comparators; |
| 3083 | p->lineno = lineno; |
| 3084 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3085 | p->end_lineno = end_lineno; |
| 3086 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3087 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3088 | } |
| 3089 | |
| 3090 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 3091 | Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3092 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3093 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3094 | expr_ty p; |
| 3095 | if (!func) { |
| 3096 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3097 | "field 'func' is required for Call"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3098 | return NULL; |
| 3099 | } |
| 3100 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3101 | if (!p) |
| 3102 | return NULL; |
| 3103 | p->kind = Call_kind; |
| 3104 | p->v.Call.func = func; |
| 3105 | p->v.Call.args = args; |
| 3106 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3107 | p->lineno = lineno; |
| 3108 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3109 | p->end_lineno = end_lineno; |
| 3110 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3111 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3112 | } |
| 3113 | |
| 3114 | expr_ty |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 3115 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
| 3116 | int col_offset, int end_lineno, int end_col_offset, PyArena |
| 3117 | *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3118 | { |
| 3119 | expr_ty p; |
| 3120 | if (!value) { |
| 3121 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3122 | "field 'value' is required for FormattedValue"); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3123 | return NULL; |
| 3124 | } |
| 3125 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3126 | if (!p) |
| 3127 | return NULL; |
| 3128 | p->kind = FormattedValue_kind; |
| 3129 | p->v.FormattedValue.value = value; |
| 3130 | p->v.FormattedValue.conversion = conversion; |
| 3131 | p->v.FormattedValue.format_spec = format_spec; |
| 3132 | p->lineno = lineno; |
| 3133 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3134 | p->end_lineno = end_lineno; |
| 3135 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3136 | return p; |
| 3137 | } |
| 3138 | |
| 3139 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3140 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 3141 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3142 | { |
| 3143 | expr_ty p; |
| 3144 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3145 | if (!p) |
| 3146 | return NULL; |
| 3147 | p->kind = JoinedStr_kind; |
| 3148 | p->v.JoinedStr.values = values; |
| 3149 | p->lineno = lineno; |
| 3150 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3151 | p->end_lineno = end_lineno; |
| 3152 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3153 | return p; |
| 3154 | } |
| 3155 | |
| 3156 | expr_ty |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 3157 | Constant(constant value, string kind, int lineno, int col_offset, int |
| 3158 | end_lineno, int end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3159 | { |
| 3160 | expr_ty p; |
| 3161 | if (!value) { |
| 3162 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3163 | "field 'value' is required for Constant"); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3164 | return NULL; |
| 3165 | } |
| 3166 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3167 | if (!p) |
| 3168 | return NULL; |
| 3169 | p->kind = Constant_kind; |
| 3170 | p->v.Constant.value = value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 3171 | p->v.Constant.kind = kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3172 | p->lineno = lineno; |
| 3173 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3174 | p->end_lineno = end_lineno; |
| 3175 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3176 | return p; |
| 3177 | } |
| 3178 | |
| 3179 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3180 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3181 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3182 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3183 | expr_ty p; |
| 3184 | if (!value) { |
| 3185 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3186 | "field 'value' is required for Attribute"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3187 | return NULL; |
| 3188 | } |
| 3189 | if (!attr) { |
| 3190 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3191 | "field 'attr' is required for Attribute"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3192 | return NULL; |
| 3193 | } |
| 3194 | if (!ctx) { |
| 3195 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3196 | "field 'ctx' is required for Attribute"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3197 | return NULL; |
| 3198 | } |
| 3199 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3200 | if (!p) |
| 3201 | return NULL; |
| 3202 | p->kind = Attribute_kind; |
| 3203 | p->v.Attribute.value = value; |
| 3204 | p->v.Attribute.attr = attr; |
| 3205 | p->v.Attribute.ctx = ctx; |
| 3206 | p->lineno = lineno; |
| 3207 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3208 | p->end_lineno = end_lineno; |
| 3209 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3210 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3211 | } |
| 3212 | |
| 3213 | expr_ty |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3214 | Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3215 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3216 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3217 | expr_ty p; |
| 3218 | if (!value) { |
| 3219 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3220 | "field 'value' is required for Subscript"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3221 | return NULL; |
| 3222 | } |
| 3223 | if (!slice) { |
| 3224 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3225 | "field 'slice' is required for Subscript"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3226 | return NULL; |
| 3227 | } |
| 3228 | if (!ctx) { |
| 3229 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3230 | "field 'ctx' is required for Subscript"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3231 | return NULL; |
| 3232 | } |
| 3233 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3234 | if (!p) |
| 3235 | return NULL; |
| 3236 | p->kind = Subscript_kind; |
| 3237 | p->v.Subscript.value = value; |
| 3238 | p->v.Subscript.slice = slice; |
| 3239 | p->v.Subscript.ctx = ctx; |
| 3240 | p->lineno = lineno; |
| 3241 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3242 | p->end_lineno = end_lineno; |
| 3243 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3244 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3245 | } |
| 3246 | |
| 3247 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3248 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 3249 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3250 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3251 | expr_ty p; |
| 3252 | if (!value) { |
| 3253 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3254 | "field 'value' is required for Starred"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3255 | return NULL; |
| 3256 | } |
| 3257 | if (!ctx) { |
| 3258 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3259 | "field 'ctx' is required for Starred"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3260 | return NULL; |
| 3261 | } |
| 3262 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3263 | if (!p) |
| 3264 | return NULL; |
| 3265 | p->kind = Starred_kind; |
| 3266 | p->v.Starred.value = value; |
| 3267 | p->v.Starred.ctx = ctx; |
| 3268 | p->lineno = lineno; |
| 3269 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3270 | p->end_lineno = end_lineno; |
| 3271 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3272 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3273 | } |
| 3274 | |
| 3275 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3276 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 3277 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3278 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3279 | expr_ty p; |
| 3280 | if (!id) { |
| 3281 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3282 | "field 'id' is required for Name"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3283 | return NULL; |
| 3284 | } |
| 3285 | if (!ctx) { |
| 3286 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3287 | "field 'ctx' is required for Name"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3288 | return NULL; |
| 3289 | } |
| 3290 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3291 | if (!p) |
| 3292 | return NULL; |
| 3293 | p->kind = Name_kind; |
| 3294 | p->v.Name.id = id; |
| 3295 | p->v.Name.ctx = ctx; |
| 3296 | p->lineno = lineno; |
| 3297 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3298 | p->end_lineno = end_lineno; |
| 3299 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3300 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3301 | } |
| 3302 | |
| 3303 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3304 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3305 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3306 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3307 | expr_ty p; |
| 3308 | if (!ctx) { |
| 3309 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3310 | "field 'ctx' is required for List"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3311 | return NULL; |
| 3312 | } |
| 3313 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3314 | if (!p) |
| 3315 | return NULL; |
| 3316 | p->kind = List_kind; |
| 3317 | p->v.List.elts = elts; |
| 3318 | p->v.List.ctx = ctx; |
| 3319 | p->lineno = lineno; |
| 3320 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3321 | p->end_lineno = end_lineno; |
| 3322 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3323 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3324 | } |
| 3325 | |
| 3326 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3327 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3328 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3329 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3330 | expr_ty p; |
| 3331 | if (!ctx) { |
| 3332 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3333 | "field 'ctx' is required for Tuple"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3334 | return NULL; |
| 3335 | } |
| 3336 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3337 | if (!p) |
| 3338 | return NULL; |
| 3339 | p->kind = Tuple_kind; |
| 3340 | p->v.Tuple.elts = elts; |
| 3341 | p->v.Tuple.ctx = ctx; |
| 3342 | p->lineno = lineno; |
| 3343 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3344 | p->end_lineno = end_lineno; |
| 3345 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3346 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3347 | } |
| 3348 | |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3349 | expr_ty |
| 3350 | Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int col_offset, |
| 3351 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3352 | { |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3353 | expr_ty p; |
| 3354 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3355 | if (!p) |
| 3356 | return NULL; |
| 3357 | p->kind = Slice_kind; |
| 3358 | p->v.Slice.lower = lower; |
| 3359 | p->v.Slice.upper = upper; |
| 3360 | p->v.Slice.step = step; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3361 | p->lineno = lineno; |
| 3362 | p->col_offset = col_offset; |
| 3363 | p->end_lineno = end_lineno; |
| 3364 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3365 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3366 | } |
| 3367 | |
| 3368 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3369 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 3370 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3371 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3372 | comprehension_ty p; |
| 3373 | if (!target) { |
| 3374 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3375 | "field 'target' is required for comprehension"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3376 | return NULL; |
| 3377 | } |
| 3378 | if (!iter) { |
| 3379 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3380 | "field 'iter' is required for comprehension"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3381 | return NULL; |
| 3382 | } |
| 3383 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3384 | if (!p) |
| 3385 | return NULL; |
| 3386 | p->target = target; |
| 3387 | p->iter = iter; |
| 3388 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3389 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3390 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3394 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3395 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3396 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3397 | excepthandler_ty p; |
| 3398 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3399 | if (!p) |
| 3400 | return NULL; |
| 3401 | p->kind = ExceptHandler_kind; |
| 3402 | p->v.ExceptHandler.type = type; |
| 3403 | p->v.ExceptHandler.name = name; |
| 3404 | p->v.ExceptHandler.body = body; |
| 3405 | p->lineno = lineno; |
| 3406 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3407 | p->end_lineno = end_lineno; |
| 3408 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3409 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | arguments_ty |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3413 | arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq * |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3414 | kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq * |
| 3415 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3416 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3417 | arguments_ty p; |
| 3418 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3419 | if (!p) |
| 3420 | return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3421 | p->posonlyargs = posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3422 | p->args = args; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3423 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3424 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3425 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3426 | p->kwarg = kwarg; |
| 3427 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3428 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3429 | } |
| 3430 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3431 | arg_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3432 | arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int |
| 3433 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3434 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3435 | arg_ty p; |
| 3436 | if (!arg) { |
| 3437 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3438 | "field 'arg' is required for arg"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3439 | return NULL; |
| 3440 | } |
| 3441 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3442 | if (!p) |
| 3443 | return NULL; |
| 3444 | p->arg = arg; |
| 3445 | p->annotation = annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3446 | p->type_comment = type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 3447 | p->lineno = lineno; |
| 3448 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3449 | p->end_lineno = end_lineno; |
| 3450 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3451 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3452 | } |
| 3453 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3454 | keyword_ty |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 3455 | keyword(identifier arg, expr_ty value, int lineno, int col_offset, int |
| 3456 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3457 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3458 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3459 | if (!value) { |
| 3460 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3461 | "field 'value' is required for keyword"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3462 | return NULL; |
| 3463 | } |
| 3464 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3465 | if (!p) |
| 3466 | return NULL; |
| 3467 | p->arg = arg; |
| 3468 | p->value = value; |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 3469 | p->lineno = lineno; |
| 3470 | p->col_offset = col_offset; |
| 3471 | p->end_lineno = end_lineno; |
| 3472 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3473 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3474 | } |
| 3475 | |
| 3476 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3477 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3478 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3479 | alias_ty p; |
| 3480 | if (!name) { |
| 3481 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3482 | "field 'name' is required for alias"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3483 | return NULL; |
| 3484 | } |
| 3485 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3486 | if (!p) |
| 3487 | return NULL; |
| 3488 | p->name = name; |
| 3489 | p->asname = asname; |
| 3490 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3491 | } |
| 3492 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3493 | withitem_ty |
| 3494 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 3495 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3496 | withitem_ty p; |
| 3497 | if (!context_expr) { |
| 3498 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3499 | "field 'context_expr' is required for withitem"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3500 | return NULL; |
| 3501 | } |
| 3502 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3503 | if (!p) |
| 3504 | return NULL; |
| 3505 | p->context_expr = context_expr; |
| 3506 | p->optional_vars = optional_vars; |
| 3507 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3508 | } |
| 3509 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3510 | type_ignore_ty |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3511 | TypeIgnore(int lineno, string tag, PyArena *arena) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3512 | { |
| 3513 | type_ignore_ty p; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3514 | if (!tag) { |
| 3515 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3516 | "field 'tag' is required for TypeIgnore"); |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3517 | return NULL; |
| 3518 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3519 | p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3520 | if (!p) |
| 3521 | return NULL; |
| 3522 | p->kind = TypeIgnore_kind; |
| 3523 | p->v.TypeIgnore.lineno = lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3524 | p->v.TypeIgnore.tag = tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3525 | return p; |
| 3526 | } |
| 3527 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3528 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3529 | PyObject* |
| 3530 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3531 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3532 | mod_ty o = (mod_ty)_o; |
| 3533 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3534 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3535 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3536 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3537 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3538 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3539 | switch (o->kind) { |
| 3540 | case Module_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3541 | tp = (PyTypeObject *)astmodulestate_global->Module_type; |
| 3542 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3543 | if (!result) goto failed; |
| 3544 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 3545 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3546 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3547 | goto failed; |
| 3548 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3549 | value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); |
| 3550 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3551 | if (PyObject_SetAttr(result, astmodulestate_global->type_ignores, |
| 3552 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3553 | goto failed; |
| 3554 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3555 | break; |
| 3556 | case Interactive_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3557 | tp = (PyTypeObject *)astmodulestate_global->Interactive_type; |
| 3558 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3559 | if (!result) goto failed; |
| 3560 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 3561 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3562 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3563 | goto failed; |
| 3564 | Py_DECREF(value); |
| 3565 | break; |
| 3566 | case Expression_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3567 | tp = (PyTypeObject *)astmodulestate_global->Expression_type; |
| 3568 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3569 | if (!result) goto failed; |
| 3570 | value = ast2obj_expr(o->v.Expression.body); |
| 3571 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3572 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3573 | goto failed; |
| 3574 | Py_DECREF(value); |
| 3575 | break; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3576 | case FunctionType_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3577 | tp = (PyTypeObject *)astmodulestate_global->FunctionType_type; |
| 3578 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3579 | if (!result) goto failed; |
| 3580 | value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); |
| 3581 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3582 | if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) == |
| 3583 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3584 | goto failed; |
| 3585 | Py_DECREF(value); |
| 3586 | value = ast2obj_expr(o->v.FunctionType.returns); |
| 3587 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3588 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3589 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3590 | goto failed; |
| 3591 | Py_DECREF(value); |
| 3592 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3593 | } |
| 3594 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3595 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3596 | Py_XDECREF(value); |
| 3597 | Py_XDECREF(result); |
| 3598 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3599 | } |
| 3600 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3601 | PyObject* |
| 3602 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3603 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3604 | stmt_ty o = (stmt_ty)_o; |
| 3605 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3606 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3607 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3608 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3609 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3610 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3611 | switch (o->kind) { |
| 3612 | case FunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3613 | tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type; |
| 3614 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3615 | if (!result) goto failed; |
| 3616 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3617 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3618 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3619 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3620 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3621 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3622 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3623 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3624 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3625 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3626 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 3627 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3628 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3629 | goto failed; |
| 3630 | Py_DECREF(value); |
| 3631 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 3632 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3633 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3634 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3635 | goto failed; |
| 3636 | Py_DECREF(value); |
| 3637 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 3638 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3639 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3640 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3641 | goto failed; |
| 3642 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3643 | value = ast2obj_string(o->v.FunctionDef.type_comment); |
| 3644 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3645 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3646 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3647 | goto failed; |
| 3648 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3649 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3650 | case AsyncFunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3651 | tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type; |
| 3652 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3653 | if (!result) goto failed; |
| 3654 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 3655 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3656 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3657 | goto failed; |
| 3658 | Py_DECREF(value); |
| 3659 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 3660 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3661 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3662 | goto failed; |
| 3663 | Py_DECREF(value); |
| 3664 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 3665 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3666 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3667 | goto failed; |
| 3668 | Py_DECREF(value); |
| 3669 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 3670 | ast2obj_expr); |
| 3671 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3672 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3673 | value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3674 | goto failed; |
| 3675 | Py_DECREF(value); |
| 3676 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 3677 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3678 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3679 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3680 | goto failed; |
| 3681 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3682 | value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); |
| 3683 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3684 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3685 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3686 | goto failed; |
| 3687 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3688 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3689 | case ClassDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3690 | tp = (PyTypeObject *)astmodulestate_global->ClassDef_type; |
| 3691 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3692 | if (!result) goto failed; |
| 3693 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 3694 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3695 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3696 | goto failed; |
| 3697 | Py_DECREF(value); |
| 3698 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 3699 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3700 | if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3701 | goto failed; |
| 3702 | Py_DECREF(value); |
| 3703 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 3704 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3705 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 3706 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3707 | goto failed; |
| 3708 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3709 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 3710 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3711 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3712 | goto failed; |
| 3713 | Py_DECREF(value); |
| 3714 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 3715 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3716 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3717 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3718 | goto failed; |
| 3719 | Py_DECREF(value); |
| 3720 | break; |
| 3721 | case Return_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3722 | tp = (PyTypeObject *)astmodulestate_global->Return_type; |
| 3723 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3724 | if (!result) goto failed; |
| 3725 | value = ast2obj_expr(o->v.Return.value); |
| 3726 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3727 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3728 | goto failed; |
| 3729 | Py_DECREF(value); |
| 3730 | break; |
| 3731 | case Delete_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3732 | tp = (PyTypeObject *)astmodulestate_global->Delete_type; |
| 3733 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3734 | if (!result) goto failed; |
| 3735 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 3736 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3737 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3738 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3739 | goto failed; |
| 3740 | Py_DECREF(value); |
| 3741 | break; |
| 3742 | case Assign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3743 | tp = (PyTypeObject *)astmodulestate_global->Assign_type; |
| 3744 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3745 | if (!result) goto failed; |
| 3746 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 3747 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3748 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3749 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3750 | goto failed; |
| 3751 | Py_DECREF(value); |
| 3752 | value = ast2obj_expr(o->v.Assign.value); |
| 3753 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3754 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3755 | goto failed; |
| 3756 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3757 | value = ast2obj_string(o->v.Assign.type_comment); |
| 3758 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3759 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3760 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3761 | goto failed; |
| 3762 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3763 | break; |
| 3764 | case AugAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3765 | tp = (PyTypeObject *)astmodulestate_global->AugAssign_type; |
| 3766 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3767 | if (!result) goto failed; |
| 3768 | value = ast2obj_expr(o->v.AugAssign.target); |
| 3769 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3770 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3771 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3772 | goto failed; |
| 3773 | Py_DECREF(value); |
| 3774 | value = ast2obj_operator(o->v.AugAssign.op); |
| 3775 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3776 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3777 | goto failed; |
| 3778 | Py_DECREF(value); |
| 3779 | value = ast2obj_expr(o->v.AugAssign.value); |
| 3780 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3781 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3782 | goto failed; |
| 3783 | Py_DECREF(value); |
| 3784 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3785 | case AnnAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3786 | tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type; |
| 3787 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3788 | if (!result) goto failed; |
| 3789 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 3790 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3791 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3792 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3793 | goto failed; |
| 3794 | Py_DECREF(value); |
| 3795 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 3796 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3797 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) |
| 3798 | == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3799 | goto failed; |
| 3800 | Py_DECREF(value); |
| 3801 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 3802 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3803 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3804 | goto failed; |
| 3805 | Py_DECREF(value); |
| 3806 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 3807 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3808 | if (PyObject_SetAttr(result, astmodulestate_global->simple, value) == |
| 3809 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3810 | goto failed; |
| 3811 | Py_DECREF(value); |
| 3812 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3813 | case For_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3814 | tp = (PyTypeObject *)astmodulestate_global->For_type; |
| 3815 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3816 | if (!result) goto failed; |
| 3817 | value = ast2obj_expr(o->v.For.target); |
| 3818 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3819 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3820 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3821 | goto failed; |
| 3822 | Py_DECREF(value); |
| 3823 | value = ast2obj_expr(o->v.For.iter); |
| 3824 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3825 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3826 | goto failed; |
| 3827 | Py_DECREF(value); |
| 3828 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 3829 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3830 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3831 | goto failed; |
| 3832 | Py_DECREF(value); |
| 3833 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 3834 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3835 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3836 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3837 | goto failed; |
| 3838 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3839 | value = ast2obj_string(o->v.For.type_comment); |
| 3840 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3841 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3842 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3843 | goto failed; |
| 3844 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3845 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3846 | case AsyncFor_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3847 | tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type; |
| 3848 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3849 | if (!result) goto failed; |
| 3850 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 3851 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3852 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3853 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3854 | goto failed; |
| 3855 | Py_DECREF(value); |
| 3856 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 3857 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3858 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3859 | goto failed; |
| 3860 | Py_DECREF(value); |
| 3861 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 3862 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3863 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3864 | goto failed; |
| 3865 | Py_DECREF(value); |
| 3866 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 3867 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3868 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3869 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3870 | goto failed; |
| 3871 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3872 | value = ast2obj_string(o->v.AsyncFor.type_comment); |
| 3873 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3874 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3875 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3876 | goto failed; |
| 3877 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3878 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3879 | case While_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3880 | tp = (PyTypeObject *)astmodulestate_global->While_type; |
| 3881 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3882 | if (!result) goto failed; |
| 3883 | value = ast2obj_expr(o->v.While.test); |
| 3884 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3885 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3886 | goto failed; |
| 3887 | Py_DECREF(value); |
| 3888 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 3889 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3890 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3891 | goto failed; |
| 3892 | Py_DECREF(value); |
| 3893 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 3894 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3895 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3896 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3897 | goto failed; |
| 3898 | Py_DECREF(value); |
| 3899 | break; |
| 3900 | case If_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3901 | tp = (PyTypeObject *)astmodulestate_global->If_type; |
| 3902 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3903 | if (!result) goto failed; |
| 3904 | value = ast2obj_expr(o->v.If.test); |
| 3905 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3906 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3907 | goto failed; |
| 3908 | Py_DECREF(value); |
| 3909 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 3910 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3911 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3912 | goto failed; |
| 3913 | Py_DECREF(value); |
| 3914 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 3915 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3916 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3917 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3918 | goto failed; |
| 3919 | Py_DECREF(value); |
| 3920 | break; |
| 3921 | case With_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3922 | tp = (PyTypeObject *)astmodulestate_global->With_type; |
| 3923 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3924 | if (!result) goto failed; |
| 3925 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 3926 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3927 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3928 | goto failed; |
| 3929 | Py_DECREF(value); |
| 3930 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 3931 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3932 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3933 | goto failed; |
| 3934 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3935 | value = ast2obj_string(o->v.With.type_comment); |
| 3936 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3937 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3938 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3939 | goto failed; |
| 3940 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3941 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3942 | case AsyncWith_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3943 | tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type; |
| 3944 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3945 | if (!result) goto failed; |
| 3946 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 3947 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3948 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3949 | goto failed; |
| 3950 | Py_DECREF(value); |
| 3951 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 3952 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3953 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3954 | goto failed; |
| 3955 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3956 | value = ast2obj_string(o->v.AsyncWith.type_comment); |
| 3957 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3958 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3959 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3960 | goto failed; |
| 3961 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3962 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3963 | case Raise_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3964 | tp = (PyTypeObject *)astmodulestate_global->Raise_type; |
| 3965 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3966 | if (!result) goto failed; |
| 3967 | value = ast2obj_expr(o->v.Raise.exc); |
| 3968 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3969 | if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3970 | goto failed; |
| 3971 | Py_DECREF(value); |
| 3972 | value = ast2obj_expr(o->v.Raise.cause); |
| 3973 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3974 | if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3975 | goto failed; |
| 3976 | Py_DECREF(value); |
| 3977 | break; |
| 3978 | case Try_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3979 | tp = (PyTypeObject *)astmodulestate_global->Try_type; |
| 3980 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3981 | if (!result) goto failed; |
| 3982 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 3983 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3984 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3985 | goto failed; |
| 3986 | Py_DECREF(value); |
| 3987 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 3988 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3989 | if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) == |
| 3990 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3991 | goto failed; |
| 3992 | Py_DECREF(value); |
| 3993 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 3994 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3995 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3996 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3997 | goto failed; |
| 3998 | Py_DECREF(value); |
| 3999 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 4000 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4001 | if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value) |
| 4002 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4003 | goto failed; |
| 4004 | Py_DECREF(value); |
| 4005 | break; |
| 4006 | case Assert_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4007 | tp = (PyTypeObject *)astmodulestate_global->Assert_type; |
| 4008 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4009 | if (!result) goto failed; |
| 4010 | value = ast2obj_expr(o->v.Assert.test); |
| 4011 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4012 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4013 | goto failed; |
| 4014 | Py_DECREF(value); |
| 4015 | value = ast2obj_expr(o->v.Assert.msg); |
| 4016 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4017 | if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4018 | goto failed; |
| 4019 | Py_DECREF(value); |
| 4020 | break; |
| 4021 | case Import_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4022 | tp = (PyTypeObject *)astmodulestate_global->Import_type; |
| 4023 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4024 | if (!result) goto failed; |
| 4025 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 4026 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4027 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4028 | goto failed; |
| 4029 | Py_DECREF(value); |
| 4030 | break; |
| 4031 | case ImportFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4032 | tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type; |
| 4033 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4034 | if (!result) goto failed; |
| 4035 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 4036 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4037 | if (PyObject_SetAttr(result, astmodulestate_global->module, value) == |
| 4038 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4039 | goto failed; |
| 4040 | Py_DECREF(value); |
| 4041 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 4042 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4043 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4044 | goto failed; |
| 4045 | Py_DECREF(value); |
| 4046 | value = ast2obj_int(o->v.ImportFrom.level); |
| 4047 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4048 | if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4049 | goto failed; |
| 4050 | Py_DECREF(value); |
| 4051 | break; |
| 4052 | case Global_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4053 | tp = (PyTypeObject *)astmodulestate_global->Global_type; |
| 4054 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4055 | if (!result) goto failed; |
| 4056 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 4057 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4058 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4059 | goto failed; |
| 4060 | Py_DECREF(value); |
| 4061 | break; |
| 4062 | case Nonlocal_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4063 | tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type; |
| 4064 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4065 | if (!result) goto failed; |
| 4066 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 4067 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4068 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4069 | goto failed; |
| 4070 | Py_DECREF(value); |
| 4071 | break; |
| 4072 | case Expr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4073 | tp = (PyTypeObject *)astmodulestate_global->Expr_type; |
| 4074 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4075 | if (!result) goto failed; |
| 4076 | value = ast2obj_expr(o->v.Expr.value); |
| 4077 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4078 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4079 | goto failed; |
| 4080 | Py_DECREF(value); |
| 4081 | break; |
| 4082 | case Pass_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4083 | tp = (PyTypeObject *)astmodulestate_global->Pass_type; |
| 4084 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4085 | if (!result) goto failed; |
| 4086 | break; |
| 4087 | case Break_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4088 | tp = (PyTypeObject *)astmodulestate_global->Break_type; |
| 4089 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4090 | if (!result) goto failed; |
| 4091 | break; |
| 4092 | case Continue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4093 | tp = (PyTypeObject *)astmodulestate_global->Continue_type; |
| 4094 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4095 | if (!result) goto failed; |
| 4096 | break; |
| 4097 | } |
| 4098 | value = ast2obj_int(o->lineno); |
| 4099 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4100 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4101 | goto failed; |
| 4102 | Py_DECREF(value); |
| 4103 | value = ast2obj_int(o->col_offset); |
| 4104 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4105 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4106 | goto failed; |
| 4107 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4108 | value = ast2obj_int(o->end_lineno); |
| 4109 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4110 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4111 | goto failed; |
| 4112 | Py_DECREF(value); |
| 4113 | value = ast2obj_int(o->end_col_offset); |
| 4114 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4115 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4116 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4117 | goto failed; |
| 4118 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4119 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4120 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4121 | Py_XDECREF(value); |
| 4122 | Py_XDECREF(result); |
| 4123 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4124 | } |
| 4125 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4126 | PyObject* |
| 4127 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4128 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4129 | expr_ty o = (expr_ty)_o; |
| 4130 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4131 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4132 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4133 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4134 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4135 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4136 | switch (o->kind) { |
| 4137 | case BoolOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4138 | tp = (PyTypeObject *)astmodulestate_global->BoolOp_type; |
| 4139 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4140 | if (!result) goto failed; |
| 4141 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 4142 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4143 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4144 | goto failed; |
| 4145 | Py_DECREF(value); |
| 4146 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 4147 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4148 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4149 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4150 | goto failed; |
| 4151 | Py_DECREF(value); |
| 4152 | break; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4153 | case NamedExpr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4154 | tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type; |
| 4155 | result = PyType_GenericNew(tp, NULL, NULL); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4156 | if (!result) goto failed; |
| 4157 | value = ast2obj_expr(o->v.NamedExpr.target); |
| 4158 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4159 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 4160 | -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4161 | goto failed; |
| 4162 | Py_DECREF(value); |
| 4163 | value = ast2obj_expr(o->v.NamedExpr.value); |
| 4164 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4165 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4166 | goto failed; |
| 4167 | Py_DECREF(value); |
| 4168 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4169 | case BinOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4170 | tp = (PyTypeObject *)astmodulestate_global->BinOp_type; |
| 4171 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4172 | if (!result) goto failed; |
| 4173 | value = ast2obj_expr(o->v.BinOp.left); |
| 4174 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4175 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4176 | goto failed; |
| 4177 | Py_DECREF(value); |
| 4178 | value = ast2obj_operator(o->v.BinOp.op); |
| 4179 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4180 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4181 | goto failed; |
| 4182 | Py_DECREF(value); |
| 4183 | value = ast2obj_expr(o->v.BinOp.right); |
| 4184 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4185 | if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4186 | goto failed; |
| 4187 | Py_DECREF(value); |
| 4188 | break; |
| 4189 | case UnaryOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4190 | tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type; |
| 4191 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4192 | if (!result) goto failed; |
| 4193 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 4194 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4195 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4196 | goto failed; |
| 4197 | Py_DECREF(value); |
| 4198 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 4199 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4200 | if (PyObject_SetAttr(result, astmodulestate_global->operand, value) == |
| 4201 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4202 | goto failed; |
| 4203 | Py_DECREF(value); |
| 4204 | break; |
| 4205 | case Lambda_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4206 | tp = (PyTypeObject *)astmodulestate_global->Lambda_type; |
| 4207 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4208 | if (!result) goto failed; |
| 4209 | value = ast2obj_arguments(o->v.Lambda.args); |
| 4210 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4211 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4212 | goto failed; |
| 4213 | Py_DECREF(value); |
| 4214 | value = ast2obj_expr(o->v.Lambda.body); |
| 4215 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4216 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4217 | goto failed; |
| 4218 | Py_DECREF(value); |
| 4219 | break; |
| 4220 | case IfExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4221 | tp = (PyTypeObject *)astmodulestate_global->IfExp_type; |
| 4222 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4223 | if (!result) goto failed; |
| 4224 | value = ast2obj_expr(o->v.IfExp.test); |
| 4225 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4226 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4227 | goto failed; |
| 4228 | Py_DECREF(value); |
| 4229 | value = ast2obj_expr(o->v.IfExp.body); |
| 4230 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4231 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4232 | goto failed; |
| 4233 | Py_DECREF(value); |
| 4234 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 4235 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4236 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 4237 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4238 | goto failed; |
| 4239 | Py_DECREF(value); |
| 4240 | break; |
| 4241 | case Dict_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4242 | tp = (PyTypeObject *)astmodulestate_global->Dict_type; |
| 4243 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4244 | if (!result) goto failed; |
| 4245 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 4246 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4247 | if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4248 | goto failed; |
| 4249 | Py_DECREF(value); |
| 4250 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 4251 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4252 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4253 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4254 | goto failed; |
| 4255 | Py_DECREF(value); |
| 4256 | break; |
| 4257 | case Set_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4258 | tp = (PyTypeObject *)astmodulestate_global->Set_type; |
| 4259 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4260 | if (!result) goto failed; |
| 4261 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 4262 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4263 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4264 | goto failed; |
| 4265 | Py_DECREF(value); |
| 4266 | break; |
| 4267 | case ListComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4268 | tp = (PyTypeObject *)astmodulestate_global->ListComp_type; |
| 4269 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4270 | if (!result) goto failed; |
| 4271 | value = ast2obj_expr(o->v.ListComp.elt); |
| 4272 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4273 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4274 | goto failed; |
| 4275 | Py_DECREF(value); |
| 4276 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 4277 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4278 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4279 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4280 | goto failed; |
| 4281 | Py_DECREF(value); |
| 4282 | break; |
| 4283 | case SetComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4284 | tp = (PyTypeObject *)astmodulestate_global->SetComp_type; |
| 4285 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4286 | if (!result) goto failed; |
| 4287 | value = ast2obj_expr(o->v.SetComp.elt); |
| 4288 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4289 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4290 | goto failed; |
| 4291 | Py_DECREF(value); |
| 4292 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 4293 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4294 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4295 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4296 | goto failed; |
| 4297 | Py_DECREF(value); |
| 4298 | break; |
| 4299 | case DictComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4300 | tp = (PyTypeObject *)astmodulestate_global->DictComp_type; |
| 4301 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4302 | if (!result) goto failed; |
| 4303 | value = ast2obj_expr(o->v.DictComp.key); |
| 4304 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4305 | if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4306 | goto failed; |
| 4307 | Py_DECREF(value); |
| 4308 | value = ast2obj_expr(o->v.DictComp.value); |
| 4309 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4310 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4311 | goto failed; |
| 4312 | Py_DECREF(value); |
| 4313 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 4314 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4315 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4316 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4317 | goto failed; |
| 4318 | Py_DECREF(value); |
| 4319 | break; |
| 4320 | case GeneratorExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4321 | tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type; |
| 4322 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4323 | if (!result) goto failed; |
| 4324 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 4325 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4326 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4327 | goto failed; |
| 4328 | Py_DECREF(value); |
| 4329 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 4330 | ast2obj_comprehension); |
| 4331 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4332 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4333 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4334 | goto failed; |
| 4335 | Py_DECREF(value); |
| 4336 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4337 | case Await_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4338 | tp = (PyTypeObject *)astmodulestate_global->Await_type; |
| 4339 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4340 | if (!result) goto failed; |
| 4341 | value = ast2obj_expr(o->v.Await.value); |
| 4342 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4343 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4344 | goto failed; |
| 4345 | Py_DECREF(value); |
| 4346 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4347 | case Yield_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4348 | tp = (PyTypeObject *)astmodulestate_global->Yield_type; |
| 4349 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4350 | if (!result) goto failed; |
| 4351 | value = ast2obj_expr(o->v.Yield.value); |
| 4352 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4353 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4354 | goto failed; |
| 4355 | Py_DECREF(value); |
| 4356 | break; |
| 4357 | case YieldFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4358 | tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type; |
| 4359 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4360 | if (!result) goto failed; |
| 4361 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 4362 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4363 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4364 | goto failed; |
| 4365 | Py_DECREF(value); |
| 4366 | break; |
| 4367 | case Compare_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4368 | tp = (PyTypeObject *)astmodulestate_global->Compare_type; |
| 4369 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4370 | if (!result) goto failed; |
| 4371 | value = ast2obj_expr(o->v.Compare.left); |
| 4372 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4373 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4374 | goto failed; |
| 4375 | Py_DECREF(value); |
| 4376 | { |
| 4377 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 4378 | value = PyList_New(n); |
| 4379 | if (!value) goto failed; |
| 4380 | for(i = 0; i < n; i++) |
| 4381 | 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] | 4382 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 4383 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4384 | if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4385 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4386 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4387 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 4388 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4389 | if (PyObject_SetAttr(result, astmodulestate_global->comparators, value) |
| 4390 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4391 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4392 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4393 | break; |
| 4394 | case Call_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4395 | tp = (PyTypeObject *)astmodulestate_global->Call_type; |
| 4396 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4397 | if (!result) goto failed; |
| 4398 | value = ast2obj_expr(o->v.Call.func); |
| 4399 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4400 | if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4401 | goto failed; |
| 4402 | Py_DECREF(value); |
| 4403 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 4404 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4405 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4406 | goto failed; |
| 4407 | Py_DECREF(value); |
| 4408 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 4409 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4410 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 4411 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4412 | goto failed; |
| 4413 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4414 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4415 | case FormattedValue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4416 | tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type; |
| 4417 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4418 | if (!result) goto failed; |
| 4419 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 4420 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4421 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4422 | goto failed; |
| 4423 | Py_DECREF(value); |
| 4424 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 4425 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4426 | if (PyObject_SetAttr(result, astmodulestate_global->conversion, value) |
| 4427 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4428 | goto failed; |
| 4429 | Py_DECREF(value); |
| 4430 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 4431 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4432 | if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value) |
| 4433 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4434 | goto failed; |
| 4435 | Py_DECREF(value); |
| 4436 | break; |
| 4437 | case JoinedStr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4438 | tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type; |
| 4439 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4440 | if (!result) goto failed; |
| 4441 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 4442 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4443 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4444 | -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4445 | goto failed; |
| 4446 | Py_DECREF(value); |
| 4447 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4448 | case Constant_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4449 | tp = (PyTypeObject *)astmodulestate_global->Constant_type; |
| 4450 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4451 | if (!result) goto failed; |
| 4452 | value = ast2obj_constant(o->v.Constant.value); |
| 4453 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4454 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4455 | goto failed; |
| 4456 | Py_DECREF(value); |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4457 | value = ast2obj_string(o->v.Constant.kind); |
| 4458 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4459 | if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1) |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4460 | goto failed; |
| 4461 | Py_DECREF(value); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4462 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4463 | case Attribute_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4464 | tp = (PyTypeObject *)astmodulestate_global->Attribute_type; |
| 4465 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4466 | if (!result) goto failed; |
| 4467 | value = ast2obj_expr(o->v.Attribute.value); |
| 4468 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4469 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4470 | goto failed; |
| 4471 | Py_DECREF(value); |
| 4472 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 4473 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4474 | if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4475 | goto failed; |
| 4476 | Py_DECREF(value); |
| 4477 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 4478 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4479 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4480 | goto failed; |
| 4481 | Py_DECREF(value); |
| 4482 | break; |
| 4483 | case Subscript_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4484 | tp = (PyTypeObject *)astmodulestate_global->Subscript_type; |
| 4485 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4486 | if (!result) goto failed; |
| 4487 | value = ast2obj_expr(o->v.Subscript.value); |
| 4488 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4489 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4490 | goto failed; |
| 4491 | Py_DECREF(value); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 4492 | value = ast2obj_expr(o->v.Subscript.slice); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4493 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4494 | if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4495 | goto failed; |
| 4496 | Py_DECREF(value); |
| 4497 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 4498 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4499 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4500 | goto failed; |
| 4501 | Py_DECREF(value); |
| 4502 | break; |
| 4503 | case Starred_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4504 | tp = (PyTypeObject *)astmodulestate_global->Starred_type; |
| 4505 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4506 | if (!result) goto failed; |
| 4507 | value = ast2obj_expr(o->v.Starred.value); |
| 4508 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4509 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4510 | goto failed; |
| 4511 | Py_DECREF(value); |
| 4512 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 4513 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4514 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4515 | goto failed; |
| 4516 | Py_DECREF(value); |
| 4517 | break; |
| 4518 | case Name_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4519 | tp = (PyTypeObject *)astmodulestate_global->Name_type; |
| 4520 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4521 | if (!result) goto failed; |
| 4522 | value = ast2obj_identifier(o->v.Name.id); |
| 4523 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4524 | if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4525 | goto failed; |
| 4526 | Py_DECREF(value); |
| 4527 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 4528 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4529 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4530 | goto failed; |
| 4531 | Py_DECREF(value); |
| 4532 | break; |
| 4533 | case List_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4534 | tp = (PyTypeObject *)astmodulestate_global->List_type; |
| 4535 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4536 | if (!result) goto failed; |
| 4537 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 4538 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4539 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4540 | goto failed; |
| 4541 | Py_DECREF(value); |
| 4542 | value = ast2obj_expr_context(o->v.List.ctx); |
| 4543 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4544 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4545 | goto failed; |
| 4546 | Py_DECREF(value); |
| 4547 | break; |
| 4548 | case Tuple_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4549 | tp = (PyTypeObject *)astmodulestate_global->Tuple_type; |
| 4550 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4551 | if (!result) goto failed; |
| 4552 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 4553 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4554 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4555 | goto failed; |
| 4556 | Py_DECREF(value); |
| 4557 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 4558 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4559 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4560 | goto failed; |
| 4561 | Py_DECREF(value); |
| 4562 | break; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 4563 | case Slice_kind: |
| 4564 | tp = (PyTypeObject *)astmodulestate_global->Slice_type; |
| 4565 | result = PyType_GenericNew(tp, NULL, NULL); |
| 4566 | if (!result) goto failed; |
| 4567 | value = ast2obj_expr(o->v.Slice.lower); |
| 4568 | if (!value) goto failed; |
| 4569 | if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1) |
| 4570 | goto failed; |
| 4571 | Py_DECREF(value); |
| 4572 | value = ast2obj_expr(o->v.Slice.upper); |
| 4573 | if (!value) goto failed; |
| 4574 | if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1) |
| 4575 | goto failed; |
| 4576 | Py_DECREF(value); |
| 4577 | value = ast2obj_expr(o->v.Slice.step); |
| 4578 | if (!value) goto failed; |
| 4579 | if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1) |
| 4580 | goto failed; |
| 4581 | Py_DECREF(value); |
| 4582 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4583 | } |
| 4584 | value = ast2obj_int(o->lineno); |
| 4585 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4586 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4587 | goto failed; |
| 4588 | Py_DECREF(value); |
| 4589 | value = ast2obj_int(o->col_offset); |
| 4590 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4591 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4592 | goto failed; |
| 4593 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4594 | value = ast2obj_int(o->end_lineno); |
| 4595 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4596 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4597 | goto failed; |
| 4598 | Py_DECREF(value); |
| 4599 | value = ast2obj_int(o->end_col_offset); |
| 4600 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4601 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4602 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4603 | goto failed; |
| 4604 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4605 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4606 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4607 | Py_XDECREF(value); |
| 4608 | Py_XDECREF(result); |
| 4609 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4610 | } |
| 4611 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4612 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4613 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4614 | switch(o) { |
| 4615 | case Load: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4616 | Py_INCREF(astmodulestate_global->Load_singleton); |
| 4617 | return astmodulestate_global->Load_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4618 | case Store: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4619 | Py_INCREF(astmodulestate_global->Store_singleton); |
| 4620 | return astmodulestate_global->Store_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4621 | case Del: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4622 | Py_INCREF(astmodulestate_global->Del_singleton); |
| 4623 | return astmodulestate_global->Del_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4624 | } |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 4625 | Py_UNREACHABLE(); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4626 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4627 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4628 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4629 | switch(o) { |
| 4630 | case And: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4631 | Py_INCREF(astmodulestate_global->And_singleton); |
| 4632 | return astmodulestate_global->And_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4633 | case Or: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4634 | Py_INCREF(astmodulestate_global->Or_singleton); |
| 4635 | return astmodulestate_global->Or_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4636 | } |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 4637 | Py_UNREACHABLE(); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4638 | } |
| 4639 | PyObject* ast2obj_operator(operator_ty o) |
| 4640 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4641 | switch(o) { |
| 4642 | case Add: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4643 | Py_INCREF(astmodulestate_global->Add_singleton); |
| 4644 | return astmodulestate_global->Add_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4645 | case Sub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4646 | Py_INCREF(astmodulestate_global->Sub_singleton); |
| 4647 | return astmodulestate_global->Sub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4648 | case Mult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4649 | Py_INCREF(astmodulestate_global->Mult_singleton); |
| 4650 | return astmodulestate_global->Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 4651 | case MatMult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4652 | Py_INCREF(astmodulestate_global->MatMult_singleton); |
| 4653 | return astmodulestate_global->MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4654 | case Div: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4655 | Py_INCREF(astmodulestate_global->Div_singleton); |
| 4656 | return astmodulestate_global->Div_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4657 | case Mod: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4658 | Py_INCREF(astmodulestate_global->Mod_singleton); |
| 4659 | return astmodulestate_global->Mod_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4660 | case Pow: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4661 | Py_INCREF(astmodulestate_global->Pow_singleton); |
| 4662 | return astmodulestate_global->Pow_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4663 | case LShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4664 | Py_INCREF(astmodulestate_global->LShift_singleton); |
| 4665 | return astmodulestate_global->LShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4666 | case RShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4667 | Py_INCREF(astmodulestate_global->RShift_singleton); |
| 4668 | return astmodulestate_global->RShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4669 | case BitOr: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4670 | Py_INCREF(astmodulestate_global->BitOr_singleton); |
| 4671 | return astmodulestate_global->BitOr_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4672 | case BitXor: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4673 | Py_INCREF(astmodulestate_global->BitXor_singleton); |
| 4674 | return astmodulestate_global->BitXor_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4675 | case BitAnd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4676 | Py_INCREF(astmodulestate_global->BitAnd_singleton); |
| 4677 | return astmodulestate_global->BitAnd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4678 | case FloorDiv: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4679 | Py_INCREF(astmodulestate_global->FloorDiv_singleton); |
| 4680 | return astmodulestate_global->FloorDiv_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4681 | } |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 4682 | Py_UNREACHABLE(); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4683 | } |
| 4684 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 4685 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4686 | switch(o) { |
| 4687 | case Invert: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4688 | Py_INCREF(astmodulestate_global->Invert_singleton); |
| 4689 | return astmodulestate_global->Invert_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4690 | case Not: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4691 | Py_INCREF(astmodulestate_global->Not_singleton); |
| 4692 | return astmodulestate_global->Not_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4693 | case UAdd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4694 | Py_INCREF(astmodulestate_global->UAdd_singleton); |
| 4695 | return astmodulestate_global->UAdd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4696 | case USub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4697 | Py_INCREF(astmodulestate_global->USub_singleton); |
| 4698 | return astmodulestate_global->USub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4699 | } |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 4700 | Py_UNREACHABLE(); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4701 | } |
| 4702 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 4703 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4704 | switch(o) { |
| 4705 | case Eq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4706 | Py_INCREF(astmodulestate_global->Eq_singleton); |
| 4707 | return astmodulestate_global->Eq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4708 | case NotEq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4709 | Py_INCREF(astmodulestate_global->NotEq_singleton); |
| 4710 | return astmodulestate_global->NotEq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4711 | case Lt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4712 | Py_INCREF(astmodulestate_global->Lt_singleton); |
| 4713 | return astmodulestate_global->Lt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4714 | case LtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4715 | Py_INCREF(astmodulestate_global->LtE_singleton); |
| 4716 | return astmodulestate_global->LtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4717 | case Gt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4718 | Py_INCREF(astmodulestate_global->Gt_singleton); |
| 4719 | return astmodulestate_global->Gt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4720 | case GtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4721 | Py_INCREF(astmodulestate_global->GtE_singleton); |
| 4722 | return astmodulestate_global->GtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4723 | case Is: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4724 | Py_INCREF(astmodulestate_global->Is_singleton); |
| 4725 | return astmodulestate_global->Is_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4726 | case IsNot: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4727 | Py_INCREF(astmodulestate_global->IsNot_singleton); |
| 4728 | return astmodulestate_global->IsNot_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4729 | case In: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4730 | Py_INCREF(astmodulestate_global->In_singleton); |
| 4731 | return astmodulestate_global->In_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4732 | case NotIn: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4733 | Py_INCREF(astmodulestate_global->NotIn_singleton); |
| 4734 | return astmodulestate_global->NotIn_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4735 | } |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 4736 | Py_UNREACHABLE(); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4737 | } |
| 4738 | PyObject* |
| 4739 | ast2obj_comprehension(void* _o) |
| 4740 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4741 | comprehension_ty o = (comprehension_ty)_o; |
| 4742 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4743 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4744 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4745 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4746 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4747 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4748 | tp = (PyTypeObject *)astmodulestate_global->comprehension_type; |
| 4749 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4750 | if (!result) return NULL; |
| 4751 | value = ast2obj_expr(o->target); |
| 4752 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4753 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4754 | goto failed; |
| 4755 | Py_DECREF(value); |
| 4756 | value = ast2obj_expr(o->iter); |
| 4757 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4758 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4759 | goto failed; |
| 4760 | Py_DECREF(value); |
| 4761 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 4762 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4763 | if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4764 | goto failed; |
| 4765 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4766 | value = ast2obj_int(o->is_async); |
| 4767 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4768 | if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1) |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4769 | goto failed; |
| 4770 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4771 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4772 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4773 | Py_XDECREF(value); |
| 4774 | Py_XDECREF(result); |
| 4775 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4776 | } |
| 4777 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4778 | PyObject* |
| 4779 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4780 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4781 | excepthandler_ty o = (excepthandler_ty)_o; |
| 4782 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4783 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4784 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4785 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4786 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4787 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4788 | switch (o->kind) { |
| 4789 | case ExceptHandler_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4790 | tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type; |
| 4791 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4792 | if (!result) goto failed; |
| 4793 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4794 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4795 | if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4796 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4797 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4798 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4799 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4800 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4801 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4802 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4803 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 4804 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4805 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4806 | goto failed; |
| 4807 | Py_DECREF(value); |
| 4808 | break; |
| 4809 | } |
| 4810 | value = ast2obj_int(o->lineno); |
| 4811 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4812 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4813 | goto failed; |
| 4814 | Py_DECREF(value); |
| 4815 | value = ast2obj_int(o->col_offset); |
| 4816 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4817 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4818 | goto failed; |
| 4819 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4820 | value = ast2obj_int(o->end_lineno); |
| 4821 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4822 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4823 | goto failed; |
| 4824 | Py_DECREF(value); |
| 4825 | value = ast2obj_int(o->end_col_offset); |
| 4826 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4827 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4828 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4829 | goto failed; |
| 4830 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4831 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4832 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4833 | Py_XDECREF(value); |
| 4834 | Py_XDECREF(result); |
| 4835 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4836 | } |
| 4837 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4838 | PyObject* |
| 4839 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4840 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4841 | arguments_ty o = (arguments_ty)_o; |
| 4842 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4843 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4844 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4845 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4846 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4847 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4848 | tp = (PyTypeObject *)astmodulestate_global->arguments_type; |
| 4849 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4850 | if (!result) return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4851 | value = ast2obj_list(o->posonlyargs, ast2obj_arg); |
| 4852 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4853 | if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) == |
| 4854 | -1) |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4855 | goto failed; |
| 4856 | Py_DECREF(value); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4857 | value = ast2obj_list(o->args, ast2obj_arg); |
| 4858 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4859 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4860 | goto failed; |
| 4861 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4862 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4863 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4864 | if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4865 | goto failed; |
| 4866 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4867 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 4868 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4869 | if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) == |
| 4870 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4871 | goto failed; |
| 4872 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4873 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4874 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4875 | if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) == |
| 4876 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4877 | goto failed; |
| 4878 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4879 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4880 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4881 | if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4882 | goto failed; |
| 4883 | Py_DECREF(value); |
| 4884 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 4885 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4886 | if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4887 | goto failed; |
| 4888 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4889 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4890 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4891 | Py_XDECREF(value); |
| 4892 | Py_XDECREF(result); |
| 4893 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4894 | } |
| 4895 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4896 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4897 | ast2obj_arg(void* _o) |
| 4898 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4899 | arg_ty o = (arg_ty)_o; |
| 4900 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4901 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4902 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4903 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4904 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4905 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4906 | tp = (PyTypeObject *)astmodulestate_global->arg_type; |
| 4907 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4908 | if (!result) return NULL; |
| 4909 | value = ast2obj_identifier(o->arg); |
| 4910 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4911 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4912 | goto failed; |
| 4913 | Py_DECREF(value); |
| 4914 | value = ast2obj_expr(o->annotation); |
| 4915 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4916 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) == |
| 4917 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4918 | goto failed; |
| 4919 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4920 | value = ast2obj_string(o->type_comment); |
| 4921 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4922 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) == |
| 4923 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4924 | goto failed; |
| 4925 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4926 | value = ast2obj_int(o->lineno); |
| 4927 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4928 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4929 | goto failed; |
| 4930 | Py_DECREF(value); |
| 4931 | value = ast2obj_int(o->col_offset); |
| 4932 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4933 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4934 | goto failed; |
| 4935 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4936 | value = ast2obj_int(o->end_lineno); |
| 4937 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4938 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4939 | goto failed; |
| 4940 | Py_DECREF(value); |
| 4941 | value = ast2obj_int(o->end_col_offset); |
| 4942 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4943 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4944 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4945 | goto failed; |
| 4946 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4947 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4948 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4949 | Py_XDECREF(value); |
| 4950 | Py_XDECREF(result); |
| 4951 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4952 | } |
| 4953 | |
| 4954 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4955 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4956 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4957 | keyword_ty o = (keyword_ty)_o; |
| 4958 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4959 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4960 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4961 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4962 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4963 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4964 | tp = (PyTypeObject *)astmodulestate_global->keyword_type; |
| 4965 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4966 | if (!result) return NULL; |
| 4967 | value = ast2obj_identifier(o->arg); |
| 4968 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4969 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4970 | goto failed; |
| 4971 | Py_DECREF(value); |
| 4972 | value = ast2obj_expr(o->value); |
| 4973 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4974 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4975 | goto failed; |
| 4976 | Py_DECREF(value); |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 4977 | value = ast2obj_int(o->lineno); |
| 4978 | if (!value) goto failed; |
| 4979 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
| 4980 | goto failed; |
| 4981 | Py_DECREF(value); |
| 4982 | value = ast2obj_int(o->col_offset); |
| 4983 | if (!value) goto failed; |
| 4984 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
| 4985 | goto failed; |
| 4986 | Py_DECREF(value); |
| 4987 | value = ast2obj_int(o->end_lineno); |
| 4988 | if (!value) goto failed; |
| 4989 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
| 4990 | goto failed; |
| 4991 | Py_DECREF(value); |
| 4992 | value = ast2obj_int(o->end_col_offset); |
| 4993 | if (!value) goto failed; |
| 4994 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4995 | < 0) |
| 4996 | goto failed; |
| 4997 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4998 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4999 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5000 | Py_XDECREF(value); |
| 5001 | Py_XDECREF(result); |
| 5002 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5003 | } |
| 5004 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 5005 | PyObject* |
| 5006 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5007 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5008 | alias_ty o = (alias_ty)_o; |
| 5009 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5010 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5011 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 5012 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5013 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 5014 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5015 | tp = (PyTypeObject *)astmodulestate_global->alias_type; |
| 5016 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5017 | if (!result) return NULL; |
| 5018 | value = ast2obj_identifier(o->name); |
| 5019 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5020 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5021 | goto failed; |
| 5022 | Py_DECREF(value); |
| 5023 | value = ast2obj_identifier(o->asname); |
| 5024 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5025 | if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5026 | goto failed; |
| 5027 | Py_DECREF(value); |
| 5028 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 5029 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5030 | Py_XDECREF(value); |
| 5031 | Py_XDECREF(result); |
| 5032 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5033 | } |
| 5034 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5035 | PyObject* |
| 5036 | ast2obj_withitem(void* _o) |
| 5037 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5038 | withitem_ty o = (withitem_ty)_o; |
| 5039 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5040 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5041 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 5042 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5043 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5044 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5045 | tp = (PyTypeObject *)astmodulestate_global->withitem_type; |
| 5046 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5047 | if (!result) return NULL; |
| 5048 | value = ast2obj_expr(o->context_expr); |
| 5049 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5050 | if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) == |
| 5051 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5052 | goto failed; |
| 5053 | Py_DECREF(value); |
| 5054 | value = ast2obj_expr(o->optional_vars); |
| 5055 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5056 | if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value) |
| 5057 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5058 | goto failed; |
| 5059 | Py_DECREF(value); |
| 5060 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5061 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5062 | Py_XDECREF(value); |
| 5063 | Py_XDECREF(result); |
| 5064 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5065 | } |
| 5066 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5067 | PyObject* |
| 5068 | ast2obj_type_ignore(void* _o) |
| 5069 | { |
| 5070 | type_ignore_ty o = (type_ignore_ty)_o; |
| 5071 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5072 | PyTypeObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5073 | if (!o) { |
| 5074 | Py_RETURN_NONE; |
| 5075 | } |
| 5076 | |
| 5077 | switch (o->kind) { |
| 5078 | case TypeIgnore_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5079 | tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type; |
| 5080 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5081 | if (!result) goto failed; |
| 5082 | value = ast2obj_int(o->v.TypeIgnore.lineno); |
| 5083 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5084 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) == |
| 5085 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5086 | goto failed; |
| 5087 | Py_DECREF(value); |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 5088 | value = ast2obj_string(o->v.TypeIgnore.tag); |
| 5089 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5090 | if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1) |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 5091 | goto failed; |
| 5092 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5093 | break; |
| 5094 | } |
| 5095 | return result; |
| 5096 | failed: |
| 5097 | Py_XDECREF(value); |
| 5098 | Py_XDECREF(result); |
| 5099 | return NULL; |
| 5100 | } |
| 5101 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5102 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5103 | int |
| 5104 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 5105 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5106 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5107 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5108 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5109 | PyObject *tp; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5110 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5111 | if (obj == Py_None) { |
| 5112 | *out = NULL; |
| 5113 | return 0; |
| 5114 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5115 | tp = astmodulestate_global->Module_type; |
| 5116 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5117 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5118 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5119 | } |
| 5120 | if (isinstance) { |
| 5121 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5122 | asdl_seq* type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5123 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5124 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5125 | return 1; |
| 5126 | } |
| 5127 | if (tmp == NULL) { |
| 5128 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 5129 | return 1; |
| 5130 | } |
| 5131 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5132 | int res; |
| 5133 | Py_ssize_t len; |
| 5134 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5135 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5136 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5137 | goto failed; |
| 5138 | } |
| 5139 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5140 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5141 | if (body == NULL) goto failed; |
| 5142 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5143 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5144 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5145 | Py_INCREF(tmp2); |
| 5146 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5147 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5148 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5149 | if (len != PyList_GET_SIZE(tmp)) { |
| 5150 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 5151 | goto failed; |
| 5152 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5153 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5154 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5155 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5156 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5157 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores, |
| 5158 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5159 | return 1; |
| 5160 | } |
| 5161 | if (tmp == NULL) { |
| 5162 | PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module"); |
| 5163 | return 1; |
| 5164 | } |
| 5165 | else { |
| 5166 | int res; |
| 5167 | Py_ssize_t len; |
| 5168 | Py_ssize_t i; |
| 5169 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5170 | PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5171 | goto failed; |
| 5172 | } |
| 5173 | len = PyList_GET_SIZE(tmp); |
| 5174 | type_ignores = _Py_asdl_seq_new(len, arena); |
| 5175 | if (type_ignores == NULL) goto failed; |
| 5176 | for (i = 0; i < len; i++) { |
| 5177 | type_ignore_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5178 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5179 | Py_INCREF(tmp2); |
| 5180 | res = obj2ast_type_ignore(tmp2, &val, arena); |
| 5181 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5182 | if (res != 0) goto failed; |
| 5183 | if (len != PyList_GET_SIZE(tmp)) { |
| 5184 | PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration"); |
| 5185 | goto failed; |
| 5186 | } |
| 5187 | asdl_seq_SET(type_ignores, i, val); |
| 5188 | } |
| 5189 | Py_CLEAR(tmp); |
| 5190 | } |
| 5191 | *out = Module(body, type_ignores, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5192 | if (*out == NULL) goto failed; |
| 5193 | return 0; |
| 5194 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5195 | tp = astmodulestate_global->Interactive_type; |
| 5196 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5197 | if (isinstance == -1) { |
| 5198 | return 1; |
| 5199 | } |
| 5200 | if (isinstance) { |
| 5201 | asdl_seq* body; |
| 5202 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5203 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5204 | return 1; |
| 5205 | } |
| 5206 | if (tmp == NULL) { |
| 5207 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 5208 | return 1; |
| 5209 | } |
| 5210 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5211 | int res; |
| 5212 | Py_ssize_t len; |
| 5213 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5214 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5215 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5216 | goto failed; |
| 5217 | } |
| 5218 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5219 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5220 | if (body == NULL) goto failed; |
| 5221 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5222 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5223 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5224 | Py_INCREF(tmp2); |
| 5225 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5226 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5227 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5228 | if (len != PyList_GET_SIZE(tmp)) { |
| 5229 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 5230 | goto failed; |
| 5231 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5232 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5233 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5234 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5235 | } |
| 5236 | *out = Interactive(body, arena); |
| 5237 | if (*out == NULL) goto failed; |
| 5238 | return 0; |
| 5239 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5240 | tp = astmodulestate_global->Expression_type; |
| 5241 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5242 | if (isinstance == -1) { |
| 5243 | return 1; |
| 5244 | } |
| 5245 | if (isinstance) { |
| 5246 | expr_ty body; |
| 5247 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5248 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5249 | return 1; |
| 5250 | } |
| 5251 | if (tmp == NULL) { |
| 5252 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 5253 | return 1; |
| 5254 | } |
| 5255 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5256 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5257 | res = obj2ast_expr(tmp, &body, arena); |
| 5258 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5259 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5260 | } |
| 5261 | *out = Expression(body, arena); |
| 5262 | if (*out == NULL) goto failed; |
| 5263 | return 0; |
| 5264 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5265 | tp = astmodulestate_global->FunctionType_type; |
| 5266 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5267 | if (isinstance == -1) { |
| 5268 | return 1; |
| 5269 | } |
| 5270 | if (isinstance) { |
| 5271 | asdl_seq* argtypes; |
| 5272 | expr_ty returns; |
| 5273 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5274 | if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) < |
| 5275 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5276 | return 1; |
| 5277 | } |
| 5278 | if (tmp == NULL) { |
| 5279 | PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType"); |
| 5280 | return 1; |
| 5281 | } |
| 5282 | else { |
| 5283 | int res; |
| 5284 | Py_ssize_t len; |
| 5285 | Py_ssize_t i; |
| 5286 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5287 | PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5288 | goto failed; |
| 5289 | } |
| 5290 | len = PyList_GET_SIZE(tmp); |
| 5291 | argtypes = _Py_asdl_seq_new(len, arena); |
| 5292 | if (argtypes == NULL) goto failed; |
| 5293 | for (i = 0; i < len; i++) { |
| 5294 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5295 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5296 | Py_INCREF(tmp2); |
| 5297 | res = obj2ast_expr(tmp2, &val, arena); |
| 5298 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5299 | if (res != 0) goto failed; |
| 5300 | if (len != PyList_GET_SIZE(tmp)) { |
| 5301 | PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration"); |
| 5302 | goto failed; |
| 5303 | } |
| 5304 | asdl_seq_SET(argtypes, i, val); |
| 5305 | } |
| 5306 | Py_CLEAR(tmp); |
| 5307 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5308 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5309 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5310 | return 1; |
| 5311 | } |
| 5312 | if (tmp == NULL) { |
| 5313 | PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType"); |
| 5314 | return 1; |
| 5315 | } |
| 5316 | else { |
| 5317 | int res; |
| 5318 | res = obj2ast_expr(tmp, &returns, arena); |
| 5319 | if (res != 0) goto failed; |
| 5320 | Py_CLEAR(tmp); |
| 5321 | } |
| 5322 | *out = FunctionType(argtypes, returns, arena); |
| 5323 | if (*out == NULL) goto failed; |
| 5324 | return 0; |
| 5325 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5326 | |
| 5327 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 5328 | failed: |
| 5329 | Py_XDECREF(tmp); |
| 5330 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5331 | } |
| 5332 | |
| 5333 | int |
| 5334 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 5335 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5336 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5337 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5338 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5339 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5340 | int lineno; |
| 5341 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5342 | int end_lineno; |
| 5343 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5344 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5345 | if (obj == Py_None) { |
| 5346 | *out = NULL; |
| 5347 | return 0; |
| 5348 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5349 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5350 | return 1; |
| 5351 | } |
| 5352 | if (tmp == NULL) { |
| 5353 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 5354 | return 1; |
| 5355 | } |
| 5356 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5357 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5358 | res = obj2ast_int(tmp, &lineno, arena); |
| 5359 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5360 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5361 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5362 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 5363 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5364 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5365 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5366 | if (tmp == NULL) { |
| 5367 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 5368 | return 1; |
| 5369 | } |
| 5370 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5371 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5372 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5373 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5374 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5375 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5376 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 5377 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5378 | return 1; |
| 5379 | } |
| 5380 | if (tmp == NULL || tmp == Py_None) { |
| 5381 | Py_CLEAR(tmp); |
| 5382 | end_lineno = 0; |
| 5383 | } |
| 5384 | else { |
| 5385 | int res; |
| 5386 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 5387 | if (res != 0) goto failed; |
| 5388 | Py_CLEAR(tmp); |
| 5389 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5390 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 5391 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5392 | return 1; |
| 5393 | } |
| 5394 | if (tmp == NULL || tmp == Py_None) { |
| 5395 | Py_CLEAR(tmp); |
| 5396 | end_col_offset = 0; |
| 5397 | } |
| 5398 | else { |
| 5399 | int res; |
| 5400 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 5401 | if (res != 0) goto failed; |
| 5402 | Py_CLEAR(tmp); |
| 5403 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5404 | tp = astmodulestate_global->FunctionDef_type; |
| 5405 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5406 | if (isinstance == -1) { |
| 5407 | return 1; |
| 5408 | } |
| 5409 | if (isinstance) { |
| 5410 | identifier name; |
| 5411 | arguments_ty args; |
| 5412 | asdl_seq* body; |
| 5413 | asdl_seq* decorator_list; |
| 5414 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5415 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5416 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5417 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5418 | return 1; |
| 5419 | } |
| 5420 | if (tmp == NULL) { |
| 5421 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 5422 | return 1; |
| 5423 | } |
| 5424 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5425 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5426 | res = obj2ast_identifier(tmp, &name, arena); |
| 5427 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5428 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5429 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5430 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5431 | return 1; |
| 5432 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5433 | if (tmp == NULL) { |
| 5434 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 5435 | return 1; |
| 5436 | } |
| 5437 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5438 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5439 | res = obj2ast_arguments(tmp, &args, arena); |
| 5440 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5441 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5442 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5443 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5444 | return 1; |
| 5445 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5446 | if (tmp == NULL) { |
| 5447 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 5448 | return 1; |
| 5449 | } |
| 5450 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5451 | int res; |
| 5452 | Py_ssize_t len; |
| 5453 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5454 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5455 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5456 | goto failed; |
| 5457 | } |
| 5458 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5459 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5460 | if (body == NULL) goto failed; |
| 5461 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5462 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5463 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5464 | Py_INCREF(tmp2); |
| 5465 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5466 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5467 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5468 | if (len != PyList_GET_SIZE(tmp)) { |
| 5469 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 5470 | goto failed; |
| 5471 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5472 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5473 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5474 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5475 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5476 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5477 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5478 | return 1; |
| 5479 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5480 | if (tmp == NULL) { |
| 5481 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 5482 | return 1; |
| 5483 | } |
| 5484 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5485 | int res; |
| 5486 | Py_ssize_t len; |
| 5487 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5488 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5489 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5490 | goto failed; |
| 5491 | } |
| 5492 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5493 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5494 | if (decorator_list == NULL) goto failed; |
| 5495 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5496 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5497 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5498 | Py_INCREF(tmp2); |
| 5499 | res = obj2ast_expr(tmp2, &val, arena); |
| 5500 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5501 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5502 | if (len != PyList_GET_SIZE(tmp)) { |
| 5503 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 5504 | goto failed; |
| 5505 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5506 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5507 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5508 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5509 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5510 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5511 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5512 | return 1; |
| 5513 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5514 | if (tmp == NULL || tmp == Py_None) { |
| 5515 | Py_CLEAR(tmp); |
| 5516 | returns = NULL; |
| 5517 | } |
| 5518 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5519 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5520 | res = obj2ast_expr(tmp, &returns, arena); |
| 5521 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5522 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5523 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5524 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5525 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5526 | return 1; |
| 5527 | } |
| 5528 | if (tmp == NULL || tmp == Py_None) { |
| 5529 | Py_CLEAR(tmp); |
| 5530 | type_comment = NULL; |
| 5531 | } |
| 5532 | else { |
| 5533 | int res; |
| 5534 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5535 | if (res != 0) goto failed; |
| 5536 | Py_CLEAR(tmp); |
| 5537 | } |
| 5538 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 5539 | type_comment, lineno, col_offset, end_lineno, |
| 5540 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5541 | if (*out == NULL) goto failed; |
| 5542 | return 0; |
| 5543 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5544 | tp = astmodulestate_global->AsyncFunctionDef_type; |
| 5545 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5546 | if (isinstance == -1) { |
| 5547 | return 1; |
| 5548 | } |
| 5549 | if (isinstance) { |
| 5550 | identifier name; |
| 5551 | arguments_ty args; |
| 5552 | asdl_seq* body; |
| 5553 | asdl_seq* decorator_list; |
| 5554 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5555 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5556 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5557 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5558 | return 1; |
| 5559 | } |
| 5560 | if (tmp == NULL) { |
| 5561 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 5562 | return 1; |
| 5563 | } |
| 5564 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5565 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5566 | res = obj2ast_identifier(tmp, &name, arena); |
| 5567 | if (res != 0) goto failed; |
| 5568 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5569 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5570 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5571 | return 1; |
| 5572 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5573 | if (tmp == NULL) { |
| 5574 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 5575 | return 1; |
| 5576 | } |
| 5577 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5578 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5579 | res = obj2ast_arguments(tmp, &args, arena); |
| 5580 | if (res != 0) goto failed; |
| 5581 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5582 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5583 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5584 | return 1; |
| 5585 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5586 | if (tmp == NULL) { |
| 5587 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 5588 | return 1; |
| 5589 | } |
| 5590 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5591 | int res; |
| 5592 | Py_ssize_t len; |
| 5593 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5594 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5595 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5596 | goto failed; |
| 5597 | } |
| 5598 | len = PyList_GET_SIZE(tmp); |
| 5599 | body = _Py_asdl_seq_new(len, arena); |
| 5600 | if (body == NULL) goto failed; |
| 5601 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5602 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5603 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5604 | Py_INCREF(tmp2); |
| 5605 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5606 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5607 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5608 | if (len != PyList_GET_SIZE(tmp)) { |
| 5609 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 5610 | goto failed; |
| 5611 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5612 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5613 | } |
| 5614 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5615 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5616 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5617 | &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5618 | return 1; |
| 5619 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5620 | if (tmp == NULL) { |
| 5621 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 5622 | return 1; |
| 5623 | } |
| 5624 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5625 | int res; |
| 5626 | Py_ssize_t len; |
| 5627 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5628 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5629 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5630 | goto failed; |
| 5631 | } |
| 5632 | len = PyList_GET_SIZE(tmp); |
| 5633 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 5634 | if (decorator_list == NULL) goto failed; |
| 5635 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5636 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5637 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5638 | Py_INCREF(tmp2); |
| 5639 | res = obj2ast_expr(tmp2, &val, arena); |
| 5640 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5641 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5642 | if (len != PyList_GET_SIZE(tmp)) { |
| 5643 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 5644 | goto failed; |
| 5645 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5646 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5647 | } |
| 5648 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5649 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5650 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5651 | 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5652 | return 1; |
| 5653 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5654 | if (tmp == NULL || tmp == Py_None) { |
| 5655 | Py_CLEAR(tmp); |
| 5656 | returns = NULL; |
| 5657 | } |
| 5658 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5659 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5660 | res = obj2ast_expr(tmp, &returns, arena); |
| 5661 | if (res != 0) goto failed; |
| 5662 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5663 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5664 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5665 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5666 | return 1; |
| 5667 | } |
| 5668 | if (tmp == NULL || tmp == Py_None) { |
| 5669 | Py_CLEAR(tmp); |
| 5670 | type_comment = NULL; |
| 5671 | } |
| 5672 | else { |
| 5673 | int res; |
| 5674 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5675 | if (res != 0) goto failed; |
| 5676 | Py_CLEAR(tmp); |
| 5677 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5678 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5679 | type_comment, lineno, col_offset, end_lineno, |
| 5680 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5681 | if (*out == NULL) goto failed; |
| 5682 | return 0; |
| 5683 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5684 | tp = astmodulestate_global->ClassDef_type; |
| 5685 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5686 | if (isinstance == -1) { |
| 5687 | return 1; |
| 5688 | } |
| 5689 | if (isinstance) { |
| 5690 | identifier name; |
| 5691 | asdl_seq* bases; |
| 5692 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5693 | asdl_seq* body; |
| 5694 | asdl_seq* decorator_list; |
| 5695 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5696 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5697 | return 1; |
| 5698 | } |
| 5699 | if (tmp == NULL) { |
| 5700 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 5701 | return 1; |
| 5702 | } |
| 5703 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5704 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5705 | res = obj2ast_identifier(tmp, &name, arena); |
| 5706 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5707 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5708 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5709 | if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5710 | return 1; |
| 5711 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5712 | if (tmp == NULL) { |
| 5713 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 5714 | return 1; |
| 5715 | } |
| 5716 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5717 | int res; |
| 5718 | Py_ssize_t len; |
| 5719 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5720 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5721 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5722 | goto failed; |
| 5723 | } |
| 5724 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5725 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5726 | if (bases == NULL) goto failed; |
| 5727 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5728 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5729 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5730 | Py_INCREF(tmp2); |
| 5731 | res = obj2ast_expr(tmp2, &val, arena); |
| 5732 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5733 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5734 | if (len != PyList_GET_SIZE(tmp)) { |
| 5735 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 5736 | goto failed; |
| 5737 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5738 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5739 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5740 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5741 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5742 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 5743 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5744 | return 1; |
| 5745 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5746 | if (tmp == NULL) { |
| 5747 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 5748 | return 1; |
| 5749 | } |
| 5750 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5751 | int res; |
| 5752 | Py_ssize_t len; |
| 5753 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5754 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5755 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5756 | goto failed; |
| 5757 | } |
| 5758 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5759 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5760 | if (keywords == NULL) goto failed; |
| 5761 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5762 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5763 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5764 | Py_INCREF(tmp2); |
| 5765 | res = obj2ast_keyword(tmp2, &val, arena); |
| 5766 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5767 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5768 | if (len != PyList_GET_SIZE(tmp)) { |
| 5769 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 5770 | goto failed; |
| 5771 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5772 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5773 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5774 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5775 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5776 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5777 | return 1; |
| 5778 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5779 | if (tmp == NULL) { |
| 5780 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 5781 | return 1; |
| 5782 | } |
| 5783 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5784 | int res; |
| 5785 | Py_ssize_t len; |
| 5786 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5787 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5788 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5789 | goto failed; |
| 5790 | } |
| 5791 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5792 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5793 | if (body == NULL) goto failed; |
| 5794 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5795 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5796 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5797 | Py_INCREF(tmp2); |
| 5798 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5799 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5800 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5801 | if (len != PyList_GET_SIZE(tmp)) { |
| 5802 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 5803 | goto failed; |
| 5804 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5805 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5806 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5807 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5808 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5809 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5810 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5811 | return 1; |
| 5812 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5813 | if (tmp == NULL) { |
| 5814 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 5815 | return 1; |
| 5816 | } |
| 5817 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5818 | int res; |
| 5819 | Py_ssize_t len; |
| 5820 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5821 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5822 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5823 | goto failed; |
| 5824 | } |
| 5825 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5826 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5827 | if (decorator_list == NULL) goto failed; |
| 5828 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5829 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5830 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5831 | Py_INCREF(tmp2); |
| 5832 | res = obj2ast_expr(tmp2, &val, arena); |
| 5833 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5834 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5835 | if (len != PyList_GET_SIZE(tmp)) { |
| 5836 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
| 5837 | goto failed; |
| 5838 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5839 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5840 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5841 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5842 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 5843 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5844 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5845 | if (*out == NULL) goto failed; |
| 5846 | return 0; |
| 5847 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5848 | tp = astmodulestate_global->Return_type; |
| 5849 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5850 | if (isinstance == -1) { |
| 5851 | return 1; |
| 5852 | } |
| 5853 | if (isinstance) { |
| 5854 | expr_ty value; |
| 5855 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5856 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5857 | return 1; |
| 5858 | } |
| 5859 | if (tmp == NULL || tmp == Py_None) { |
| 5860 | Py_CLEAR(tmp); |
| 5861 | value = NULL; |
| 5862 | } |
| 5863 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5864 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5865 | res = obj2ast_expr(tmp, &value, arena); |
| 5866 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5867 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5868 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5869 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 5870 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5871 | if (*out == NULL) goto failed; |
| 5872 | return 0; |
| 5873 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5874 | tp = astmodulestate_global->Delete_type; |
| 5875 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5876 | if (isinstance == -1) { |
| 5877 | return 1; |
| 5878 | } |
| 5879 | if (isinstance) { |
| 5880 | asdl_seq* targets; |
| 5881 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5882 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5883 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5884 | return 1; |
| 5885 | } |
| 5886 | if (tmp == NULL) { |
| 5887 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 5888 | return 1; |
| 5889 | } |
| 5890 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5891 | int res; |
| 5892 | Py_ssize_t len; |
| 5893 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5894 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5895 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5896 | goto failed; |
| 5897 | } |
| 5898 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5899 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5900 | if (targets == NULL) goto failed; |
| 5901 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5902 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5903 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5904 | Py_INCREF(tmp2); |
| 5905 | res = obj2ast_expr(tmp2, &val, arena); |
| 5906 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5907 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5908 | if (len != PyList_GET_SIZE(tmp)) { |
| 5909 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 5910 | goto failed; |
| 5911 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5912 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5913 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5914 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5915 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5916 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 5917 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5918 | if (*out == NULL) goto failed; |
| 5919 | return 0; |
| 5920 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5921 | tp = astmodulestate_global->Assign_type; |
| 5922 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5923 | if (isinstance == -1) { |
| 5924 | return 1; |
| 5925 | } |
| 5926 | if (isinstance) { |
| 5927 | asdl_seq* targets; |
| 5928 | expr_ty value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5929 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5930 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5931 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5932 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5933 | return 1; |
| 5934 | } |
| 5935 | if (tmp == NULL) { |
| 5936 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 5937 | return 1; |
| 5938 | } |
| 5939 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5940 | int res; |
| 5941 | Py_ssize_t len; |
| 5942 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5943 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5944 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5945 | goto failed; |
| 5946 | } |
| 5947 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5948 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5949 | if (targets == NULL) goto failed; |
| 5950 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5951 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5952 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5953 | Py_INCREF(tmp2); |
| 5954 | res = obj2ast_expr(tmp2, &val, arena); |
| 5955 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5956 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5957 | if (len != PyList_GET_SIZE(tmp)) { |
| 5958 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 5959 | goto failed; |
| 5960 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5961 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5962 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5963 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5964 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5965 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5966 | return 1; |
| 5967 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5968 | if (tmp == NULL) { |
| 5969 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 5970 | return 1; |
| 5971 | } |
| 5972 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5973 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5974 | res = obj2ast_expr(tmp, &value, arena); |
| 5975 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5976 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5977 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5978 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5979 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5980 | return 1; |
| 5981 | } |
| 5982 | if (tmp == NULL || tmp == Py_None) { |
| 5983 | Py_CLEAR(tmp); |
| 5984 | type_comment = NULL; |
| 5985 | } |
| 5986 | else { |
| 5987 | int res; |
| 5988 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5989 | if (res != 0) goto failed; |
| 5990 | Py_CLEAR(tmp); |
| 5991 | } |
| 5992 | *out = Assign(targets, value, type_comment, lineno, col_offset, |
| 5993 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5994 | if (*out == NULL) goto failed; |
| 5995 | return 0; |
| 5996 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5997 | tp = astmodulestate_global->AugAssign_type; |
| 5998 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5999 | if (isinstance == -1) { |
| 6000 | return 1; |
| 6001 | } |
| 6002 | if (isinstance) { |
| 6003 | expr_ty target; |
| 6004 | operator_ty op; |
| 6005 | expr_ty value; |
| 6006 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6007 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6008 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6009 | return 1; |
| 6010 | } |
| 6011 | if (tmp == NULL) { |
| 6012 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 6013 | return 1; |
| 6014 | } |
| 6015 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6016 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6017 | res = obj2ast_expr(tmp, &target, arena); |
| 6018 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6019 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6020 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6021 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6022 | return 1; |
| 6023 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6024 | if (tmp == NULL) { |
| 6025 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 6026 | return 1; |
| 6027 | } |
| 6028 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6029 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6030 | res = obj2ast_operator(tmp, &op, arena); |
| 6031 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6032 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6033 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6034 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6035 | return 1; |
| 6036 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6037 | if (tmp == NULL) { |
| 6038 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 6039 | return 1; |
| 6040 | } |
| 6041 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6042 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6043 | res = obj2ast_expr(tmp, &value, arena); |
| 6044 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6045 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6046 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6047 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 6048 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6049 | if (*out == NULL) goto failed; |
| 6050 | return 0; |
| 6051 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6052 | tp = astmodulestate_global->AnnAssign_type; |
| 6053 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6054 | if (isinstance == -1) { |
| 6055 | return 1; |
| 6056 | } |
| 6057 | if (isinstance) { |
| 6058 | expr_ty target; |
| 6059 | expr_ty annotation; |
| 6060 | expr_ty value; |
| 6061 | int simple; |
| 6062 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6063 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6064 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6065 | return 1; |
| 6066 | } |
| 6067 | if (tmp == NULL) { |
| 6068 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 6069 | return 1; |
| 6070 | } |
| 6071 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6072 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6073 | res = obj2ast_expr(tmp, &target, arena); |
| 6074 | if (res != 0) goto failed; |
| 6075 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6076 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6077 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) |
| 6078 | < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6079 | return 1; |
| 6080 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6081 | if (tmp == NULL) { |
| 6082 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 6083 | return 1; |
| 6084 | } |
| 6085 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6086 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6087 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6088 | if (res != 0) goto failed; |
| 6089 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6090 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6091 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6092 | return 1; |
| 6093 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6094 | if (tmp == NULL || tmp == Py_None) { |
| 6095 | Py_CLEAR(tmp); |
| 6096 | value = NULL; |
| 6097 | } |
| 6098 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6099 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6100 | res = obj2ast_expr(tmp, &value, arena); |
| 6101 | if (res != 0) goto failed; |
| 6102 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6103 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6104 | if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0) |
| 6105 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6106 | return 1; |
| 6107 | } |
| 6108 | if (tmp == NULL) { |
| 6109 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 6110 | return 1; |
| 6111 | } |
| 6112 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6113 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6114 | res = obj2ast_int(tmp, &simple, arena); |
| 6115 | if (res != 0) goto failed; |
| 6116 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6117 | } |
| 6118 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6119 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6120 | if (*out == NULL) goto failed; |
| 6121 | return 0; |
| 6122 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6123 | tp = astmodulestate_global->For_type; |
| 6124 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6125 | if (isinstance == -1) { |
| 6126 | return 1; |
| 6127 | } |
| 6128 | if (isinstance) { |
| 6129 | expr_ty target; |
| 6130 | expr_ty iter; |
| 6131 | asdl_seq* body; |
| 6132 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6133 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6134 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6135 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6136 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6137 | return 1; |
| 6138 | } |
| 6139 | if (tmp == NULL) { |
| 6140 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 6141 | return 1; |
| 6142 | } |
| 6143 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6144 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6145 | res = obj2ast_expr(tmp, &target, arena); |
| 6146 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6147 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6148 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6149 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6150 | return 1; |
| 6151 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6152 | if (tmp == NULL) { |
| 6153 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 6154 | return 1; |
| 6155 | } |
| 6156 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6157 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6158 | res = obj2ast_expr(tmp, &iter, arena); |
| 6159 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6160 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6161 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6162 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6163 | return 1; |
| 6164 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6165 | if (tmp == NULL) { |
| 6166 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 6167 | return 1; |
| 6168 | } |
| 6169 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6170 | int res; |
| 6171 | Py_ssize_t len; |
| 6172 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6173 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6174 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6175 | goto failed; |
| 6176 | } |
| 6177 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6178 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6179 | if (body == NULL) goto failed; |
| 6180 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6181 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6182 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6183 | Py_INCREF(tmp2); |
| 6184 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6185 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6186 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6187 | if (len != PyList_GET_SIZE(tmp)) { |
| 6188 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 6189 | goto failed; |
| 6190 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6191 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6192 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6193 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6194 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6195 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6196 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6197 | return 1; |
| 6198 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6199 | if (tmp == NULL) { |
| 6200 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 6201 | return 1; |
| 6202 | } |
| 6203 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6204 | int res; |
| 6205 | Py_ssize_t len; |
| 6206 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6207 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6208 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6209 | goto failed; |
| 6210 | } |
| 6211 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6212 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6213 | if (orelse == NULL) goto failed; |
| 6214 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6215 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6216 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6217 | Py_INCREF(tmp2); |
| 6218 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6219 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6220 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6221 | if (len != PyList_GET_SIZE(tmp)) { |
| 6222 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 6223 | goto failed; |
| 6224 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6225 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6226 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6227 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6228 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6229 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6230 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6231 | return 1; |
| 6232 | } |
| 6233 | if (tmp == NULL || tmp == Py_None) { |
| 6234 | Py_CLEAR(tmp); |
| 6235 | type_comment = NULL; |
| 6236 | } |
| 6237 | else { |
| 6238 | int res; |
| 6239 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6240 | if (res != 0) goto failed; |
| 6241 | Py_CLEAR(tmp); |
| 6242 | } |
| 6243 | *out = For(target, iter, body, orelse, type_comment, lineno, |
| 6244 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6245 | if (*out == NULL) goto failed; |
| 6246 | return 0; |
| 6247 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6248 | tp = astmodulestate_global->AsyncFor_type; |
| 6249 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6250 | if (isinstance == -1) { |
| 6251 | return 1; |
| 6252 | } |
| 6253 | if (isinstance) { |
| 6254 | expr_ty target; |
| 6255 | expr_ty iter; |
| 6256 | asdl_seq* body; |
| 6257 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6258 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6259 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6260 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6261 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6262 | return 1; |
| 6263 | } |
| 6264 | if (tmp == NULL) { |
| 6265 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 6266 | return 1; |
| 6267 | } |
| 6268 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6269 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6270 | res = obj2ast_expr(tmp, &target, arena); |
| 6271 | if (res != 0) goto failed; |
| 6272 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6273 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6274 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6275 | return 1; |
| 6276 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6277 | if (tmp == NULL) { |
| 6278 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 6279 | return 1; |
| 6280 | } |
| 6281 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6282 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6283 | res = obj2ast_expr(tmp, &iter, arena); |
| 6284 | if (res != 0) goto failed; |
| 6285 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6286 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6287 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6288 | return 1; |
| 6289 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6290 | if (tmp == NULL) { |
| 6291 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 6292 | return 1; |
| 6293 | } |
| 6294 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6295 | int res; |
| 6296 | Py_ssize_t len; |
| 6297 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6298 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6299 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6300 | goto failed; |
| 6301 | } |
| 6302 | len = PyList_GET_SIZE(tmp); |
| 6303 | body = _Py_asdl_seq_new(len, arena); |
| 6304 | if (body == NULL) goto failed; |
| 6305 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6306 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6307 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6308 | Py_INCREF(tmp2); |
| 6309 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6310 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6311 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6312 | if (len != PyList_GET_SIZE(tmp)) { |
| 6313 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 6314 | goto failed; |
| 6315 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6316 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6317 | } |
| 6318 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6319 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6320 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6321 | { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6322 | return 1; |
| 6323 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6324 | if (tmp == NULL) { |
| 6325 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 6326 | return 1; |
| 6327 | } |
| 6328 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6329 | int res; |
| 6330 | Py_ssize_t len; |
| 6331 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6332 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6333 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6334 | goto failed; |
| 6335 | } |
| 6336 | len = PyList_GET_SIZE(tmp); |
| 6337 | orelse = _Py_asdl_seq_new(len, arena); |
| 6338 | if (orelse == NULL) goto failed; |
| 6339 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6340 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6341 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6342 | Py_INCREF(tmp2); |
| 6343 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6344 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6345 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6346 | if (len != PyList_GET_SIZE(tmp)) { |
| 6347 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 6348 | goto failed; |
| 6349 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6350 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6351 | } |
| 6352 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6353 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6354 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6355 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6356 | return 1; |
| 6357 | } |
| 6358 | if (tmp == NULL || tmp == Py_None) { |
| 6359 | Py_CLEAR(tmp); |
| 6360 | type_comment = NULL; |
| 6361 | } |
| 6362 | else { |
| 6363 | int res; |
| 6364 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6365 | if (res != 0) goto failed; |
| 6366 | Py_CLEAR(tmp); |
| 6367 | } |
| 6368 | *out = AsyncFor(target, iter, body, orelse, type_comment, lineno, |
| 6369 | col_offset, end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6370 | if (*out == NULL) goto failed; |
| 6371 | return 0; |
| 6372 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6373 | tp = astmodulestate_global->While_type; |
| 6374 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6375 | if (isinstance == -1) { |
| 6376 | return 1; |
| 6377 | } |
| 6378 | if (isinstance) { |
| 6379 | expr_ty test; |
| 6380 | asdl_seq* body; |
| 6381 | asdl_seq* orelse; |
| 6382 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6383 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6384 | return 1; |
| 6385 | } |
| 6386 | if (tmp == NULL) { |
| 6387 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 6388 | return 1; |
| 6389 | } |
| 6390 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6391 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6392 | res = obj2ast_expr(tmp, &test, arena); |
| 6393 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6394 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6395 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6396 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6397 | return 1; |
| 6398 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6399 | if (tmp == NULL) { |
| 6400 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 6401 | return 1; |
| 6402 | } |
| 6403 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6404 | int res; |
| 6405 | Py_ssize_t len; |
| 6406 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6407 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6408 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6409 | goto failed; |
| 6410 | } |
| 6411 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6412 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6413 | if (body == NULL) goto failed; |
| 6414 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6415 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6416 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6417 | Py_INCREF(tmp2); |
| 6418 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6419 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6420 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6421 | if (len != PyList_GET_SIZE(tmp)) { |
| 6422 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 6423 | goto failed; |
| 6424 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6425 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6426 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6427 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6428 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6429 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6430 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6431 | return 1; |
| 6432 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6433 | if (tmp == NULL) { |
| 6434 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 6435 | return 1; |
| 6436 | } |
| 6437 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6438 | int res; |
| 6439 | Py_ssize_t len; |
| 6440 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6441 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6442 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6443 | goto failed; |
| 6444 | } |
| 6445 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6446 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6447 | if (orelse == NULL) goto failed; |
| 6448 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6449 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6450 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6451 | Py_INCREF(tmp2); |
| 6452 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6453 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6454 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6455 | if (len != PyList_GET_SIZE(tmp)) { |
| 6456 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 6457 | goto failed; |
| 6458 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6459 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6460 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6461 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6462 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6463 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 6464 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6465 | if (*out == NULL) goto failed; |
| 6466 | return 0; |
| 6467 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6468 | tp = astmodulestate_global->If_type; |
| 6469 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6470 | if (isinstance == -1) { |
| 6471 | return 1; |
| 6472 | } |
| 6473 | if (isinstance) { |
| 6474 | expr_ty test; |
| 6475 | asdl_seq* body; |
| 6476 | asdl_seq* orelse; |
| 6477 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6478 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6479 | return 1; |
| 6480 | } |
| 6481 | if (tmp == NULL) { |
| 6482 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 6483 | return 1; |
| 6484 | } |
| 6485 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6486 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6487 | res = obj2ast_expr(tmp, &test, arena); |
| 6488 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6489 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6490 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6491 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6492 | return 1; |
| 6493 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6494 | if (tmp == NULL) { |
| 6495 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 6496 | return 1; |
| 6497 | } |
| 6498 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6499 | int res; |
| 6500 | Py_ssize_t len; |
| 6501 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6502 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6503 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6504 | goto failed; |
| 6505 | } |
| 6506 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6507 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6508 | if (body == NULL) goto failed; |
| 6509 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6510 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6511 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6512 | Py_INCREF(tmp2); |
| 6513 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6514 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6515 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6516 | if (len != PyList_GET_SIZE(tmp)) { |
| 6517 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 6518 | goto failed; |
| 6519 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6520 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6521 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6522 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6523 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6524 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6525 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6526 | return 1; |
| 6527 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6528 | if (tmp == NULL) { |
| 6529 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 6530 | return 1; |
| 6531 | } |
| 6532 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6533 | int res; |
| 6534 | Py_ssize_t len; |
| 6535 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6536 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6537 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6538 | goto failed; |
| 6539 | } |
| 6540 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6541 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6542 | if (orelse == NULL) goto failed; |
| 6543 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6544 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6545 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6546 | Py_INCREF(tmp2); |
| 6547 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6548 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6549 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6550 | if (len != PyList_GET_SIZE(tmp)) { |
| 6551 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 6552 | goto failed; |
| 6553 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6554 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6555 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6556 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6557 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6558 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 6559 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6560 | if (*out == NULL) goto failed; |
| 6561 | return 0; |
| 6562 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6563 | tp = astmodulestate_global->With_type; |
| 6564 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6565 | if (isinstance == -1) { |
| 6566 | return 1; |
| 6567 | } |
| 6568 | if (isinstance) { |
| 6569 | asdl_seq* items; |
| 6570 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6571 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6572 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6573 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6574 | return 1; |
| 6575 | } |
| 6576 | if (tmp == NULL) { |
| 6577 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 6578 | return 1; |
| 6579 | } |
| 6580 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6581 | int res; |
| 6582 | Py_ssize_t len; |
| 6583 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6584 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6585 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6586 | goto failed; |
| 6587 | } |
| 6588 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6589 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6590 | if (items == NULL) goto failed; |
| 6591 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6592 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6593 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6594 | Py_INCREF(tmp2); |
| 6595 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6596 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6597 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6598 | if (len != PyList_GET_SIZE(tmp)) { |
| 6599 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 6600 | goto failed; |
| 6601 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6602 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6603 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6604 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6605 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6606 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6607 | return 1; |
| 6608 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6609 | if (tmp == NULL) { |
| 6610 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 6611 | return 1; |
| 6612 | } |
| 6613 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6614 | int res; |
| 6615 | Py_ssize_t len; |
| 6616 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6617 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6618 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6619 | goto failed; |
| 6620 | } |
| 6621 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6622 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6623 | if (body == NULL) goto failed; |
| 6624 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6625 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6626 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6627 | Py_INCREF(tmp2); |
| 6628 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6629 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6630 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6631 | if (len != PyList_GET_SIZE(tmp)) { |
| 6632 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 6633 | goto failed; |
| 6634 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6635 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6636 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6637 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6638 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6639 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6640 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6641 | return 1; |
| 6642 | } |
| 6643 | if (tmp == NULL || tmp == Py_None) { |
| 6644 | Py_CLEAR(tmp); |
| 6645 | type_comment = NULL; |
| 6646 | } |
| 6647 | else { |
| 6648 | int res; |
| 6649 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6650 | if (res != 0) goto failed; |
| 6651 | Py_CLEAR(tmp); |
| 6652 | } |
| 6653 | *out = With(items, body, type_comment, lineno, col_offset, end_lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6654 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6655 | if (*out == NULL) goto failed; |
| 6656 | return 0; |
| 6657 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6658 | tp = astmodulestate_global->AsyncWith_type; |
| 6659 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6660 | if (isinstance == -1) { |
| 6661 | return 1; |
| 6662 | } |
| 6663 | if (isinstance) { |
| 6664 | asdl_seq* items; |
| 6665 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6666 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6667 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6668 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6669 | return 1; |
| 6670 | } |
| 6671 | if (tmp == NULL) { |
| 6672 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 6673 | return 1; |
| 6674 | } |
| 6675 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6676 | int res; |
| 6677 | Py_ssize_t len; |
| 6678 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6679 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6680 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6681 | goto failed; |
| 6682 | } |
| 6683 | len = PyList_GET_SIZE(tmp); |
| 6684 | items = _Py_asdl_seq_new(len, arena); |
| 6685 | if (items == NULL) goto failed; |
| 6686 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6687 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6688 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6689 | Py_INCREF(tmp2); |
| 6690 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6691 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6692 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6693 | if (len != PyList_GET_SIZE(tmp)) { |
| 6694 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 6695 | goto failed; |
| 6696 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6697 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6698 | } |
| 6699 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6700 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6701 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6702 | return 1; |
| 6703 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6704 | if (tmp == NULL) { |
| 6705 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 6706 | return 1; |
| 6707 | } |
| 6708 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6709 | int res; |
| 6710 | Py_ssize_t len; |
| 6711 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6712 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6713 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6714 | goto failed; |
| 6715 | } |
| 6716 | len = PyList_GET_SIZE(tmp); |
| 6717 | body = _Py_asdl_seq_new(len, arena); |
| 6718 | if (body == NULL) goto failed; |
| 6719 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6720 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6721 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6722 | Py_INCREF(tmp2); |
| 6723 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6724 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6725 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6726 | if (len != PyList_GET_SIZE(tmp)) { |
| 6727 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 6728 | goto failed; |
| 6729 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6730 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6731 | } |
| 6732 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6733 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6734 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6735 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6736 | return 1; |
| 6737 | } |
| 6738 | if (tmp == NULL || tmp == Py_None) { |
| 6739 | Py_CLEAR(tmp); |
| 6740 | type_comment = NULL; |
| 6741 | } |
| 6742 | else { |
| 6743 | int res; |
| 6744 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6745 | if (res != 0) goto failed; |
| 6746 | Py_CLEAR(tmp); |
| 6747 | } |
| 6748 | *out = AsyncWith(items, body, type_comment, lineno, col_offset, |
| 6749 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6750 | if (*out == NULL) goto failed; |
| 6751 | return 0; |
| 6752 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6753 | tp = astmodulestate_global->Raise_type; |
| 6754 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6755 | if (isinstance == -1) { |
| 6756 | return 1; |
| 6757 | } |
| 6758 | if (isinstance) { |
| 6759 | expr_ty exc; |
| 6760 | expr_ty cause; |
| 6761 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6762 | if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6763 | return 1; |
| 6764 | } |
| 6765 | if (tmp == NULL || tmp == Py_None) { |
| 6766 | Py_CLEAR(tmp); |
| 6767 | exc = NULL; |
| 6768 | } |
| 6769 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6770 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6771 | res = obj2ast_expr(tmp, &exc, arena); |
| 6772 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6773 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6774 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6775 | if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6776 | return 1; |
| 6777 | } |
| 6778 | if (tmp == NULL || tmp == Py_None) { |
| 6779 | Py_CLEAR(tmp); |
| 6780 | cause = NULL; |
| 6781 | } |
| 6782 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6783 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6784 | res = obj2ast_expr(tmp, &cause, arena); |
| 6785 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6786 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6787 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6788 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 6789 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6790 | if (*out == NULL) goto failed; |
| 6791 | return 0; |
| 6792 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6793 | tp = astmodulestate_global->Try_type; |
| 6794 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6795 | if (isinstance == -1) { |
| 6796 | return 1; |
| 6797 | } |
| 6798 | if (isinstance) { |
| 6799 | asdl_seq* body; |
| 6800 | asdl_seq* handlers; |
| 6801 | asdl_seq* orelse; |
| 6802 | asdl_seq* finalbody; |
| 6803 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6804 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6805 | return 1; |
| 6806 | } |
| 6807 | if (tmp == NULL) { |
| 6808 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 6809 | return 1; |
| 6810 | } |
| 6811 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6812 | int res; |
| 6813 | Py_ssize_t len; |
| 6814 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6815 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6816 | PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6817 | goto failed; |
| 6818 | } |
| 6819 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6820 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6821 | if (body == NULL) goto failed; |
| 6822 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6823 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6824 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6825 | Py_INCREF(tmp2); |
| 6826 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6827 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6828 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6829 | if (len != PyList_GET_SIZE(tmp)) { |
| 6830 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 6831 | goto failed; |
| 6832 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6833 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6834 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6835 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6836 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6837 | if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) < |
| 6838 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6839 | return 1; |
| 6840 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6841 | if (tmp == NULL) { |
| 6842 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 6843 | return 1; |
| 6844 | } |
| 6845 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6846 | int res; |
| 6847 | Py_ssize_t len; |
| 6848 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6849 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6850 | PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6851 | goto failed; |
| 6852 | } |
| 6853 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6854 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6855 | if (handlers == NULL) goto failed; |
| 6856 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6857 | excepthandler_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6858 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6859 | Py_INCREF(tmp2); |
| 6860 | res = obj2ast_excepthandler(tmp2, &val, arena); |
| 6861 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6862 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6863 | if (len != PyList_GET_SIZE(tmp)) { |
| 6864 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 6865 | goto failed; |
| 6866 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6867 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6868 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6869 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6870 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6871 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6872 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6873 | return 1; |
| 6874 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6875 | if (tmp == NULL) { |
| 6876 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 6877 | return 1; |
| 6878 | } |
| 6879 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6880 | int res; |
| 6881 | Py_ssize_t len; |
| 6882 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6883 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6884 | PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6885 | goto failed; |
| 6886 | } |
| 6887 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6888 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6889 | if (orelse == NULL) goto failed; |
| 6890 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6891 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6892 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6893 | Py_INCREF(tmp2); |
| 6894 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6895 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6896 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6897 | if (len != PyList_GET_SIZE(tmp)) { |
| 6898 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 6899 | goto failed; |
| 6900 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6901 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6902 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6903 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6904 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6905 | if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) < |
| 6906 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6907 | return 1; |
| 6908 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6909 | if (tmp == NULL) { |
| 6910 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 6911 | return 1; |
| 6912 | } |
| 6913 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6914 | int res; |
| 6915 | Py_ssize_t len; |
| 6916 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6917 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6918 | PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6919 | goto failed; |
| 6920 | } |
| 6921 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6922 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6923 | if (finalbody == NULL) goto failed; |
| 6924 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6925 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6926 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6927 | Py_INCREF(tmp2); |
| 6928 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6929 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6930 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6931 | if (len != PyList_GET_SIZE(tmp)) { |
| 6932 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 6933 | goto failed; |
| 6934 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6935 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6936 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6937 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6938 | } |
| 6939 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6940 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6941 | if (*out == NULL) goto failed; |
| 6942 | return 0; |
| 6943 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6944 | tp = astmodulestate_global->Assert_type; |
| 6945 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6946 | if (isinstance == -1) { |
| 6947 | return 1; |
| 6948 | } |
| 6949 | if (isinstance) { |
| 6950 | expr_ty test; |
| 6951 | expr_ty msg; |
| 6952 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6953 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6954 | return 1; |
| 6955 | } |
| 6956 | if (tmp == NULL) { |
| 6957 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 6958 | return 1; |
| 6959 | } |
| 6960 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6961 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6962 | res = obj2ast_expr(tmp, &test, arena); |
| 6963 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6964 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6965 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6966 | if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6967 | return 1; |
| 6968 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6969 | if (tmp == NULL || tmp == Py_None) { |
| 6970 | Py_CLEAR(tmp); |
| 6971 | msg = NULL; |
| 6972 | } |
| 6973 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6974 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6975 | res = obj2ast_expr(tmp, &msg, arena); |
| 6976 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6977 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6978 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6979 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 6980 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6981 | if (*out == NULL) goto failed; |
| 6982 | return 0; |
| 6983 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6984 | tp = astmodulestate_global->Import_type; |
| 6985 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6986 | if (isinstance == -1) { |
| 6987 | return 1; |
| 6988 | } |
| 6989 | if (isinstance) { |
| 6990 | asdl_seq* names; |
| 6991 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6992 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6993 | return 1; |
| 6994 | } |
| 6995 | if (tmp == NULL) { |
| 6996 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 6997 | return 1; |
| 6998 | } |
| 6999 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7000 | int res; |
| 7001 | Py_ssize_t len; |
| 7002 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7003 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7004 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7005 | goto failed; |
| 7006 | } |
| 7007 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7008 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7009 | if (names == NULL) goto failed; |
| 7010 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7011 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7012 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7013 | Py_INCREF(tmp2); |
| 7014 | res = obj2ast_alias(tmp2, &val, arena); |
| 7015 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7016 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7017 | if (len != PyList_GET_SIZE(tmp)) { |
| 7018 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 7019 | goto failed; |
| 7020 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7021 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7022 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7023 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7024 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7025 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7026 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7027 | if (*out == NULL) goto failed; |
| 7028 | return 0; |
| 7029 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7030 | tp = astmodulestate_global->ImportFrom_type; |
| 7031 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7032 | if (isinstance == -1) { |
| 7033 | return 1; |
| 7034 | } |
| 7035 | if (isinstance) { |
| 7036 | identifier module; |
| 7037 | asdl_seq* names; |
| 7038 | int level; |
| 7039 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7040 | if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0) |
| 7041 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7042 | return 1; |
| 7043 | } |
| 7044 | if (tmp == NULL || tmp == Py_None) { |
| 7045 | Py_CLEAR(tmp); |
| 7046 | module = NULL; |
| 7047 | } |
| 7048 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7049 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7050 | res = obj2ast_identifier(tmp, &module, arena); |
| 7051 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7052 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7053 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7054 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7055 | return 1; |
| 7056 | } |
| 7057 | if (tmp == NULL) { |
| 7058 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 7059 | return 1; |
| 7060 | } |
| 7061 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7062 | int res; |
| 7063 | Py_ssize_t len; |
| 7064 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7065 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7066 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7067 | goto failed; |
| 7068 | } |
| 7069 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7070 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7071 | if (names == NULL) goto failed; |
| 7072 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7073 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7074 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7075 | Py_INCREF(tmp2); |
| 7076 | res = obj2ast_alias(tmp2, &val, arena); |
| 7077 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7078 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7079 | if (len != PyList_GET_SIZE(tmp)) { |
| 7080 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 7081 | goto failed; |
| 7082 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7083 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7084 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7085 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7086 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7087 | if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7088 | return 1; |
| 7089 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7090 | if (tmp == NULL || tmp == Py_None) { |
| 7091 | Py_CLEAR(tmp); |
| 7092 | level = 0; |
| 7093 | } |
| 7094 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7095 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7096 | res = obj2ast_int(tmp, &level, arena); |
| 7097 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7098 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7099 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7100 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 7101 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7102 | if (*out == NULL) goto failed; |
| 7103 | return 0; |
| 7104 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7105 | tp = astmodulestate_global->Global_type; |
| 7106 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7107 | if (isinstance == -1) { |
| 7108 | return 1; |
| 7109 | } |
| 7110 | if (isinstance) { |
| 7111 | asdl_seq* names; |
| 7112 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7113 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7114 | return 1; |
| 7115 | } |
| 7116 | if (tmp == NULL) { |
| 7117 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 7118 | return 1; |
| 7119 | } |
| 7120 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7121 | int res; |
| 7122 | Py_ssize_t len; |
| 7123 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7124 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7125 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7126 | goto failed; |
| 7127 | } |
| 7128 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7129 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7130 | if (names == NULL) goto failed; |
| 7131 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7132 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7133 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7134 | Py_INCREF(tmp2); |
| 7135 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7136 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7137 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7138 | if (len != PyList_GET_SIZE(tmp)) { |
| 7139 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 7140 | goto failed; |
| 7141 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7142 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7143 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7144 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7145 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7146 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7147 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7148 | if (*out == NULL) goto failed; |
| 7149 | return 0; |
| 7150 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7151 | tp = astmodulestate_global->Nonlocal_type; |
| 7152 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7153 | if (isinstance == -1) { |
| 7154 | return 1; |
| 7155 | } |
| 7156 | if (isinstance) { |
| 7157 | asdl_seq* names; |
| 7158 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7159 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7160 | return 1; |
| 7161 | } |
| 7162 | if (tmp == NULL) { |
| 7163 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 7164 | return 1; |
| 7165 | } |
| 7166 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7167 | int res; |
| 7168 | Py_ssize_t len; |
| 7169 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7170 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7171 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7172 | goto failed; |
| 7173 | } |
| 7174 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7175 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7176 | if (names == NULL) goto failed; |
| 7177 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7178 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7179 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7180 | Py_INCREF(tmp2); |
| 7181 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7182 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7183 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7184 | if (len != PyList_GET_SIZE(tmp)) { |
| 7185 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 7186 | goto failed; |
| 7187 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7188 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7189 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7190 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7191 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7192 | *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7193 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7194 | if (*out == NULL) goto failed; |
| 7195 | return 0; |
| 7196 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7197 | tp = astmodulestate_global->Expr_type; |
| 7198 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7199 | if (isinstance == -1) { |
| 7200 | return 1; |
| 7201 | } |
| 7202 | if (isinstance) { |
| 7203 | expr_ty value; |
| 7204 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7205 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7206 | return 1; |
| 7207 | } |
| 7208 | if (tmp == NULL) { |
| 7209 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 7210 | return 1; |
| 7211 | } |
| 7212 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7213 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7214 | res = obj2ast_expr(tmp, &value, arena); |
| 7215 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7216 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7217 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7218 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7219 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7220 | if (*out == NULL) goto failed; |
| 7221 | return 0; |
| 7222 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7223 | tp = astmodulestate_global->Pass_type; |
| 7224 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7225 | if (isinstance == -1) { |
| 7226 | return 1; |
| 7227 | } |
| 7228 | if (isinstance) { |
| 7229 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7230 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7231 | if (*out == NULL) goto failed; |
| 7232 | return 0; |
| 7233 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7234 | tp = astmodulestate_global->Break_type; |
| 7235 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7236 | if (isinstance == -1) { |
| 7237 | return 1; |
| 7238 | } |
| 7239 | if (isinstance) { |
| 7240 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7241 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7242 | if (*out == NULL) goto failed; |
| 7243 | return 0; |
| 7244 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7245 | tp = astmodulestate_global->Continue_type; |
| 7246 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7247 | if (isinstance == -1) { |
| 7248 | return 1; |
| 7249 | } |
| 7250 | if (isinstance) { |
| 7251 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7252 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7253 | if (*out == NULL) goto failed; |
| 7254 | return 0; |
| 7255 | } |
| 7256 | |
| 7257 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 7258 | failed: |
| 7259 | Py_XDECREF(tmp); |
| 7260 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7261 | } |
| 7262 | |
| 7263 | int |
| 7264 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 7265 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7266 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7267 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7268 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7269 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7270 | int lineno; |
| 7271 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7272 | int end_lineno; |
| 7273 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7274 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7275 | if (obj == Py_None) { |
| 7276 | *out = NULL; |
| 7277 | return 0; |
| 7278 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7279 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7280 | return 1; |
| 7281 | } |
| 7282 | if (tmp == NULL) { |
| 7283 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 7284 | return 1; |
| 7285 | } |
| 7286 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7287 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7288 | res = obj2ast_int(tmp, &lineno, arena); |
| 7289 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7290 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7291 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7292 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 7293 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7294 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7295 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7296 | if (tmp == NULL) { |
| 7297 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 7298 | return 1; |
| 7299 | } |
| 7300 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7301 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7302 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7303 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7304 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7305 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7306 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 7307 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7308 | return 1; |
| 7309 | } |
| 7310 | if (tmp == NULL || tmp == Py_None) { |
| 7311 | Py_CLEAR(tmp); |
| 7312 | end_lineno = 0; |
| 7313 | } |
| 7314 | else { |
| 7315 | int res; |
| 7316 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 7317 | if (res != 0) goto failed; |
| 7318 | Py_CLEAR(tmp); |
| 7319 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7320 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 7321 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7322 | return 1; |
| 7323 | } |
| 7324 | if (tmp == NULL || tmp == Py_None) { |
| 7325 | Py_CLEAR(tmp); |
| 7326 | end_col_offset = 0; |
| 7327 | } |
| 7328 | else { |
| 7329 | int res; |
| 7330 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 7331 | if (res != 0) goto failed; |
| 7332 | Py_CLEAR(tmp); |
| 7333 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7334 | tp = astmodulestate_global->BoolOp_type; |
| 7335 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7336 | if (isinstance == -1) { |
| 7337 | return 1; |
| 7338 | } |
| 7339 | if (isinstance) { |
| 7340 | boolop_ty op; |
| 7341 | asdl_seq* values; |
| 7342 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7343 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7344 | return 1; |
| 7345 | } |
| 7346 | if (tmp == NULL) { |
| 7347 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 7348 | return 1; |
| 7349 | } |
| 7350 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7351 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7352 | res = obj2ast_boolop(tmp, &op, arena); |
| 7353 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7354 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7355 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7356 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7357 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7358 | return 1; |
| 7359 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7360 | if (tmp == NULL) { |
| 7361 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 7362 | return 1; |
| 7363 | } |
| 7364 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7365 | int res; |
| 7366 | Py_ssize_t len; |
| 7367 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7368 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7369 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7370 | goto failed; |
| 7371 | } |
| 7372 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7373 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7374 | if (values == NULL) goto failed; |
| 7375 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7376 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7377 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7378 | Py_INCREF(tmp2); |
| 7379 | res = obj2ast_expr(tmp2, &val, arena); |
| 7380 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7381 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7382 | if (len != PyList_GET_SIZE(tmp)) { |
| 7383 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 7384 | goto failed; |
| 7385 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7386 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7387 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7388 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7389 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7390 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 7391 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7392 | if (*out == NULL) goto failed; |
| 7393 | return 0; |
| 7394 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7395 | tp = astmodulestate_global->NamedExpr_type; |
| 7396 | isinstance = PyObject_IsInstance(obj, tp); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7397 | if (isinstance == -1) { |
| 7398 | return 1; |
| 7399 | } |
| 7400 | if (isinstance) { |
| 7401 | expr_ty target; |
| 7402 | expr_ty value; |
| 7403 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7404 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 7405 | { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7406 | return 1; |
| 7407 | } |
| 7408 | if (tmp == NULL) { |
| 7409 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); |
| 7410 | return 1; |
| 7411 | } |
| 7412 | else { |
| 7413 | int res; |
| 7414 | res = obj2ast_expr(tmp, &target, arena); |
| 7415 | if (res != 0) goto failed; |
| 7416 | Py_CLEAR(tmp); |
| 7417 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7418 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7419 | return 1; |
| 7420 | } |
| 7421 | if (tmp == NULL) { |
| 7422 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); |
| 7423 | return 1; |
| 7424 | } |
| 7425 | else { |
| 7426 | int res; |
| 7427 | res = obj2ast_expr(tmp, &value, arena); |
| 7428 | if (res != 0) goto failed; |
| 7429 | Py_CLEAR(tmp); |
| 7430 | } |
| 7431 | *out = NamedExpr(target, value, lineno, col_offset, end_lineno, |
| 7432 | end_col_offset, arena); |
| 7433 | if (*out == NULL) goto failed; |
| 7434 | return 0; |
| 7435 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7436 | tp = astmodulestate_global->BinOp_type; |
| 7437 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7438 | if (isinstance == -1) { |
| 7439 | return 1; |
| 7440 | } |
| 7441 | if (isinstance) { |
| 7442 | expr_ty left; |
| 7443 | operator_ty op; |
| 7444 | expr_ty right; |
| 7445 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7446 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7447 | return 1; |
| 7448 | } |
| 7449 | if (tmp == NULL) { |
| 7450 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 7451 | return 1; |
| 7452 | } |
| 7453 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7454 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7455 | res = obj2ast_expr(tmp, &left, arena); |
| 7456 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7457 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7458 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7459 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7460 | return 1; |
| 7461 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7462 | if (tmp == NULL) { |
| 7463 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 7464 | return 1; |
| 7465 | } |
| 7466 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7467 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7468 | res = obj2ast_operator(tmp, &op, arena); |
| 7469 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7470 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7471 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7472 | if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7473 | return 1; |
| 7474 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7475 | if (tmp == NULL) { |
| 7476 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 7477 | return 1; |
| 7478 | } |
| 7479 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7480 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7481 | res = obj2ast_expr(tmp, &right, arena); |
| 7482 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7483 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7484 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7485 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 7486 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7487 | if (*out == NULL) goto failed; |
| 7488 | return 0; |
| 7489 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7490 | tp = astmodulestate_global->UnaryOp_type; |
| 7491 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7492 | if (isinstance == -1) { |
| 7493 | return 1; |
| 7494 | } |
| 7495 | if (isinstance) { |
| 7496 | unaryop_ty op; |
| 7497 | expr_ty operand; |
| 7498 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7499 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7500 | return 1; |
| 7501 | } |
| 7502 | if (tmp == NULL) { |
| 7503 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 7504 | return 1; |
| 7505 | } |
| 7506 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7507 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7508 | res = obj2ast_unaryop(tmp, &op, arena); |
| 7509 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7510 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7511 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7512 | if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) < |
| 7513 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7514 | return 1; |
| 7515 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7516 | if (tmp == NULL) { |
| 7517 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 7518 | return 1; |
| 7519 | } |
| 7520 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7521 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7522 | res = obj2ast_expr(tmp, &operand, arena); |
| 7523 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7524 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7525 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7526 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 7527 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7528 | if (*out == NULL) goto failed; |
| 7529 | return 0; |
| 7530 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7531 | tp = astmodulestate_global->Lambda_type; |
| 7532 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7533 | if (isinstance == -1) { |
| 7534 | return 1; |
| 7535 | } |
| 7536 | if (isinstance) { |
| 7537 | arguments_ty args; |
| 7538 | expr_ty body; |
| 7539 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7540 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7541 | return 1; |
| 7542 | } |
| 7543 | if (tmp == NULL) { |
| 7544 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 7545 | return 1; |
| 7546 | } |
| 7547 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7548 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7549 | res = obj2ast_arguments(tmp, &args, arena); |
| 7550 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7551 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7552 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7553 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7554 | return 1; |
| 7555 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7556 | if (tmp == NULL) { |
| 7557 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 7558 | return 1; |
| 7559 | } |
| 7560 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7561 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7562 | res = obj2ast_expr(tmp, &body, arena); |
| 7563 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7564 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7565 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7566 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 7567 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7568 | if (*out == NULL) goto failed; |
| 7569 | return 0; |
| 7570 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7571 | tp = astmodulestate_global->IfExp_type; |
| 7572 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7573 | if (isinstance == -1) { |
| 7574 | return 1; |
| 7575 | } |
| 7576 | if (isinstance) { |
| 7577 | expr_ty test; |
| 7578 | expr_ty body; |
| 7579 | expr_ty orelse; |
| 7580 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7581 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7582 | return 1; |
| 7583 | } |
| 7584 | if (tmp == NULL) { |
| 7585 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 7586 | return 1; |
| 7587 | } |
| 7588 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7589 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7590 | res = obj2ast_expr(tmp, &test, arena); |
| 7591 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7592 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7593 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7594 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7595 | return 1; |
| 7596 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7597 | if (tmp == NULL) { |
| 7598 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 7599 | return 1; |
| 7600 | } |
| 7601 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7602 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7603 | res = obj2ast_expr(tmp, &body, arena); |
| 7604 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7605 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7606 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7607 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 7608 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7609 | return 1; |
| 7610 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7611 | if (tmp == NULL) { |
| 7612 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 7613 | return 1; |
| 7614 | } |
| 7615 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7616 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7617 | res = obj2ast_expr(tmp, &orelse, arena); |
| 7618 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7619 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7620 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7621 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 7622 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7623 | if (*out == NULL) goto failed; |
| 7624 | return 0; |
| 7625 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7626 | tp = astmodulestate_global->Dict_type; |
| 7627 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7628 | if (isinstance == -1) { |
| 7629 | return 1; |
| 7630 | } |
| 7631 | if (isinstance) { |
| 7632 | asdl_seq* keys; |
| 7633 | asdl_seq* values; |
| 7634 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7635 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7636 | return 1; |
| 7637 | } |
| 7638 | if (tmp == NULL) { |
| 7639 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 7640 | return 1; |
| 7641 | } |
| 7642 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7643 | int res; |
| 7644 | Py_ssize_t len; |
| 7645 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7646 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7647 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7648 | goto failed; |
| 7649 | } |
| 7650 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7651 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7652 | if (keys == NULL) goto failed; |
| 7653 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7654 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7655 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7656 | Py_INCREF(tmp2); |
| 7657 | res = obj2ast_expr(tmp2, &val, arena); |
| 7658 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7659 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7660 | if (len != PyList_GET_SIZE(tmp)) { |
| 7661 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 7662 | goto failed; |
| 7663 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7664 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7665 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7666 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7667 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7668 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7669 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7670 | return 1; |
| 7671 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7672 | if (tmp == NULL) { |
| 7673 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 7674 | return 1; |
| 7675 | } |
| 7676 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7677 | int res; |
| 7678 | Py_ssize_t len; |
| 7679 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7680 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7681 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7682 | goto failed; |
| 7683 | } |
| 7684 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7685 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7686 | if (values == NULL) goto failed; |
| 7687 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7688 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7689 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7690 | Py_INCREF(tmp2); |
| 7691 | res = obj2ast_expr(tmp2, &val, arena); |
| 7692 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7693 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7694 | if (len != PyList_GET_SIZE(tmp)) { |
| 7695 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 7696 | goto failed; |
| 7697 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7698 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7699 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7700 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7701 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7702 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 7703 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7704 | if (*out == NULL) goto failed; |
| 7705 | return 0; |
| 7706 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7707 | tp = astmodulestate_global->Set_type; |
| 7708 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7709 | if (isinstance == -1) { |
| 7710 | return 1; |
| 7711 | } |
| 7712 | if (isinstance) { |
| 7713 | asdl_seq* elts; |
| 7714 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7715 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7716 | return 1; |
| 7717 | } |
| 7718 | if (tmp == NULL) { |
| 7719 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 7720 | return 1; |
| 7721 | } |
| 7722 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7723 | int res; |
| 7724 | Py_ssize_t len; |
| 7725 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7726 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7727 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7728 | goto failed; |
| 7729 | } |
| 7730 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7731 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7732 | if (elts == NULL) goto failed; |
| 7733 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7734 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7735 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7736 | Py_INCREF(tmp2); |
| 7737 | res = obj2ast_expr(tmp2, &val, arena); |
| 7738 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7739 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7740 | if (len != PyList_GET_SIZE(tmp)) { |
| 7741 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 7742 | goto failed; |
| 7743 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7744 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7745 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7746 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7747 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7748 | *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7749 | if (*out == NULL) goto failed; |
| 7750 | return 0; |
| 7751 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7752 | tp = astmodulestate_global->ListComp_type; |
| 7753 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7754 | if (isinstance == -1) { |
| 7755 | return 1; |
| 7756 | } |
| 7757 | if (isinstance) { |
| 7758 | expr_ty elt; |
| 7759 | asdl_seq* generators; |
| 7760 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7761 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7762 | return 1; |
| 7763 | } |
| 7764 | if (tmp == NULL) { |
| 7765 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 7766 | return 1; |
| 7767 | } |
| 7768 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7769 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7770 | res = obj2ast_expr(tmp, &elt, arena); |
| 7771 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7772 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7773 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7774 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7775 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7776 | return 1; |
| 7777 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7778 | if (tmp == NULL) { |
| 7779 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 7780 | return 1; |
| 7781 | } |
| 7782 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7783 | int res; |
| 7784 | Py_ssize_t len; |
| 7785 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7786 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7787 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7788 | goto failed; |
| 7789 | } |
| 7790 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7791 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7792 | if (generators == NULL) goto failed; |
| 7793 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7794 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7795 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7796 | Py_INCREF(tmp2); |
| 7797 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7798 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7799 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7800 | if (len != PyList_GET_SIZE(tmp)) { |
| 7801 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 7802 | goto failed; |
| 7803 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7804 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7805 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7806 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7807 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7808 | *out = ListComp(elt, generators, lineno, col_offset, end_lineno, |
| 7809 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7810 | if (*out == NULL) goto failed; |
| 7811 | return 0; |
| 7812 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7813 | tp = astmodulestate_global->SetComp_type; |
| 7814 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7815 | if (isinstance == -1) { |
| 7816 | return 1; |
| 7817 | } |
| 7818 | if (isinstance) { |
| 7819 | expr_ty elt; |
| 7820 | asdl_seq* generators; |
| 7821 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7822 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7823 | return 1; |
| 7824 | } |
| 7825 | if (tmp == NULL) { |
| 7826 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 7827 | return 1; |
| 7828 | } |
| 7829 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7830 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7831 | res = obj2ast_expr(tmp, &elt, arena); |
| 7832 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7833 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7834 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7835 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7836 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7837 | return 1; |
| 7838 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7839 | if (tmp == NULL) { |
| 7840 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 7841 | return 1; |
| 7842 | } |
| 7843 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7844 | int res; |
| 7845 | Py_ssize_t len; |
| 7846 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7847 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7848 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7849 | goto failed; |
| 7850 | } |
| 7851 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7852 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7853 | if (generators == NULL) goto failed; |
| 7854 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7855 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7856 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7857 | Py_INCREF(tmp2); |
| 7858 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7859 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7860 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7861 | if (len != PyList_GET_SIZE(tmp)) { |
| 7862 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 7863 | goto failed; |
| 7864 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7865 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7866 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7867 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7868 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7869 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 7870 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7871 | if (*out == NULL) goto failed; |
| 7872 | return 0; |
| 7873 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7874 | tp = astmodulestate_global->DictComp_type; |
| 7875 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7876 | if (isinstance == -1) { |
| 7877 | return 1; |
| 7878 | } |
| 7879 | if (isinstance) { |
| 7880 | expr_ty key; |
| 7881 | expr_ty value; |
| 7882 | asdl_seq* generators; |
| 7883 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7884 | if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7885 | return 1; |
| 7886 | } |
| 7887 | if (tmp == NULL) { |
| 7888 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 7889 | return 1; |
| 7890 | } |
| 7891 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7892 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7893 | res = obj2ast_expr(tmp, &key, arena); |
| 7894 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7895 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7896 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7897 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7898 | return 1; |
| 7899 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7900 | if (tmp == NULL) { |
| 7901 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 7902 | return 1; |
| 7903 | } |
| 7904 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7905 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7906 | res = obj2ast_expr(tmp, &value, arena); |
| 7907 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7908 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7909 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7910 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7911 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7912 | return 1; |
| 7913 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7914 | if (tmp == NULL) { |
| 7915 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 7916 | return 1; |
| 7917 | } |
| 7918 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7919 | int res; |
| 7920 | Py_ssize_t len; |
| 7921 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7922 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7923 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7924 | goto failed; |
| 7925 | } |
| 7926 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7927 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7928 | if (generators == NULL) goto failed; |
| 7929 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7930 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7931 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7932 | Py_INCREF(tmp2); |
| 7933 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7934 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7935 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7936 | if (len != PyList_GET_SIZE(tmp)) { |
| 7937 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 7938 | goto failed; |
| 7939 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7940 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7941 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7942 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7943 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7944 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 7945 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7946 | if (*out == NULL) goto failed; |
| 7947 | return 0; |
| 7948 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7949 | tp = astmodulestate_global->GeneratorExp_type; |
| 7950 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7951 | if (isinstance == -1) { |
| 7952 | return 1; |
| 7953 | } |
| 7954 | if (isinstance) { |
| 7955 | expr_ty elt; |
| 7956 | asdl_seq* generators; |
| 7957 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7958 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7959 | return 1; |
| 7960 | } |
| 7961 | if (tmp == NULL) { |
| 7962 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 7963 | return 1; |
| 7964 | } |
| 7965 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7966 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7967 | res = obj2ast_expr(tmp, &elt, arena); |
| 7968 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7969 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7970 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7971 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7972 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7973 | return 1; |
| 7974 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7975 | if (tmp == NULL) { |
| 7976 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 7977 | return 1; |
| 7978 | } |
| 7979 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7980 | int res; |
| 7981 | Py_ssize_t len; |
| 7982 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7983 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7984 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7985 | goto failed; |
| 7986 | } |
| 7987 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7988 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7989 | if (generators == NULL) goto failed; |
| 7990 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7991 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7992 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7993 | Py_INCREF(tmp2); |
| 7994 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7995 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7996 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7997 | if (len != PyList_GET_SIZE(tmp)) { |
| 7998 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 7999 | goto failed; |
| 8000 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8001 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8002 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8003 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8004 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8005 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 8006 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8007 | if (*out == NULL) goto failed; |
| 8008 | return 0; |
| 8009 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8010 | tp = astmodulestate_global->Await_type; |
| 8011 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8012 | if (isinstance == -1) { |
| 8013 | return 1; |
| 8014 | } |
| 8015 | if (isinstance) { |
| 8016 | expr_ty value; |
| 8017 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8018 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8019 | return 1; |
| 8020 | } |
| 8021 | if (tmp == NULL) { |
| 8022 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 8023 | return 1; |
| 8024 | } |
| 8025 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8026 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8027 | res = obj2ast_expr(tmp, &value, arena); |
| 8028 | if (res != 0) goto failed; |
| 8029 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8030 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8031 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8032 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8033 | if (*out == NULL) goto failed; |
| 8034 | return 0; |
| 8035 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8036 | tp = astmodulestate_global->Yield_type; |
| 8037 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8038 | if (isinstance == -1) { |
| 8039 | return 1; |
| 8040 | } |
| 8041 | if (isinstance) { |
| 8042 | expr_ty value; |
| 8043 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8044 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8045 | return 1; |
| 8046 | } |
| 8047 | if (tmp == NULL || tmp == Py_None) { |
| 8048 | Py_CLEAR(tmp); |
| 8049 | value = NULL; |
| 8050 | } |
| 8051 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8052 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8053 | res = obj2ast_expr(tmp, &value, arena); |
| 8054 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8055 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8056 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8057 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8058 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8059 | if (*out == NULL) goto failed; |
| 8060 | return 0; |
| 8061 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8062 | tp = astmodulestate_global->YieldFrom_type; |
| 8063 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8064 | if (isinstance == -1) { |
| 8065 | return 1; |
| 8066 | } |
| 8067 | if (isinstance) { |
| 8068 | expr_ty value; |
| 8069 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8070 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8071 | return 1; |
| 8072 | } |
| 8073 | if (tmp == NULL) { |
| 8074 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 8075 | return 1; |
| 8076 | } |
| 8077 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8078 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8079 | res = obj2ast_expr(tmp, &value, arena); |
| 8080 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8081 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8082 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8083 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8084 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8085 | if (*out == NULL) goto failed; |
| 8086 | return 0; |
| 8087 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8088 | tp = astmodulestate_global->Compare_type; |
| 8089 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8090 | if (isinstance == -1) { |
| 8091 | return 1; |
| 8092 | } |
| 8093 | if (isinstance) { |
| 8094 | expr_ty left; |
| 8095 | asdl_int_seq* ops; |
| 8096 | asdl_seq* comparators; |
| 8097 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8098 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8099 | return 1; |
| 8100 | } |
| 8101 | if (tmp == NULL) { |
| 8102 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 8103 | return 1; |
| 8104 | } |
| 8105 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8106 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8107 | res = obj2ast_expr(tmp, &left, arena); |
| 8108 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8109 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8110 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8111 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8112 | return 1; |
| 8113 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8114 | if (tmp == NULL) { |
| 8115 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 8116 | return 1; |
| 8117 | } |
| 8118 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8119 | int res; |
| 8120 | Py_ssize_t len; |
| 8121 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8122 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8123 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8124 | goto failed; |
| 8125 | } |
| 8126 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8127 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8128 | if (ops == NULL) goto failed; |
| 8129 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8130 | cmpop_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8131 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8132 | Py_INCREF(tmp2); |
| 8133 | res = obj2ast_cmpop(tmp2, &val, arena); |
| 8134 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8135 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8136 | if (len != PyList_GET_SIZE(tmp)) { |
| 8137 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 8138 | goto failed; |
| 8139 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8140 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8141 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8142 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8143 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8144 | if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp) |
| 8145 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8146 | return 1; |
| 8147 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8148 | if (tmp == NULL) { |
| 8149 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 8150 | return 1; |
| 8151 | } |
| 8152 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8153 | int res; |
| 8154 | Py_ssize_t len; |
| 8155 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8156 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8157 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8158 | goto failed; |
| 8159 | } |
| 8160 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8161 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8162 | if (comparators == NULL) goto failed; |
| 8163 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8164 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8165 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8166 | Py_INCREF(tmp2); |
| 8167 | res = obj2ast_expr(tmp2, &val, arena); |
| 8168 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8169 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8170 | if (len != PyList_GET_SIZE(tmp)) { |
| 8171 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 8172 | goto failed; |
| 8173 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8174 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8175 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8176 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8177 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8178 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 8179 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8180 | if (*out == NULL) goto failed; |
| 8181 | return 0; |
| 8182 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8183 | tp = astmodulestate_global->Call_type; |
| 8184 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8185 | if (isinstance == -1) { |
| 8186 | return 1; |
| 8187 | } |
| 8188 | if (isinstance) { |
| 8189 | expr_ty func; |
| 8190 | asdl_seq* args; |
| 8191 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8192 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8193 | if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8194 | return 1; |
| 8195 | } |
| 8196 | if (tmp == NULL) { |
| 8197 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 8198 | return 1; |
| 8199 | } |
| 8200 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8201 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8202 | res = obj2ast_expr(tmp, &func, arena); |
| 8203 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8204 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8205 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8206 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8207 | return 1; |
| 8208 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8209 | if (tmp == NULL) { |
| 8210 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 8211 | return 1; |
| 8212 | } |
| 8213 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8214 | int res; |
| 8215 | Py_ssize_t len; |
| 8216 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8217 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8218 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8219 | goto failed; |
| 8220 | } |
| 8221 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8222 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8223 | if (args == NULL) goto failed; |
| 8224 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8225 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8226 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8227 | Py_INCREF(tmp2); |
| 8228 | res = obj2ast_expr(tmp2, &val, arena); |
| 8229 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8230 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8231 | if (len != PyList_GET_SIZE(tmp)) { |
| 8232 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 8233 | goto failed; |
| 8234 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8235 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8236 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8237 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8238 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8239 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 8240 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8241 | return 1; |
| 8242 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8243 | if (tmp == NULL) { |
| 8244 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 8245 | return 1; |
| 8246 | } |
| 8247 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8248 | int res; |
| 8249 | Py_ssize_t len; |
| 8250 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8251 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8252 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8253 | goto failed; |
| 8254 | } |
| 8255 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8256 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8257 | if (keywords == NULL) goto failed; |
| 8258 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8259 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8260 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8261 | Py_INCREF(tmp2); |
| 8262 | res = obj2ast_keyword(tmp2, &val, arena); |
| 8263 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8264 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8265 | if (len != PyList_GET_SIZE(tmp)) { |
| 8266 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 8267 | goto failed; |
| 8268 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8269 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8270 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8271 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8272 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8273 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 8274 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8275 | if (*out == NULL) goto failed; |
| 8276 | return 0; |
| 8277 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8278 | tp = astmodulestate_global->FormattedValue_type; |
| 8279 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8280 | if (isinstance == -1) { |
| 8281 | return 1; |
| 8282 | } |
| 8283 | if (isinstance) { |
| 8284 | expr_ty value; |
| 8285 | int conversion; |
| 8286 | expr_ty format_spec; |
| 8287 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8288 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8289 | return 1; |
| 8290 | } |
| 8291 | if (tmp == NULL) { |
| 8292 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 8293 | return 1; |
| 8294 | } |
| 8295 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8296 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8297 | res = obj2ast_expr(tmp, &value, arena); |
| 8298 | if (res != 0) goto failed; |
| 8299 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8300 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8301 | if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp) |
| 8302 | < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8303 | return 1; |
| 8304 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8305 | if (tmp == NULL || tmp == Py_None) { |
| 8306 | Py_CLEAR(tmp); |
| 8307 | conversion = 0; |
| 8308 | } |
| 8309 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8310 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8311 | res = obj2ast_int(tmp, &conversion, arena); |
| 8312 | if (res != 0) goto failed; |
| 8313 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8314 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8315 | if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp) |
| 8316 | < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8317 | return 1; |
| 8318 | } |
| 8319 | if (tmp == NULL || tmp == Py_None) { |
| 8320 | Py_CLEAR(tmp); |
| 8321 | format_spec = NULL; |
| 8322 | } |
| 8323 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8324 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8325 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 8326 | if (res != 0) goto failed; |
| 8327 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8328 | } |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 8329 | *out = FormattedValue(value, conversion, format_spec, lineno, |
| 8330 | col_offset, end_lineno, end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8331 | if (*out == NULL) goto failed; |
| 8332 | return 0; |
| 8333 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8334 | tp = astmodulestate_global->JoinedStr_type; |
| 8335 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8336 | if (isinstance == -1) { |
| 8337 | return 1; |
| 8338 | } |
| 8339 | if (isinstance) { |
| 8340 | asdl_seq* values; |
| 8341 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8342 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 8343 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8344 | return 1; |
| 8345 | } |
| 8346 | if (tmp == NULL) { |
| 8347 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 8348 | return 1; |
| 8349 | } |
| 8350 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8351 | int res; |
| 8352 | Py_ssize_t len; |
| 8353 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8354 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8355 | PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8356 | goto failed; |
| 8357 | } |
| 8358 | len = PyList_GET_SIZE(tmp); |
| 8359 | values = _Py_asdl_seq_new(len, arena); |
| 8360 | if (values == NULL) goto failed; |
| 8361 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8362 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8363 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8364 | Py_INCREF(tmp2); |
| 8365 | res = obj2ast_expr(tmp2, &val, arena); |
| 8366 | Py_DECREF(tmp2); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8367 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 8368 | if (len != PyList_GET_SIZE(tmp)) { |
| 8369 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 8370 | goto failed; |
| 8371 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8372 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8373 | } |
| 8374 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8375 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8376 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 8377 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8378 | if (*out == NULL) goto failed; |
| 8379 | return 0; |
| 8380 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8381 | tp = astmodulestate_global->Constant_type; |
| 8382 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8383 | if (isinstance == -1) { |
| 8384 | return 1; |
| 8385 | } |
| 8386 | if (isinstance) { |
| 8387 | constant value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8388 | string kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8389 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8390 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8391 | return 1; |
| 8392 | } |
| 8393 | if (tmp == NULL) { |
| 8394 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 8395 | return 1; |
| 8396 | } |
| 8397 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8398 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8399 | res = obj2ast_constant(tmp, &value, arena); |
| 8400 | if (res != 0) goto failed; |
| 8401 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8402 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8403 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) { |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8404 | return 1; |
| 8405 | } |
| 8406 | if (tmp == NULL || tmp == Py_None) { |
| 8407 | Py_CLEAR(tmp); |
| 8408 | kind = NULL; |
| 8409 | } |
| 8410 | else { |
| 8411 | int res; |
| 8412 | res = obj2ast_string(tmp, &kind, arena); |
| 8413 | if (res != 0) goto failed; |
| 8414 | Py_CLEAR(tmp); |
| 8415 | } |
| 8416 | *out = Constant(value, kind, lineno, col_offset, end_lineno, |
| 8417 | end_col_offset, arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8418 | if (*out == NULL) goto failed; |
| 8419 | return 0; |
| 8420 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8421 | tp = astmodulestate_global->Attribute_type; |
| 8422 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8423 | if (isinstance == -1) { |
| 8424 | return 1; |
| 8425 | } |
| 8426 | if (isinstance) { |
| 8427 | expr_ty value; |
| 8428 | identifier attr; |
| 8429 | expr_context_ty ctx; |
| 8430 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8431 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8432 | return 1; |
| 8433 | } |
| 8434 | if (tmp == NULL) { |
| 8435 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 8436 | return 1; |
| 8437 | } |
| 8438 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8439 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8440 | res = obj2ast_expr(tmp, &value, arena); |
| 8441 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8442 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8443 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8444 | if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8445 | return 1; |
| 8446 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8447 | if (tmp == NULL) { |
| 8448 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 8449 | return 1; |
| 8450 | } |
| 8451 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8452 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8453 | res = obj2ast_identifier(tmp, &attr, arena); |
| 8454 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8455 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8456 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8457 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8458 | return 1; |
| 8459 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8460 | if (tmp == NULL) { |
| 8461 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 8462 | return 1; |
| 8463 | } |
| 8464 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8465 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8466 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8467 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8468 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8469 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8470 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 8471 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8472 | if (*out == NULL) goto failed; |
| 8473 | return 0; |
| 8474 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8475 | tp = astmodulestate_global->Subscript_type; |
| 8476 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8477 | if (isinstance == -1) { |
| 8478 | return 1; |
| 8479 | } |
| 8480 | if (isinstance) { |
| 8481 | expr_ty value; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8482 | expr_ty slice; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8483 | expr_context_ty ctx; |
| 8484 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8485 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8486 | return 1; |
| 8487 | } |
| 8488 | if (tmp == NULL) { |
| 8489 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 8490 | return 1; |
| 8491 | } |
| 8492 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8493 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8494 | res = obj2ast_expr(tmp, &value, arena); |
| 8495 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8496 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8497 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8498 | if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8499 | return 1; |
| 8500 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8501 | if (tmp == NULL) { |
| 8502 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 8503 | return 1; |
| 8504 | } |
| 8505 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8506 | int res; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8507 | res = obj2ast_expr(tmp, &slice, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8508 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8509 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8510 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8511 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8512 | return 1; |
| 8513 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8514 | if (tmp == NULL) { |
| 8515 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 8516 | return 1; |
| 8517 | } |
| 8518 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8519 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8520 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8521 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8522 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8523 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8524 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 8525 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8526 | if (*out == NULL) goto failed; |
| 8527 | return 0; |
| 8528 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8529 | tp = astmodulestate_global->Starred_type; |
| 8530 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8531 | if (isinstance == -1) { |
| 8532 | return 1; |
| 8533 | } |
| 8534 | if (isinstance) { |
| 8535 | expr_ty value; |
| 8536 | expr_context_ty ctx; |
| 8537 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8538 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8539 | return 1; |
| 8540 | } |
| 8541 | if (tmp == NULL) { |
| 8542 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 8543 | return 1; |
| 8544 | } |
| 8545 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8546 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8547 | res = obj2ast_expr(tmp, &value, arena); |
| 8548 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8549 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8550 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8551 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8552 | return 1; |
| 8553 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8554 | if (tmp == NULL) { |
| 8555 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 8556 | return 1; |
| 8557 | } |
| 8558 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8559 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8560 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8561 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8562 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8563 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8564 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 8565 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8566 | if (*out == NULL) goto failed; |
| 8567 | return 0; |
| 8568 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8569 | tp = astmodulestate_global->Name_type; |
| 8570 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8571 | if (isinstance == -1) { |
| 8572 | return 1; |
| 8573 | } |
| 8574 | if (isinstance) { |
| 8575 | identifier id; |
| 8576 | expr_context_ty ctx; |
| 8577 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8578 | if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8579 | return 1; |
| 8580 | } |
| 8581 | if (tmp == NULL) { |
| 8582 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 8583 | return 1; |
| 8584 | } |
| 8585 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8586 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8587 | res = obj2ast_identifier(tmp, &id, arena); |
| 8588 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8589 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8590 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8591 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8592 | return 1; |
| 8593 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8594 | if (tmp == NULL) { |
| 8595 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 8596 | return 1; |
| 8597 | } |
| 8598 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8599 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8600 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8601 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8602 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8603 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8604 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8605 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8606 | if (*out == NULL) goto failed; |
| 8607 | return 0; |
| 8608 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8609 | tp = astmodulestate_global->List_type; |
| 8610 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8611 | if (isinstance == -1) { |
| 8612 | return 1; |
| 8613 | } |
| 8614 | if (isinstance) { |
| 8615 | asdl_seq* elts; |
| 8616 | expr_context_ty ctx; |
| 8617 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8618 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8619 | return 1; |
| 8620 | } |
| 8621 | if (tmp == NULL) { |
| 8622 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 8623 | return 1; |
| 8624 | } |
| 8625 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8626 | int res; |
| 8627 | Py_ssize_t len; |
| 8628 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8629 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8630 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8631 | goto failed; |
| 8632 | } |
| 8633 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8634 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8635 | if (elts == NULL) goto failed; |
| 8636 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8637 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8638 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8639 | Py_INCREF(tmp2); |
| 8640 | res = obj2ast_expr(tmp2, &val, arena); |
| 8641 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8642 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8643 | if (len != PyList_GET_SIZE(tmp)) { |
| 8644 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 8645 | goto failed; |
| 8646 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8647 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8648 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8649 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8650 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8651 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8652 | return 1; |
| 8653 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8654 | if (tmp == NULL) { |
| 8655 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 8656 | return 1; |
| 8657 | } |
| 8658 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8659 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8660 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8661 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8662 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8663 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8664 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8665 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8666 | if (*out == NULL) goto failed; |
| 8667 | return 0; |
| 8668 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8669 | tp = astmodulestate_global->Tuple_type; |
| 8670 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8671 | if (isinstance == -1) { |
| 8672 | return 1; |
| 8673 | } |
| 8674 | if (isinstance) { |
| 8675 | asdl_seq* elts; |
| 8676 | expr_context_ty ctx; |
| 8677 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8678 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8679 | return 1; |
| 8680 | } |
| 8681 | if (tmp == NULL) { |
| 8682 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 8683 | return 1; |
| 8684 | } |
| 8685 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8686 | int res; |
| 8687 | Py_ssize_t len; |
| 8688 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8689 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8690 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8691 | goto failed; |
| 8692 | } |
| 8693 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8694 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8695 | if (elts == NULL) goto failed; |
| 8696 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8697 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8698 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8699 | Py_INCREF(tmp2); |
| 8700 | res = obj2ast_expr(tmp2, &val, arena); |
| 8701 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8702 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8703 | if (len != PyList_GET_SIZE(tmp)) { |
| 8704 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 8705 | goto failed; |
| 8706 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8707 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8708 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8709 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8710 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8711 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8712 | return 1; |
| 8713 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8714 | if (tmp == NULL) { |
| 8715 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 8716 | return 1; |
| 8717 | } |
| 8718 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8719 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8720 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8721 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8722 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8723 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8724 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8725 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8726 | if (*out == NULL) goto failed; |
| 8727 | return 0; |
| 8728 | } |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8729 | tp = astmodulestate_global->Slice_type; |
| 8730 | isinstance = PyObject_IsInstance(obj, tp); |
| 8731 | if (isinstance == -1) { |
| 8732 | return 1; |
| 8733 | } |
| 8734 | if (isinstance) { |
| 8735 | expr_ty lower; |
| 8736 | expr_ty upper; |
| 8737 | expr_ty step; |
| 8738 | |
| 8739 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) { |
| 8740 | return 1; |
| 8741 | } |
| 8742 | if (tmp == NULL || tmp == Py_None) { |
| 8743 | Py_CLEAR(tmp); |
| 8744 | lower = NULL; |
| 8745 | } |
| 8746 | else { |
| 8747 | int res; |
| 8748 | res = obj2ast_expr(tmp, &lower, arena); |
| 8749 | if (res != 0) goto failed; |
| 8750 | Py_CLEAR(tmp); |
| 8751 | } |
| 8752 | if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) { |
| 8753 | return 1; |
| 8754 | } |
| 8755 | if (tmp == NULL || tmp == Py_None) { |
| 8756 | Py_CLEAR(tmp); |
| 8757 | upper = NULL; |
| 8758 | } |
| 8759 | else { |
| 8760 | int res; |
| 8761 | res = obj2ast_expr(tmp, &upper, arena); |
| 8762 | if (res != 0) goto failed; |
| 8763 | Py_CLEAR(tmp); |
| 8764 | } |
| 8765 | if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) { |
| 8766 | return 1; |
| 8767 | } |
| 8768 | if (tmp == NULL || tmp == Py_None) { |
| 8769 | Py_CLEAR(tmp); |
| 8770 | step = NULL; |
| 8771 | } |
| 8772 | else { |
| 8773 | int res; |
| 8774 | res = obj2ast_expr(tmp, &step, arena); |
| 8775 | if (res != 0) goto failed; |
| 8776 | Py_CLEAR(tmp); |
| 8777 | } |
| 8778 | *out = Slice(lower, upper, step, lineno, col_offset, end_lineno, |
| 8779 | end_col_offset, arena); |
| 8780 | if (*out == NULL) goto failed; |
| 8781 | return 0; |
| 8782 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8783 | |
| 8784 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 8785 | failed: |
| 8786 | Py_XDECREF(tmp); |
| 8787 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8788 | } |
| 8789 | |
| 8790 | int |
| 8791 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 8792 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8793 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8794 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8795 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8796 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8797 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8798 | } |
| 8799 | if (isinstance) { |
| 8800 | *out = Load; |
| 8801 | return 0; |
| 8802 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8803 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8804 | if (isinstance == -1) { |
| 8805 | return 1; |
| 8806 | } |
| 8807 | if (isinstance) { |
| 8808 | *out = Store; |
| 8809 | return 0; |
| 8810 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8811 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8812 | if (isinstance == -1) { |
| 8813 | return 1; |
| 8814 | } |
| 8815 | if (isinstance) { |
| 8816 | *out = Del; |
| 8817 | return 0; |
| 8818 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8819 | |
| 8820 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 8821 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8822 | } |
| 8823 | |
| 8824 | int |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8825 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 8826 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8827 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8828 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8829 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8830 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8831 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8832 | } |
| 8833 | if (isinstance) { |
| 8834 | *out = And; |
| 8835 | return 0; |
| 8836 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8837 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8838 | if (isinstance == -1) { |
| 8839 | return 1; |
| 8840 | } |
| 8841 | if (isinstance) { |
| 8842 | *out = Or; |
| 8843 | return 0; |
| 8844 | } |
| 8845 | |
| 8846 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 8847 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8848 | } |
| 8849 | |
| 8850 | int |
| 8851 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 8852 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8853 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8854 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8855 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8856 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8857 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8858 | } |
| 8859 | if (isinstance) { |
| 8860 | *out = Add; |
| 8861 | return 0; |
| 8862 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8863 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8864 | if (isinstance == -1) { |
| 8865 | return 1; |
| 8866 | } |
| 8867 | if (isinstance) { |
| 8868 | *out = Sub; |
| 8869 | return 0; |
| 8870 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8871 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8872 | if (isinstance == -1) { |
| 8873 | return 1; |
| 8874 | } |
| 8875 | if (isinstance) { |
| 8876 | *out = Mult; |
| 8877 | return 0; |
| 8878 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8879 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type); |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8880 | if (isinstance == -1) { |
| 8881 | return 1; |
| 8882 | } |
| 8883 | if (isinstance) { |
| 8884 | *out = MatMult; |
| 8885 | return 0; |
| 8886 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8887 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8888 | if (isinstance == -1) { |
| 8889 | return 1; |
| 8890 | } |
| 8891 | if (isinstance) { |
| 8892 | *out = Div; |
| 8893 | return 0; |
| 8894 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8895 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8896 | if (isinstance == -1) { |
| 8897 | return 1; |
| 8898 | } |
| 8899 | if (isinstance) { |
| 8900 | *out = Mod; |
| 8901 | return 0; |
| 8902 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8903 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8904 | if (isinstance == -1) { |
| 8905 | return 1; |
| 8906 | } |
| 8907 | if (isinstance) { |
| 8908 | *out = Pow; |
| 8909 | return 0; |
| 8910 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8911 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8912 | if (isinstance == -1) { |
| 8913 | return 1; |
| 8914 | } |
| 8915 | if (isinstance) { |
| 8916 | *out = LShift; |
| 8917 | return 0; |
| 8918 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8919 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8920 | if (isinstance == -1) { |
| 8921 | return 1; |
| 8922 | } |
| 8923 | if (isinstance) { |
| 8924 | *out = RShift; |
| 8925 | return 0; |
| 8926 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8927 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8928 | if (isinstance == -1) { |
| 8929 | return 1; |
| 8930 | } |
| 8931 | if (isinstance) { |
| 8932 | *out = BitOr; |
| 8933 | return 0; |
| 8934 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8935 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8936 | if (isinstance == -1) { |
| 8937 | return 1; |
| 8938 | } |
| 8939 | if (isinstance) { |
| 8940 | *out = BitXor; |
| 8941 | return 0; |
| 8942 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8943 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8944 | if (isinstance == -1) { |
| 8945 | return 1; |
| 8946 | } |
| 8947 | if (isinstance) { |
| 8948 | *out = BitAnd; |
| 8949 | return 0; |
| 8950 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8951 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8952 | if (isinstance == -1) { |
| 8953 | return 1; |
| 8954 | } |
| 8955 | if (isinstance) { |
| 8956 | *out = FloorDiv; |
| 8957 | return 0; |
| 8958 | } |
| 8959 | |
| 8960 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 8961 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8962 | } |
| 8963 | |
| 8964 | int |
| 8965 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 8966 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8967 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8968 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8969 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8970 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8971 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8972 | } |
| 8973 | if (isinstance) { |
| 8974 | *out = Invert; |
| 8975 | return 0; |
| 8976 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8977 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8978 | if (isinstance == -1) { |
| 8979 | return 1; |
| 8980 | } |
| 8981 | if (isinstance) { |
| 8982 | *out = Not; |
| 8983 | return 0; |
| 8984 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8985 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8986 | if (isinstance == -1) { |
| 8987 | return 1; |
| 8988 | } |
| 8989 | if (isinstance) { |
| 8990 | *out = UAdd; |
| 8991 | return 0; |
| 8992 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8993 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8994 | if (isinstance == -1) { |
| 8995 | return 1; |
| 8996 | } |
| 8997 | if (isinstance) { |
| 8998 | *out = USub; |
| 8999 | return 0; |
| 9000 | } |
| 9001 | |
| 9002 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 9003 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9004 | } |
| 9005 | |
| 9006 | int |
| 9007 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 9008 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9009 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9010 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9011 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9012 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9013 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9014 | } |
| 9015 | if (isinstance) { |
| 9016 | *out = Eq; |
| 9017 | return 0; |
| 9018 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9019 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9020 | if (isinstance == -1) { |
| 9021 | return 1; |
| 9022 | } |
| 9023 | if (isinstance) { |
| 9024 | *out = NotEq; |
| 9025 | return 0; |
| 9026 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9027 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9028 | if (isinstance == -1) { |
| 9029 | return 1; |
| 9030 | } |
| 9031 | if (isinstance) { |
| 9032 | *out = Lt; |
| 9033 | return 0; |
| 9034 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9035 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9036 | if (isinstance == -1) { |
| 9037 | return 1; |
| 9038 | } |
| 9039 | if (isinstance) { |
| 9040 | *out = LtE; |
| 9041 | return 0; |
| 9042 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9043 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9044 | if (isinstance == -1) { |
| 9045 | return 1; |
| 9046 | } |
| 9047 | if (isinstance) { |
| 9048 | *out = Gt; |
| 9049 | return 0; |
| 9050 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9051 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9052 | if (isinstance == -1) { |
| 9053 | return 1; |
| 9054 | } |
| 9055 | if (isinstance) { |
| 9056 | *out = GtE; |
| 9057 | return 0; |
| 9058 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9059 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9060 | if (isinstance == -1) { |
| 9061 | return 1; |
| 9062 | } |
| 9063 | if (isinstance) { |
| 9064 | *out = Is; |
| 9065 | return 0; |
| 9066 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9067 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9068 | if (isinstance == -1) { |
| 9069 | return 1; |
| 9070 | } |
| 9071 | if (isinstance) { |
| 9072 | *out = IsNot; |
| 9073 | return 0; |
| 9074 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9075 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9076 | if (isinstance == -1) { |
| 9077 | return 1; |
| 9078 | } |
| 9079 | if (isinstance) { |
| 9080 | *out = In; |
| 9081 | return 0; |
| 9082 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9083 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9084 | if (isinstance == -1) { |
| 9085 | return 1; |
| 9086 | } |
| 9087 | if (isinstance) { |
| 9088 | *out = NotIn; |
| 9089 | return 0; |
| 9090 | } |
| 9091 | |
| 9092 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 9093 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9094 | } |
| 9095 | |
| 9096 | int |
| 9097 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 9098 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9099 | PyObject* tmp = NULL; |
| 9100 | expr_ty target; |
| 9101 | expr_ty iter; |
| 9102 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9103 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9104 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9105 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9106 | return 1; |
| 9107 | } |
| 9108 | if (tmp == NULL) { |
| 9109 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 9110 | return 1; |
| 9111 | } |
| 9112 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9113 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9114 | res = obj2ast_expr(tmp, &target, arena); |
| 9115 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9116 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9117 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9118 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9119 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9120 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9121 | if (tmp == NULL) { |
| 9122 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 9123 | return 1; |
| 9124 | } |
| 9125 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9126 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9127 | res = obj2ast_expr(tmp, &iter, arena); |
| 9128 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9129 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9130 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9131 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9132 | return 1; |
| 9133 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9134 | if (tmp == NULL) { |
| 9135 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 9136 | return 1; |
| 9137 | } |
| 9138 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9139 | int res; |
| 9140 | Py_ssize_t len; |
| 9141 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9142 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9143 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9144 | goto failed; |
| 9145 | } |
| 9146 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9147 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9148 | if (ifs == NULL) goto failed; |
| 9149 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9150 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9151 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9152 | Py_INCREF(tmp2); |
| 9153 | res = obj2ast_expr(tmp2, &val, arena); |
| 9154 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9155 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9156 | if (len != PyList_GET_SIZE(tmp)) { |
| 9157 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 9158 | goto failed; |
| 9159 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9160 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9161 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9162 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9163 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9164 | if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9165 | return 1; |
| 9166 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9167 | if (tmp == NULL) { |
| 9168 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 9169 | return 1; |
| 9170 | } |
| 9171 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9172 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9173 | res = obj2ast_int(tmp, &is_async, arena); |
| 9174 | if (res != 0) goto failed; |
| 9175 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9176 | } |
| 9177 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9178 | return 0; |
| 9179 | failed: |
| 9180 | Py_XDECREF(tmp); |
| 9181 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9182 | } |
| 9183 | |
| 9184 | int |
| 9185 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 9186 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9187 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 9188 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9189 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9190 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9191 | int lineno; |
| 9192 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9193 | int end_lineno; |
| 9194 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9195 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9196 | if (obj == Py_None) { |
| 9197 | *out = NULL; |
| 9198 | return 0; |
| 9199 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9200 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9201 | return 1; |
| 9202 | } |
| 9203 | if (tmp == NULL) { |
| 9204 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 9205 | return 1; |
| 9206 | } |
| 9207 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9208 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9209 | res = obj2ast_int(tmp, &lineno, arena); |
| 9210 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9211 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9212 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9213 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9214 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9215 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9216 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9217 | if (tmp == NULL) { |
| 9218 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 9219 | return 1; |
| 9220 | } |
| 9221 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9222 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9223 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9224 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9225 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9226 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9227 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9228 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9229 | return 1; |
| 9230 | } |
| 9231 | if (tmp == NULL || tmp == Py_None) { |
| 9232 | Py_CLEAR(tmp); |
| 9233 | end_lineno = 0; |
| 9234 | } |
| 9235 | else { |
| 9236 | int res; |
| 9237 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9238 | if (res != 0) goto failed; |
| 9239 | Py_CLEAR(tmp); |
| 9240 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9241 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9242 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9243 | return 1; |
| 9244 | } |
| 9245 | if (tmp == NULL || tmp == Py_None) { |
| 9246 | Py_CLEAR(tmp); |
| 9247 | end_col_offset = 0; |
| 9248 | } |
| 9249 | else { |
| 9250 | int res; |
| 9251 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9252 | if (res != 0) goto failed; |
| 9253 | Py_CLEAR(tmp); |
| 9254 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9255 | tp = astmodulestate_global->ExceptHandler_type; |
| 9256 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9257 | if (isinstance == -1) { |
| 9258 | return 1; |
| 9259 | } |
| 9260 | if (isinstance) { |
| 9261 | expr_ty type; |
| 9262 | identifier name; |
| 9263 | asdl_seq* body; |
| 9264 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9265 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9266 | return 1; |
| 9267 | } |
| 9268 | if (tmp == NULL || tmp == Py_None) { |
| 9269 | Py_CLEAR(tmp); |
| 9270 | type = NULL; |
| 9271 | } |
| 9272 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9273 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9274 | res = obj2ast_expr(tmp, &type, arena); |
| 9275 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9276 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9277 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9278 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9279 | return 1; |
| 9280 | } |
| 9281 | if (tmp == NULL || tmp == Py_None) { |
| 9282 | Py_CLEAR(tmp); |
| 9283 | name = NULL; |
| 9284 | } |
| 9285 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9286 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9287 | res = obj2ast_identifier(tmp, &name, arena); |
| 9288 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9289 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9290 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9291 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9292 | return 1; |
| 9293 | } |
| 9294 | if (tmp == NULL) { |
| 9295 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 9296 | return 1; |
| 9297 | } |
| 9298 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9299 | int res; |
| 9300 | Py_ssize_t len; |
| 9301 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9302 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9303 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9304 | goto failed; |
| 9305 | } |
| 9306 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9307 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9308 | if (body == NULL) goto failed; |
| 9309 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9310 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9311 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9312 | Py_INCREF(tmp2); |
| 9313 | res = obj2ast_stmt(tmp2, &val, arena); |
| 9314 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9315 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9316 | if (len != PyList_GET_SIZE(tmp)) { |
| 9317 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 9318 | goto failed; |
| 9319 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9320 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9321 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9322 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9323 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9324 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 9325 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9326 | if (*out == NULL) goto failed; |
| 9327 | return 0; |
| 9328 | } |
| 9329 | |
| 9330 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 9331 | failed: |
| 9332 | Py_XDECREF(tmp); |
| 9333 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9334 | } |
| 9335 | |
| 9336 | int |
| 9337 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 9338 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9339 | PyObject* tmp = NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9340 | asdl_seq* posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9341 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9342 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9343 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9344 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9345 | arg_ty kwarg; |
| 9346 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9347 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9348 | if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) < |
| 9349 | 0) { |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9350 | return 1; |
| 9351 | } |
| 9352 | if (tmp == NULL) { |
| 9353 | PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments"); |
| 9354 | return 1; |
| 9355 | } |
| 9356 | else { |
| 9357 | int res; |
| 9358 | Py_ssize_t len; |
| 9359 | Py_ssize_t i; |
| 9360 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9361 | PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9362 | goto failed; |
| 9363 | } |
| 9364 | len = PyList_GET_SIZE(tmp); |
| 9365 | posonlyargs = _Py_asdl_seq_new(len, arena); |
| 9366 | if (posonlyargs == NULL) goto failed; |
| 9367 | for (i = 0; i < len; i++) { |
| 9368 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9369 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9370 | Py_INCREF(tmp2); |
| 9371 | res = obj2ast_arg(tmp2, &val, arena); |
| 9372 | Py_DECREF(tmp2); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9373 | if (res != 0) goto failed; |
| 9374 | if (len != PyList_GET_SIZE(tmp)) { |
| 9375 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration"); |
| 9376 | goto failed; |
| 9377 | } |
| 9378 | asdl_seq_SET(posonlyargs, i, val); |
| 9379 | } |
| 9380 | Py_CLEAR(tmp); |
| 9381 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9382 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9383 | return 1; |
| 9384 | } |
| 9385 | if (tmp == NULL) { |
| 9386 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 9387 | return 1; |
| 9388 | } |
| 9389 | else { |
| 9390 | int res; |
| 9391 | Py_ssize_t len; |
| 9392 | Py_ssize_t i; |
| 9393 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9394 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9395 | goto failed; |
| 9396 | } |
| 9397 | len = PyList_GET_SIZE(tmp); |
| 9398 | args = _Py_asdl_seq_new(len, arena); |
| 9399 | if (args == NULL) goto failed; |
| 9400 | for (i = 0; i < len; i++) { |
| 9401 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9402 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9403 | Py_INCREF(tmp2); |
| 9404 | res = obj2ast_arg(tmp2, &val, arena); |
| 9405 | Py_DECREF(tmp2); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9406 | if (res != 0) goto failed; |
| 9407 | if (len != PyList_GET_SIZE(tmp)) { |
| 9408 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 9409 | goto failed; |
| 9410 | } |
| 9411 | asdl_seq_SET(args, i, val); |
| 9412 | } |
| 9413 | Py_CLEAR(tmp); |
| 9414 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9415 | if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9416 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9417 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9418 | if (tmp == NULL || tmp == Py_None) { |
| 9419 | Py_CLEAR(tmp); |
| 9420 | vararg = NULL; |
| 9421 | } |
| 9422 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9423 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9424 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9425 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9426 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9427 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9428 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0) |
| 9429 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9430 | return 1; |
| 9431 | } |
| 9432 | if (tmp == NULL) { |
| 9433 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 9434 | return 1; |
| 9435 | } |
| 9436 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9437 | int res; |
| 9438 | Py_ssize_t len; |
| 9439 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9440 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9441 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9442 | goto failed; |
| 9443 | } |
| 9444 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9445 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9446 | if (kwonlyargs == NULL) goto failed; |
| 9447 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9448 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9449 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9450 | Py_INCREF(tmp2); |
| 9451 | res = obj2ast_arg(tmp2, &val, arena); |
| 9452 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9453 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9454 | if (len != PyList_GET_SIZE(tmp)) { |
| 9455 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 9456 | goto failed; |
| 9457 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9458 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9459 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9460 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9461 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9462 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) < |
| 9463 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9464 | return 1; |
| 9465 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9466 | if (tmp == NULL) { |
| 9467 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 9468 | return 1; |
| 9469 | } |
| 9470 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9471 | int res; |
| 9472 | Py_ssize_t len; |
| 9473 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9474 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9475 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9476 | goto failed; |
| 9477 | } |
| 9478 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9479 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9480 | if (kw_defaults == NULL) goto failed; |
| 9481 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9482 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9483 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9484 | Py_INCREF(tmp2); |
| 9485 | res = obj2ast_expr(tmp2, &val, arena); |
| 9486 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9487 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9488 | if (len != PyList_GET_SIZE(tmp)) { |
| 9489 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 9490 | goto failed; |
| 9491 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9492 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9493 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9494 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9495 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9496 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9497 | return 1; |
| 9498 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9499 | if (tmp == NULL || tmp == Py_None) { |
| 9500 | Py_CLEAR(tmp); |
| 9501 | kwarg = NULL; |
| 9502 | } |
| 9503 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9504 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9505 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 9506 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9507 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9508 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9509 | if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9510 | return 1; |
| 9511 | } |
| 9512 | if (tmp == NULL) { |
| 9513 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 9514 | return 1; |
| 9515 | } |
| 9516 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9517 | int res; |
| 9518 | Py_ssize_t len; |
| 9519 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9520 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9521 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9522 | goto failed; |
| 9523 | } |
| 9524 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9525 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9526 | if (defaults == NULL) goto failed; |
| 9527 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9528 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9529 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9530 | Py_INCREF(tmp2); |
| 9531 | res = obj2ast_expr(tmp2, &val, arena); |
| 9532 | Py_DECREF(tmp2); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9533 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9534 | if (len != PyList_GET_SIZE(tmp)) { |
| 9535 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 9536 | goto failed; |
| 9537 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9538 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9539 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9540 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9541 | } |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9542 | *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9543 | defaults, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9544 | return 0; |
| 9545 | failed: |
| 9546 | Py_XDECREF(tmp); |
| 9547 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9548 | } |
| 9549 | |
| 9550 | int |
| 9551 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 9552 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9553 | PyObject* tmp = NULL; |
| 9554 | identifier arg; |
| 9555 | expr_ty annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9556 | string type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9557 | int lineno; |
| 9558 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9559 | int end_lineno; |
| 9560 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9561 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9562 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9563 | return 1; |
| 9564 | } |
| 9565 | if (tmp == NULL) { |
| 9566 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 9567 | return 1; |
| 9568 | } |
| 9569 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9570 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9571 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9572 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9573 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9574 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9575 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0) |
| 9576 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9577 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9578 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9579 | if (tmp == NULL || tmp == Py_None) { |
| 9580 | Py_CLEAR(tmp); |
| 9581 | annotation = NULL; |
| 9582 | } |
| 9583 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9584 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9585 | res = obj2ast_expr(tmp, &annotation, arena); |
| 9586 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9587 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9588 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9589 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) < |
| 9590 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9591 | return 1; |
| 9592 | } |
| 9593 | if (tmp == NULL || tmp == Py_None) { |
| 9594 | Py_CLEAR(tmp); |
| 9595 | type_comment = NULL; |
| 9596 | } |
| 9597 | else { |
| 9598 | int res; |
| 9599 | res = obj2ast_string(tmp, &type_comment, arena); |
| 9600 | if (res != 0) goto failed; |
| 9601 | Py_CLEAR(tmp); |
| 9602 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9603 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9604 | return 1; |
| 9605 | } |
| 9606 | if (tmp == NULL) { |
| 9607 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 9608 | return 1; |
| 9609 | } |
| 9610 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9611 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9612 | res = obj2ast_int(tmp, &lineno, arena); |
| 9613 | if (res != 0) goto failed; |
| 9614 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9615 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9616 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9617 | { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9618 | return 1; |
| 9619 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9620 | if (tmp == NULL) { |
| 9621 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 9622 | return 1; |
| 9623 | } |
| 9624 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9625 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9626 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9627 | if (res != 0) goto failed; |
| 9628 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9629 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9630 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9631 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9632 | return 1; |
| 9633 | } |
| 9634 | if (tmp == NULL || tmp == Py_None) { |
| 9635 | Py_CLEAR(tmp); |
| 9636 | end_lineno = 0; |
| 9637 | } |
| 9638 | else { |
| 9639 | int res; |
| 9640 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9641 | if (res != 0) goto failed; |
| 9642 | Py_CLEAR(tmp); |
| 9643 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9644 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9645 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9646 | return 1; |
| 9647 | } |
| 9648 | if (tmp == NULL || tmp == Py_None) { |
| 9649 | Py_CLEAR(tmp); |
| 9650 | end_col_offset = 0; |
| 9651 | } |
| 9652 | else { |
| 9653 | int res; |
| 9654 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9655 | if (res != 0) goto failed; |
| 9656 | Py_CLEAR(tmp); |
| 9657 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9658 | *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno, |
| 9659 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9660 | return 0; |
| 9661 | failed: |
| 9662 | Py_XDECREF(tmp); |
| 9663 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9664 | } |
| 9665 | |
| 9666 | int |
| 9667 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 9668 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9669 | PyObject* tmp = NULL; |
| 9670 | identifier arg; |
| 9671 | expr_ty value; |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 9672 | int lineno; |
| 9673 | int col_offset; |
| 9674 | int end_lineno; |
| 9675 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9676 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9677 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9678 | return 1; |
| 9679 | } |
| 9680 | if (tmp == NULL || tmp == Py_None) { |
| 9681 | Py_CLEAR(tmp); |
| 9682 | arg = NULL; |
| 9683 | } |
| 9684 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9685 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9686 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9687 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9688 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9689 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9690 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9691 | return 1; |
| 9692 | } |
| 9693 | if (tmp == NULL) { |
| 9694 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 9695 | return 1; |
| 9696 | } |
| 9697 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9698 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9699 | res = obj2ast_expr(tmp, &value, arena); |
| 9700 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9701 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9702 | } |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 9703 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
| 9704 | return 1; |
| 9705 | } |
| 9706 | if (tmp == NULL) { |
| 9707 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword"); |
| 9708 | return 1; |
| 9709 | } |
| 9710 | else { |
| 9711 | int res; |
| 9712 | res = obj2ast_int(tmp, &lineno, arena); |
| 9713 | if (res != 0) goto failed; |
| 9714 | Py_CLEAR(tmp); |
| 9715 | } |
| 9716 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9717 | { |
| 9718 | return 1; |
| 9719 | } |
| 9720 | if (tmp == NULL) { |
| 9721 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword"); |
| 9722 | return 1; |
| 9723 | } |
| 9724 | else { |
| 9725 | int res; |
| 9726 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9727 | if (res != 0) goto failed; |
| 9728 | Py_CLEAR(tmp); |
| 9729 | } |
| 9730 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9731 | { |
| 9732 | return 1; |
| 9733 | } |
| 9734 | if (tmp == NULL || tmp == Py_None) { |
| 9735 | Py_CLEAR(tmp); |
| 9736 | end_lineno = 0; |
| 9737 | } |
| 9738 | else { |
| 9739 | int res; |
| 9740 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9741 | if (res != 0) goto failed; |
| 9742 | Py_CLEAR(tmp); |
| 9743 | } |
| 9744 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9745 | < 0) { |
| 9746 | return 1; |
| 9747 | } |
| 9748 | if (tmp == NULL || tmp == Py_None) { |
| 9749 | Py_CLEAR(tmp); |
| 9750 | end_col_offset = 0; |
| 9751 | } |
| 9752 | else { |
| 9753 | int res; |
| 9754 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9755 | if (res != 0) goto failed; |
| 9756 | Py_CLEAR(tmp); |
| 9757 | } |
| 9758 | *out = keyword(arg, value, lineno, col_offset, end_lineno, end_col_offset, |
| 9759 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9760 | return 0; |
| 9761 | failed: |
| 9762 | Py_XDECREF(tmp); |
| 9763 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9764 | } |
| 9765 | |
| 9766 | int |
| 9767 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 9768 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9769 | PyObject* tmp = NULL; |
| 9770 | identifier name; |
| 9771 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9772 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9773 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9774 | return 1; |
| 9775 | } |
| 9776 | if (tmp == NULL) { |
| 9777 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 9778 | return 1; |
| 9779 | } |
| 9780 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9781 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9782 | res = obj2ast_identifier(tmp, &name, arena); |
| 9783 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9784 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9785 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9786 | if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9787 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9788 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9789 | if (tmp == NULL || tmp == Py_None) { |
| 9790 | Py_CLEAR(tmp); |
| 9791 | asname = NULL; |
| 9792 | } |
| 9793 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9794 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9795 | res = obj2ast_identifier(tmp, &asname, arena); |
| 9796 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9797 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9798 | } |
| 9799 | *out = alias(name, asname, arena); |
| 9800 | return 0; |
| 9801 | failed: |
| 9802 | Py_XDECREF(tmp); |
| 9803 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9804 | } |
| 9805 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9806 | int |
| 9807 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 9808 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9809 | PyObject* tmp = NULL; |
| 9810 | expr_ty context_expr; |
| 9811 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9812 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9813 | if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) < |
| 9814 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9815 | return 1; |
| 9816 | } |
| 9817 | if (tmp == NULL) { |
| 9818 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 9819 | return 1; |
| 9820 | } |
| 9821 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9822 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9823 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 9824 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9825 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9826 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9827 | if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) < |
| 9828 | 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9829 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9830 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9831 | if (tmp == NULL || tmp == Py_None) { |
| 9832 | Py_CLEAR(tmp); |
| 9833 | optional_vars = NULL; |
| 9834 | } |
| 9835 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9836 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9837 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 9838 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9839 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9840 | } |
| 9841 | *out = withitem(context_expr, optional_vars, arena); |
| 9842 | return 0; |
| 9843 | failed: |
| 9844 | Py_XDECREF(tmp); |
| 9845 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9846 | } |
| 9847 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9848 | int |
| 9849 | obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) |
| 9850 | { |
| 9851 | int isinstance; |
| 9852 | |
| 9853 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9854 | PyObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9855 | |
| 9856 | if (obj == Py_None) { |
| 9857 | *out = NULL; |
| 9858 | return 0; |
| 9859 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9860 | tp = astmodulestate_global->TypeIgnore_type; |
| 9861 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9862 | if (isinstance == -1) { |
| 9863 | return 1; |
| 9864 | } |
| 9865 | if (isinstance) { |
| 9866 | int lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9867 | string tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9868 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9869 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) |
| 9870 | { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9871 | return 1; |
| 9872 | } |
| 9873 | if (tmp == NULL) { |
| 9874 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore"); |
| 9875 | return 1; |
| 9876 | } |
| 9877 | else { |
| 9878 | int res; |
| 9879 | res = obj2ast_int(tmp, &lineno, arena); |
| 9880 | if (res != 0) goto failed; |
| 9881 | Py_CLEAR(tmp); |
| 9882 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9883 | if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) { |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9884 | return 1; |
| 9885 | } |
| 9886 | if (tmp == NULL) { |
| 9887 | PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore"); |
| 9888 | return 1; |
| 9889 | } |
| 9890 | else { |
| 9891 | int res; |
| 9892 | res = obj2ast_string(tmp, &tag, arena); |
| 9893 | if (res != 0) goto failed; |
| 9894 | Py_CLEAR(tmp); |
| 9895 | } |
| 9896 | *out = TypeIgnore(lineno, tag, arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9897 | if (*out == NULL) goto failed; |
| 9898 | return 0; |
| 9899 | } |
| 9900 | |
| 9901 | PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj); |
| 9902 | failed: |
| 9903 | Py_XDECREF(tmp); |
| 9904 | return 1; |
| 9905 | } |
| 9906 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9907 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9908 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 9909 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9910 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9911 | PyObject *m; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9912 | if (!init_types()) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9913 | m = PyState_FindModule(&_astmodule); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9914 | if (!m) return NULL; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9915 | if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) { |
| 9916 | goto error; |
| 9917 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9918 | Py_INCREF(astmodulestate(m)->AST_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9919 | if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) { |
| 9920 | goto error; |
| 9921 | } |
| 9922 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) { |
| 9923 | goto error; |
| 9924 | } |
| 9925 | if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) { |
| 9926 | goto error; |
| 9927 | } |
| 9928 | if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) { |
| 9929 | goto error; |
| 9930 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9931 | Py_INCREF(astmodulestate(m)->mod_type); |
| 9932 | if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9933 | 0) { |
| 9934 | goto error; |
| 9935 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9936 | Py_INCREF(astmodulestate(m)->Module_type); |
| 9937 | if (PyModule_AddObject(m, "Interactive", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9938 | astmodulestate_global->Interactive_type) < 0) { |
| 9939 | goto error; |
| 9940 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9941 | Py_INCREF(astmodulestate(m)->Interactive_type); |
| 9942 | if (PyModule_AddObject(m, "Expression", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9943 | astmodulestate_global->Expression_type) < 0) { |
| 9944 | goto error; |
| 9945 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9946 | Py_INCREF(astmodulestate(m)->Expression_type); |
| 9947 | if (PyModule_AddObject(m, "FunctionType", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9948 | astmodulestate_global->FunctionType_type) < 0) { |
| 9949 | goto error; |
| 9950 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9951 | Py_INCREF(astmodulestate(m)->FunctionType_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9952 | if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) { |
| 9953 | goto error; |
| 9954 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9955 | Py_INCREF(astmodulestate(m)->stmt_type); |
| 9956 | if (PyModule_AddObject(m, "FunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9957 | astmodulestate_global->FunctionDef_type) < 0) { |
| 9958 | goto error; |
| 9959 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9960 | Py_INCREF(astmodulestate(m)->FunctionDef_type); |
| 9961 | if (PyModule_AddObject(m, "AsyncFunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9962 | astmodulestate_global->AsyncFunctionDef_type) < 0) { |
| 9963 | goto error; |
| 9964 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9965 | Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type); |
| 9966 | if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9967 | < 0) { |
| 9968 | goto error; |
| 9969 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9970 | Py_INCREF(astmodulestate(m)->ClassDef_type); |
| 9971 | if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9972 | 0) { |
| 9973 | goto error; |
| 9974 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9975 | Py_INCREF(astmodulestate(m)->Return_type); |
| 9976 | if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9977 | 0) { |
| 9978 | goto error; |
| 9979 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9980 | Py_INCREF(astmodulestate(m)->Delete_type); |
| 9981 | if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9982 | 0) { |
| 9983 | goto error; |
| 9984 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9985 | Py_INCREF(astmodulestate(m)->Assign_type); |
| 9986 | if (PyModule_AddObject(m, "AugAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9987 | astmodulestate_global->AugAssign_type) < 0) { |
| 9988 | goto error; |
| 9989 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9990 | Py_INCREF(astmodulestate(m)->AugAssign_type); |
| 9991 | if (PyModule_AddObject(m, "AnnAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9992 | astmodulestate_global->AnnAssign_type) < 0) { |
| 9993 | goto error; |
| 9994 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9995 | Py_INCREF(astmodulestate(m)->AnnAssign_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9996 | if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) { |
| 9997 | goto error; |
| 9998 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9999 | Py_INCREF(astmodulestate(m)->For_type); |
| 10000 | if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10001 | < 0) { |
| 10002 | goto error; |
| 10003 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10004 | Py_INCREF(astmodulestate(m)->AsyncFor_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10005 | if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) { |
| 10006 | goto error; |
| 10007 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10008 | Py_INCREF(astmodulestate(m)->While_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10009 | if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) { |
| 10010 | goto error; |
| 10011 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10012 | Py_INCREF(astmodulestate(m)->If_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10013 | if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) { |
| 10014 | goto error; |
| 10015 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10016 | Py_INCREF(astmodulestate(m)->With_type); |
| 10017 | if (PyModule_AddObject(m, "AsyncWith", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10018 | astmodulestate_global->AsyncWith_type) < 0) { |
| 10019 | goto error; |
| 10020 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10021 | Py_INCREF(astmodulestate(m)->AsyncWith_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10022 | if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) { |
| 10023 | goto error; |
| 10024 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10025 | Py_INCREF(astmodulestate(m)->Raise_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10026 | if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) { |
| 10027 | goto error; |
| 10028 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10029 | Py_INCREF(astmodulestate(m)->Try_type); |
| 10030 | if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10031 | 0) { |
| 10032 | goto error; |
| 10033 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10034 | Py_INCREF(astmodulestate(m)->Assert_type); |
| 10035 | if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10036 | 0) { |
| 10037 | goto error; |
| 10038 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10039 | Py_INCREF(astmodulestate(m)->Import_type); |
| 10040 | if (PyModule_AddObject(m, "ImportFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10041 | astmodulestate_global->ImportFrom_type) < 0) { |
| 10042 | goto error; |
| 10043 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10044 | Py_INCREF(astmodulestate(m)->ImportFrom_type); |
| 10045 | if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10046 | 0) { |
| 10047 | goto error; |
| 10048 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10049 | Py_INCREF(astmodulestate(m)->Global_type); |
| 10050 | if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10051 | < 0) { |
| 10052 | goto error; |
| 10053 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10054 | Py_INCREF(astmodulestate(m)->Nonlocal_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10055 | if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) { |
| 10056 | goto error; |
| 10057 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10058 | Py_INCREF(astmodulestate(m)->Expr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10059 | if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) { |
| 10060 | goto error; |
| 10061 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10062 | Py_INCREF(astmodulestate(m)->Pass_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10063 | if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) { |
| 10064 | goto error; |
| 10065 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10066 | Py_INCREF(astmodulestate(m)->Break_type); |
| 10067 | if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10068 | < 0) { |
| 10069 | goto error; |
| 10070 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10071 | Py_INCREF(astmodulestate(m)->Continue_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10072 | if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) { |
| 10073 | goto error; |
| 10074 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10075 | Py_INCREF(astmodulestate(m)->expr_type); |
| 10076 | if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10077 | 0) { |
| 10078 | goto error; |
| 10079 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10080 | Py_INCREF(astmodulestate(m)->BoolOp_type); |
| 10081 | if (PyModule_AddObject(m, "NamedExpr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10082 | astmodulestate_global->NamedExpr_type) < 0) { |
| 10083 | goto error; |
| 10084 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10085 | Py_INCREF(astmodulestate(m)->NamedExpr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10086 | if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) { |
| 10087 | goto error; |
| 10088 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10089 | Py_INCREF(astmodulestate(m)->BinOp_type); |
| 10090 | if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10091 | 0) { |
| 10092 | goto error; |
| 10093 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10094 | Py_INCREF(astmodulestate(m)->UnaryOp_type); |
| 10095 | if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10096 | 0) { |
| 10097 | goto error; |
| 10098 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10099 | Py_INCREF(astmodulestate(m)->Lambda_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10100 | if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) { |
| 10101 | goto error; |
| 10102 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10103 | Py_INCREF(astmodulestate(m)->IfExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10104 | if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) { |
| 10105 | goto error; |
| 10106 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10107 | Py_INCREF(astmodulestate(m)->Dict_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10108 | if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) { |
| 10109 | goto error; |
| 10110 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10111 | Py_INCREF(astmodulestate(m)->Set_type); |
| 10112 | if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10113 | < 0) { |
| 10114 | goto error; |
| 10115 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10116 | Py_INCREF(astmodulestate(m)->ListComp_type); |
| 10117 | if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10118 | 0) { |
| 10119 | goto error; |
| 10120 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10121 | Py_INCREF(astmodulestate(m)->SetComp_type); |
| 10122 | if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10123 | < 0) { |
| 10124 | goto error; |
| 10125 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10126 | Py_INCREF(astmodulestate(m)->DictComp_type); |
| 10127 | if (PyModule_AddObject(m, "GeneratorExp", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10128 | astmodulestate_global->GeneratorExp_type) < 0) { |
| 10129 | goto error; |
| 10130 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10131 | Py_INCREF(astmodulestate(m)->GeneratorExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10132 | if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) { |
| 10133 | goto error; |
| 10134 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10135 | Py_INCREF(astmodulestate(m)->Await_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10136 | if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) { |
| 10137 | goto error; |
| 10138 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10139 | Py_INCREF(astmodulestate(m)->Yield_type); |
| 10140 | if (PyModule_AddObject(m, "YieldFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10141 | astmodulestate_global->YieldFrom_type) < 0) { |
| 10142 | goto error; |
| 10143 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10144 | Py_INCREF(astmodulestate(m)->YieldFrom_type); |
| 10145 | if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10146 | 0) { |
| 10147 | goto error; |
| 10148 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10149 | Py_INCREF(astmodulestate(m)->Compare_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10150 | if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) { |
| 10151 | goto error; |
| 10152 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10153 | Py_INCREF(astmodulestate(m)->Call_type); |
| 10154 | if (PyModule_AddObject(m, "FormattedValue", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10155 | astmodulestate_global->FormattedValue_type) < 0) { |
| 10156 | goto error; |
| 10157 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10158 | Py_INCREF(astmodulestate(m)->FormattedValue_type); |
| 10159 | if (PyModule_AddObject(m, "JoinedStr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10160 | astmodulestate_global->JoinedStr_type) < 0) { |
| 10161 | goto error; |
| 10162 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10163 | Py_INCREF(astmodulestate(m)->JoinedStr_type); |
| 10164 | if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10165 | < 0) { |
| 10166 | goto error; |
| 10167 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10168 | Py_INCREF(astmodulestate(m)->Constant_type); |
| 10169 | if (PyModule_AddObject(m, "Attribute", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10170 | astmodulestate_global->Attribute_type) < 0) { |
| 10171 | goto error; |
| 10172 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10173 | Py_INCREF(astmodulestate(m)->Attribute_type); |
| 10174 | if (PyModule_AddObject(m, "Subscript", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10175 | astmodulestate_global->Subscript_type) < 0) { |
| 10176 | goto error; |
| 10177 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10178 | Py_INCREF(astmodulestate(m)->Subscript_type); |
| 10179 | if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10180 | 0) { |
| 10181 | goto error; |
| 10182 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10183 | Py_INCREF(astmodulestate(m)->Starred_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10184 | if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) { |
| 10185 | goto error; |
| 10186 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10187 | Py_INCREF(astmodulestate(m)->Name_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10188 | if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) { |
| 10189 | goto error; |
| 10190 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10191 | Py_INCREF(astmodulestate(m)->List_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10192 | if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) { |
| 10193 | goto error; |
| 10194 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10195 | Py_INCREF(astmodulestate(m)->Tuple_type); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 10196 | if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) { |
| 10197 | goto error; |
| 10198 | } |
| 10199 | Py_INCREF(astmodulestate(m)->Slice_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10200 | if (PyModule_AddObject(m, "expr_context", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10201 | astmodulestate_global->expr_context_type) < 0) { |
| 10202 | goto error; |
| 10203 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10204 | Py_INCREF(astmodulestate(m)->expr_context_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10205 | if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) { |
| 10206 | goto error; |
| 10207 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10208 | Py_INCREF(astmodulestate(m)->Load_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10209 | if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) { |
| 10210 | goto error; |
| 10211 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10212 | Py_INCREF(astmodulestate(m)->Store_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10213 | if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) { |
| 10214 | goto error; |
| 10215 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10216 | Py_INCREF(astmodulestate(m)->Del_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10217 | if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10218 | 0) { |
| 10219 | goto error; |
| 10220 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10221 | Py_INCREF(astmodulestate(m)->boolop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10222 | if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) { |
| 10223 | goto error; |
| 10224 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10225 | Py_INCREF(astmodulestate(m)->And_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10226 | if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) { |
| 10227 | goto error; |
| 10228 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10229 | Py_INCREF(astmodulestate(m)->Or_type); |
| 10230 | if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10231 | < 0) { |
| 10232 | goto error; |
| 10233 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10234 | Py_INCREF(astmodulestate(m)->operator_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10235 | if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) { |
| 10236 | goto error; |
| 10237 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10238 | Py_INCREF(astmodulestate(m)->Add_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10239 | if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) { |
| 10240 | goto error; |
| 10241 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10242 | Py_INCREF(astmodulestate(m)->Sub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10243 | if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) { |
| 10244 | goto error; |
| 10245 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10246 | Py_INCREF(astmodulestate(m)->Mult_type); |
| 10247 | if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10248 | 0) { |
| 10249 | goto error; |
| 10250 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10251 | Py_INCREF(astmodulestate(m)->MatMult_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10252 | if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) { |
| 10253 | goto error; |
| 10254 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10255 | Py_INCREF(astmodulestate(m)->Div_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10256 | if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) { |
| 10257 | goto error; |
| 10258 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10259 | Py_INCREF(astmodulestate(m)->Mod_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10260 | if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) { |
| 10261 | goto error; |
| 10262 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10263 | Py_INCREF(astmodulestate(m)->Pow_type); |
| 10264 | if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10265 | 0) { |
| 10266 | goto error; |
| 10267 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10268 | Py_INCREF(astmodulestate(m)->LShift_type); |
| 10269 | if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10270 | 0) { |
| 10271 | goto error; |
| 10272 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10273 | Py_INCREF(astmodulestate(m)->RShift_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10274 | if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) { |
| 10275 | goto error; |
| 10276 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10277 | Py_INCREF(astmodulestate(m)->BitOr_type); |
| 10278 | if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10279 | 0) { |
| 10280 | goto error; |
| 10281 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10282 | Py_INCREF(astmodulestate(m)->BitXor_type); |
| 10283 | if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10284 | 0) { |
| 10285 | goto error; |
| 10286 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10287 | Py_INCREF(astmodulestate(m)->BitAnd_type); |
| 10288 | if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10289 | < 0) { |
| 10290 | goto error; |
| 10291 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10292 | Py_INCREF(astmodulestate(m)->FloorDiv_type); |
| 10293 | if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10294 | 0) { |
| 10295 | goto error; |
| 10296 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10297 | Py_INCREF(astmodulestate(m)->unaryop_type); |
| 10298 | if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10299 | 0) { |
| 10300 | goto error; |
| 10301 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10302 | Py_INCREF(astmodulestate(m)->Invert_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10303 | if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) { |
| 10304 | goto error; |
| 10305 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10306 | Py_INCREF(astmodulestate(m)->Not_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10307 | if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) { |
| 10308 | goto error; |
| 10309 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10310 | Py_INCREF(astmodulestate(m)->UAdd_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10311 | if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) { |
| 10312 | goto error; |
| 10313 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10314 | Py_INCREF(astmodulestate(m)->USub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10315 | if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) { |
| 10316 | goto error; |
| 10317 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10318 | Py_INCREF(astmodulestate(m)->cmpop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10319 | if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) { |
| 10320 | goto error; |
| 10321 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10322 | Py_INCREF(astmodulestate(m)->Eq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10323 | if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) { |
| 10324 | goto error; |
| 10325 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10326 | Py_INCREF(astmodulestate(m)->NotEq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10327 | if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) { |
| 10328 | goto error; |
| 10329 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10330 | Py_INCREF(astmodulestate(m)->Lt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10331 | if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) { |
| 10332 | goto error; |
| 10333 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10334 | Py_INCREF(astmodulestate(m)->LtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10335 | if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) { |
| 10336 | goto error; |
| 10337 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10338 | Py_INCREF(astmodulestate(m)->Gt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10339 | if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) { |
| 10340 | goto error; |
| 10341 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10342 | Py_INCREF(astmodulestate(m)->GtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10343 | if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) { |
| 10344 | goto error; |
| 10345 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10346 | Py_INCREF(astmodulestate(m)->Is_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10347 | if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) { |
| 10348 | goto error; |
| 10349 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10350 | Py_INCREF(astmodulestate(m)->IsNot_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10351 | if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) { |
| 10352 | goto error; |
| 10353 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10354 | Py_INCREF(astmodulestate(m)->In_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10355 | if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) { |
| 10356 | goto error; |
| 10357 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10358 | Py_INCREF(astmodulestate(m)->NotIn_type); |
| 10359 | if (PyModule_AddObject(m, "comprehension", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10360 | astmodulestate_global->comprehension_type) < 0) { |
| 10361 | goto error; |
| 10362 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10363 | Py_INCREF(astmodulestate(m)->comprehension_type); |
| 10364 | if (PyModule_AddObject(m, "excepthandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10365 | astmodulestate_global->excepthandler_type) < 0) { |
| 10366 | goto error; |
| 10367 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10368 | Py_INCREF(astmodulestate(m)->excepthandler_type); |
| 10369 | if (PyModule_AddObject(m, "ExceptHandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10370 | astmodulestate_global->ExceptHandler_type) < 0) { |
| 10371 | goto error; |
| 10372 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10373 | Py_INCREF(astmodulestate(m)->ExceptHandler_type); |
| 10374 | if (PyModule_AddObject(m, "arguments", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10375 | astmodulestate_global->arguments_type) < 0) { |
| 10376 | goto error; |
| 10377 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10378 | Py_INCREF(astmodulestate(m)->arguments_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10379 | if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) { |
| 10380 | goto error; |
| 10381 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10382 | Py_INCREF(astmodulestate(m)->arg_type); |
| 10383 | if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10384 | 0) { |
| 10385 | goto error; |
| 10386 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10387 | Py_INCREF(astmodulestate(m)->keyword_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10388 | if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) { |
| 10389 | goto error; |
| 10390 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10391 | Py_INCREF(astmodulestate(m)->alias_type); |
| 10392 | if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10393 | < 0) { |
| 10394 | goto error; |
| 10395 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10396 | Py_INCREF(astmodulestate(m)->withitem_type); |
| 10397 | if (PyModule_AddObject(m, "type_ignore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10398 | astmodulestate_global->type_ignore_type) < 0) { |
| 10399 | goto error; |
| 10400 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10401 | Py_INCREF(astmodulestate(m)->type_ignore_type); |
| 10402 | if (PyModule_AddObject(m, "TypeIgnore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10403 | astmodulestate_global->TypeIgnore_type) < 0) { |
| 10404 | goto error; |
| 10405 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10406 | Py_INCREF(astmodulestate(m)->TypeIgnore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 10407 | return m; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10408 | error: |
| 10409 | Py_DECREF(m); |
| 10410 | return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 10411 | } |
| 10412 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10413 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10414 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10415 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10416 | if (!init_types()) |
| 10417 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10418 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10419 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10420 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10421 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 10422 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10423 | { |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 10424 | PyObject *req_type[3]; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 10425 | const char * const req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10426 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10427 | |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 10428 | if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { |
| 10429 | return NULL; |
| 10430 | } |
| 10431 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10432 | req_type[0] = astmodulestate_global->Module_type; |
| 10433 | req_type[1] = astmodulestate_global->Expression_type; |
| 10434 | req_type[2] = astmodulestate_global->Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10435 | |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 10436 | assert(0 <= mode && mode <= 2); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10437 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10438 | if (!init_types()) |
| 10439 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10440 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10441 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 10442 | if (isinstance == -1) |
| 10443 | return NULL; |
| 10444 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10445 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10446 | req_name[mode], _PyType_Name(Py_TYPE(ast))); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10447 | return NULL; |
| 10448 | } |
Dong-hee Na | a05fcd3 | 2019-10-10 16:41:26 +0900 | [diff] [blame] | 10449 | |
| 10450 | mod_ty res = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10451 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 10452 | return NULL; |
| 10453 | else |
| 10454 | return res; |
| 10455 | } |
| 10456 | |
| 10457 | int PyAST_Check(PyObject* obj) |
| 10458 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10459 | if (!init_types()) |
| 10460 | return -1; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10461 | return PyObject_IsInstance(obj, astmodulestate_global->AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10462 | } |
| 10463 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10464 | |