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" |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 7 | #include "structmember.h" |
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; |
| 24 | PyObject *AugLoad_singleton; |
| 25 | PyObject *AugLoad_type; |
| 26 | PyObject *AugStore_singleton; |
| 27 | PyObject *AugStore_type; |
| 28 | PyObject *Await_type; |
| 29 | PyObject *BinOp_type; |
| 30 | PyObject *BitAnd_singleton; |
| 31 | PyObject *BitAnd_type; |
| 32 | PyObject *BitOr_singleton; |
| 33 | PyObject *BitOr_type; |
| 34 | PyObject *BitXor_singleton; |
| 35 | PyObject *BitXor_type; |
| 36 | PyObject *BoolOp_type; |
| 37 | PyObject *Break_type; |
| 38 | PyObject *Call_type; |
| 39 | PyObject *ClassDef_type; |
| 40 | PyObject *Compare_type; |
| 41 | PyObject *Constant_type; |
| 42 | PyObject *Continue_type; |
| 43 | PyObject *Del_singleton; |
| 44 | PyObject *Del_type; |
| 45 | PyObject *Delete_type; |
| 46 | PyObject *DictComp_type; |
| 47 | PyObject *Dict_type; |
| 48 | PyObject *Div_singleton; |
| 49 | PyObject *Div_type; |
| 50 | PyObject *Eq_singleton; |
| 51 | PyObject *Eq_type; |
| 52 | PyObject *ExceptHandler_type; |
| 53 | PyObject *Expr_type; |
| 54 | PyObject *Expression_type; |
| 55 | PyObject *ExtSlice_type; |
| 56 | PyObject *FloorDiv_singleton; |
| 57 | PyObject *FloorDiv_type; |
| 58 | PyObject *For_type; |
| 59 | PyObject *FormattedValue_type; |
| 60 | PyObject *FunctionDef_type; |
| 61 | PyObject *FunctionType_type; |
| 62 | PyObject *GeneratorExp_type; |
| 63 | PyObject *Global_type; |
| 64 | PyObject *GtE_singleton; |
| 65 | PyObject *GtE_type; |
| 66 | PyObject *Gt_singleton; |
| 67 | PyObject *Gt_type; |
| 68 | PyObject *IfExp_type; |
| 69 | PyObject *If_type; |
| 70 | PyObject *ImportFrom_type; |
| 71 | PyObject *Import_type; |
| 72 | PyObject *In_singleton; |
| 73 | PyObject *In_type; |
| 74 | PyObject *Index_type; |
| 75 | PyObject *Interactive_type; |
| 76 | PyObject *Invert_singleton; |
| 77 | PyObject *Invert_type; |
| 78 | PyObject *IsNot_singleton; |
| 79 | PyObject *IsNot_type; |
| 80 | PyObject *Is_singleton; |
| 81 | PyObject *Is_type; |
| 82 | PyObject *JoinedStr_type; |
| 83 | PyObject *LShift_singleton; |
| 84 | PyObject *LShift_type; |
| 85 | PyObject *Lambda_type; |
| 86 | PyObject *ListComp_type; |
| 87 | PyObject *List_type; |
| 88 | PyObject *Load_singleton; |
| 89 | PyObject *Load_type; |
| 90 | PyObject *LtE_singleton; |
| 91 | PyObject *LtE_type; |
| 92 | PyObject *Lt_singleton; |
| 93 | PyObject *Lt_type; |
| 94 | PyObject *MatMult_singleton; |
| 95 | PyObject *MatMult_type; |
| 96 | PyObject *Mod_singleton; |
| 97 | PyObject *Mod_type; |
| 98 | PyObject *Module_type; |
| 99 | PyObject *Mult_singleton; |
| 100 | PyObject *Mult_type; |
| 101 | PyObject *Name_type; |
| 102 | PyObject *NamedExpr_type; |
| 103 | PyObject *Nonlocal_type; |
| 104 | PyObject *NotEq_singleton; |
| 105 | PyObject *NotEq_type; |
| 106 | PyObject *NotIn_singleton; |
| 107 | PyObject *NotIn_type; |
| 108 | PyObject *Not_singleton; |
| 109 | PyObject *Not_type; |
| 110 | PyObject *Or_singleton; |
| 111 | PyObject *Or_type; |
| 112 | PyObject *Param_singleton; |
| 113 | PyObject *Param_type; |
| 114 | PyObject *Pass_type; |
| 115 | PyObject *Pow_singleton; |
| 116 | PyObject *Pow_type; |
| 117 | PyObject *RShift_singleton; |
| 118 | PyObject *RShift_type; |
| 119 | PyObject *Raise_type; |
| 120 | PyObject *Return_type; |
| 121 | PyObject *SetComp_type; |
| 122 | PyObject *Set_type; |
| 123 | PyObject *Slice_type; |
| 124 | PyObject *Starred_type; |
| 125 | PyObject *Store_singleton; |
| 126 | PyObject *Store_type; |
| 127 | PyObject *Sub_singleton; |
| 128 | PyObject *Sub_type; |
| 129 | PyObject *Subscript_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 130 | PyObject *Try_type; |
| 131 | PyObject *Tuple_type; |
| 132 | PyObject *TypeIgnore_type; |
| 133 | PyObject *UAdd_singleton; |
| 134 | PyObject *UAdd_type; |
| 135 | PyObject *USub_singleton; |
| 136 | PyObject *USub_type; |
| 137 | PyObject *UnaryOp_type; |
| 138 | PyObject *While_type; |
| 139 | PyObject *With_type; |
| 140 | PyObject *YieldFrom_type; |
| 141 | PyObject *Yield_type; |
| 142 | PyObject *__dict__; |
| 143 | PyObject *__module__; |
| 144 | PyObject *_ast; |
| 145 | PyObject *_attributes; |
| 146 | PyObject *_fields; |
| 147 | PyObject *alias_type; |
| 148 | PyObject *annotation; |
| 149 | PyObject *arg; |
| 150 | PyObject *arg_type; |
| 151 | PyObject *args; |
| 152 | PyObject *argtypes; |
| 153 | PyObject *arguments_type; |
| 154 | PyObject *asname; |
| 155 | PyObject *attr; |
| 156 | PyObject *bases; |
| 157 | PyObject *body; |
| 158 | PyObject *boolop_type; |
| 159 | PyObject *cause; |
| 160 | PyObject *cmpop_type; |
| 161 | PyObject *col_offset; |
| 162 | PyObject *comparators; |
| 163 | PyObject *comprehension_type; |
| 164 | PyObject *context_expr; |
| 165 | PyObject *conversion; |
| 166 | PyObject *ctx; |
| 167 | PyObject *decorator_list; |
| 168 | PyObject *defaults; |
| 169 | PyObject *dims; |
| 170 | PyObject *elt; |
| 171 | PyObject *elts; |
| 172 | PyObject *end_col_offset; |
| 173 | PyObject *end_lineno; |
| 174 | PyObject *exc; |
| 175 | PyObject *excepthandler_type; |
| 176 | PyObject *expr_context_type; |
| 177 | PyObject *expr_type; |
| 178 | PyObject *finalbody; |
| 179 | PyObject *format_spec; |
| 180 | PyObject *func; |
| 181 | PyObject *generators; |
| 182 | PyObject *handlers; |
| 183 | PyObject *id; |
| 184 | PyObject *ifs; |
| 185 | PyObject *is_async; |
| 186 | PyObject *items; |
| 187 | PyObject *iter; |
| 188 | PyObject *key; |
| 189 | PyObject *keys; |
| 190 | PyObject *keyword_type; |
| 191 | PyObject *keywords; |
| 192 | PyObject *kind; |
| 193 | PyObject *kw_defaults; |
| 194 | PyObject *kwarg; |
| 195 | PyObject *kwonlyargs; |
| 196 | PyObject *left; |
| 197 | PyObject *level; |
| 198 | PyObject *lineno; |
| 199 | PyObject *lower; |
| 200 | PyObject *mod_type; |
| 201 | PyObject *module; |
| 202 | PyObject *msg; |
| 203 | PyObject *name; |
| 204 | PyObject *names; |
| 205 | PyObject *op; |
| 206 | PyObject *operand; |
| 207 | PyObject *operator_type; |
| 208 | PyObject *ops; |
| 209 | PyObject *optional_vars; |
| 210 | PyObject *orelse; |
| 211 | PyObject *posonlyargs; |
| 212 | PyObject *returns; |
| 213 | PyObject *right; |
| 214 | PyObject *simple; |
| 215 | PyObject *slice; |
| 216 | PyObject *slice_type; |
| 217 | PyObject *step; |
| 218 | PyObject *stmt_type; |
| 219 | PyObject *tag; |
| 220 | PyObject *target; |
| 221 | PyObject *targets; |
| 222 | PyObject *test; |
| 223 | PyObject *type; |
| 224 | PyObject *type_comment; |
| 225 | PyObject *type_ignore_type; |
| 226 | PyObject *type_ignores; |
| 227 | PyObject *unaryop_type; |
| 228 | PyObject *upper; |
| 229 | PyObject *value; |
| 230 | PyObject *values; |
| 231 | PyObject *vararg; |
| 232 | PyObject *withitem_type; |
| 233 | } astmodulestate; |
| 234 | |
| 235 | |
| 236 | #define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o)) |
| 237 | |
| 238 | static int astmodule_clear(PyObject *module) |
| 239 | { |
| 240 | Py_CLEAR(astmodulestate(module)->AST_type); |
| 241 | Py_CLEAR(astmodulestate(module)->Add_singleton); |
| 242 | Py_CLEAR(astmodulestate(module)->Add_type); |
| 243 | Py_CLEAR(astmodulestate(module)->And_singleton); |
| 244 | Py_CLEAR(astmodulestate(module)->And_type); |
| 245 | Py_CLEAR(astmodulestate(module)->AnnAssign_type); |
| 246 | Py_CLEAR(astmodulestate(module)->Assert_type); |
| 247 | Py_CLEAR(astmodulestate(module)->Assign_type); |
| 248 | Py_CLEAR(astmodulestate(module)->AsyncFor_type); |
| 249 | Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type); |
| 250 | Py_CLEAR(astmodulestate(module)->AsyncWith_type); |
| 251 | Py_CLEAR(astmodulestate(module)->Attribute_type); |
| 252 | Py_CLEAR(astmodulestate(module)->AugAssign_type); |
| 253 | Py_CLEAR(astmodulestate(module)->AugLoad_singleton); |
| 254 | Py_CLEAR(astmodulestate(module)->AugLoad_type); |
| 255 | Py_CLEAR(astmodulestate(module)->AugStore_singleton); |
| 256 | Py_CLEAR(astmodulestate(module)->AugStore_type); |
| 257 | Py_CLEAR(astmodulestate(module)->Await_type); |
| 258 | Py_CLEAR(astmodulestate(module)->BinOp_type); |
| 259 | Py_CLEAR(astmodulestate(module)->BitAnd_singleton); |
| 260 | Py_CLEAR(astmodulestate(module)->BitAnd_type); |
| 261 | Py_CLEAR(astmodulestate(module)->BitOr_singleton); |
| 262 | Py_CLEAR(astmodulestate(module)->BitOr_type); |
| 263 | Py_CLEAR(astmodulestate(module)->BitXor_singleton); |
| 264 | Py_CLEAR(astmodulestate(module)->BitXor_type); |
| 265 | Py_CLEAR(astmodulestate(module)->BoolOp_type); |
| 266 | Py_CLEAR(astmodulestate(module)->Break_type); |
| 267 | Py_CLEAR(astmodulestate(module)->Call_type); |
| 268 | Py_CLEAR(astmodulestate(module)->ClassDef_type); |
| 269 | Py_CLEAR(astmodulestate(module)->Compare_type); |
| 270 | Py_CLEAR(astmodulestate(module)->Constant_type); |
| 271 | Py_CLEAR(astmodulestate(module)->Continue_type); |
| 272 | Py_CLEAR(astmodulestate(module)->Del_singleton); |
| 273 | Py_CLEAR(astmodulestate(module)->Del_type); |
| 274 | Py_CLEAR(astmodulestate(module)->Delete_type); |
| 275 | Py_CLEAR(astmodulestate(module)->DictComp_type); |
| 276 | Py_CLEAR(astmodulestate(module)->Dict_type); |
| 277 | Py_CLEAR(astmodulestate(module)->Div_singleton); |
| 278 | Py_CLEAR(astmodulestate(module)->Div_type); |
| 279 | Py_CLEAR(astmodulestate(module)->Eq_singleton); |
| 280 | Py_CLEAR(astmodulestate(module)->Eq_type); |
| 281 | Py_CLEAR(astmodulestate(module)->ExceptHandler_type); |
| 282 | Py_CLEAR(astmodulestate(module)->Expr_type); |
| 283 | Py_CLEAR(astmodulestate(module)->Expression_type); |
| 284 | Py_CLEAR(astmodulestate(module)->ExtSlice_type); |
| 285 | Py_CLEAR(astmodulestate(module)->FloorDiv_singleton); |
| 286 | Py_CLEAR(astmodulestate(module)->FloorDiv_type); |
| 287 | Py_CLEAR(astmodulestate(module)->For_type); |
| 288 | Py_CLEAR(astmodulestate(module)->FormattedValue_type); |
| 289 | Py_CLEAR(astmodulestate(module)->FunctionDef_type); |
| 290 | Py_CLEAR(astmodulestate(module)->FunctionType_type); |
| 291 | Py_CLEAR(astmodulestate(module)->GeneratorExp_type); |
| 292 | Py_CLEAR(astmodulestate(module)->Global_type); |
| 293 | Py_CLEAR(astmodulestate(module)->GtE_singleton); |
| 294 | Py_CLEAR(astmodulestate(module)->GtE_type); |
| 295 | Py_CLEAR(astmodulestate(module)->Gt_singleton); |
| 296 | Py_CLEAR(astmodulestate(module)->Gt_type); |
| 297 | Py_CLEAR(astmodulestate(module)->IfExp_type); |
| 298 | Py_CLEAR(astmodulestate(module)->If_type); |
| 299 | Py_CLEAR(astmodulestate(module)->ImportFrom_type); |
| 300 | Py_CLEAR(astmodulestate(module)->Import_type); |
| 301 | Py_CLEAR(astmodulestate(module)->In_singleton); |
| 302 | Py_CLEAR(astmodulestate(module)->In_type); |
| 303 | Py_CLEAR(astmodulestate(module)->Index_type); |
| 304 | Py_CLEAR(astmodulestate(module)->Interactive_type); |
| 305 | Py_CLEAR(astmodulestate(module)->Invert_singleton); |
| 306 | Py_CLEAR(astmodulestate(module)->Invert_type); |
| 307 | Py_CLEAR(astmodulestate(module)->IsNot_singleton); |
| 308 | Py_CLEAR(astmodulestate(module)->IsNot_type); |
| 309 | Py_CLEAR(astmodulestate(module)->Is_singleton); |
| 310 | Py_CLEAR(astmodulestate(module)->Is_type); |
| 311 | Py_CLEAR(astmodulestate(module)->JoinedStr_type); |
| 312 | Py_CLEAR(astmodulestate(module)->LShift_singleton); |
| 313 | Py_CLEAR(astmodulestate(module)->LShift_type); |
| 314 | Py_CLEAR(astmodulestate(module)->Lambda_type); |
| 315 | Py_CLEAR(astmodulestate(module)->ListComp_type); |
| 316 | Py_CLEAR(astmodulestate(module)->List_type); |
| 317 | Py_CLEAR(astmodulestate(module)->Load_singleton); |
| 318 | Py_CLEAR(astmodulestate(module)->Load_type); |
| 319 | Py_CLEAR(astmodulestate(module)->LtE_singleton); |
| 320 | Py_CLEAR(astmodulestate(module)->LtE_type); |
| 321 | Py_CLEAR(astmodulestate(module)->Lt_singleton); |
| 322 | Py_CLEAR(astmodulestate(module)->Lt_type); |
| 323 | Py_CLEAR(astmodulestate(module)->MatMult_singleton); |
| 324 | Py_CLEAR(astmodulestate(module)->MatMult_type); |
| 325 | Py_CLEAR(astmodulestate(module)->Mod_singleton); |
| 326 | Py_CLEAR(astmodulestate(module)->Mod_type); |
| 327 | Py_CLEAR(astmodulestate(module)->Module_type); |
| 328 | Py_CLEAR(astmodulestate(module)->Mult_singleton); |
| 329 | Py_CLEAR(astmodulestate(module)->Mult_type); |
| 330 | Py_CLEAR(astmodulestate(module)->Name_type); |
| 331 | Py_CLEAR(astmodulestate(module)->NamedExpr_type); |
| 332 | Py_CLEAR(astmodulestate(module)->Nonlocal_type); |
| 333 | Py_CLEAR(astmodulestate(module)->NotEq_singleton); |
| 334 | Py_CLEAR(astmodulestate(module)->NotEq_type); |
| 335 | Py_CLEAR(astmodulestate(module)->NotIn_singleton); |
| 336 | Py_CLEAR(astmodulestate(module)->NotIn_type); |
| 337 | Py_CLEAR(astmodulestate(module)->Not_singleton); |
| 338 | Py_CLEAR(astmodulestate(module)->Not_type); |
| 339 | Py_CLEAR(astmodulestate(module)->Or_singleton); |
| 340 | Py_CLEAR(astmodulestate(module)->Or_type); |
| 341 | Py_CLEAR(astmodulestate(module)->Param_singleton); |
| 342 | Py_CLEAR(astmodulestate(module)->Param_type); |
| 343 | Py_CLEAR(astmodulestate(module)->Pass_type); |
| 344 | Py_CLEAR(astmodulestate(module)->Pow_singleton); |
| 345 | Py_CLEAR(astmodulestate(module)->Pow_type); |
| 346 | Py_CLEAR(astmodulestate(module)->RShift_singleton); |
| 347 | Py_CLEAR(astmodulestate(module)->RShift_type); |
| 348 | Py_CLEAR(astmodulestate(module)->Raise_type); |
| 349 | Py_CLEAR(astmodulestate(module)->Return_type); |
| 350 | Py_CLEAR(astmodulestate(module)->SetComp_type); |
| 351 | Py_CLEAR(astmodulestate(module)->Set_type); |
| 352 | Py_CLEAR(astmodulestate(module)->Slice_type); |
| 353 | Py_CLEAR(astmodulestate(module)->Starred_type); |
| 354 | Py_CLEAR(astmodulestate(module)->Store_singleton); |
| 355 | Py_CLEAR(astmodulestate(module)->Store_type); |
| 356 | Py_CLEAR(astmodulestate(module)->Sub_singleton); |
| 357 | Py_CLEAR(astmodulestate(module)->Sub_type); |
| 358 | Py_CLEAR(astmodulestate(module)->Subscript_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 359 | Py_CLEAR(astmodulestate(module)->Try_type); |
| 360 | Py_CLEAR(astmodulestate(module)->Tuple_type); |
| 361 | Py_CLEAR(astmodulestate(module)->TypeIgnore_type); |
| 362 | Py_CLEAR(astmodulestate(module)->UAdd_singleton); |
| 363 | Py_CLEAR(astmodulestate(module)->UAdd_type); |
| 364 | Py_CLEAR(astmodulestate(module)->USub_singleton); |
| 365 | Py_CLEAR(astmodulestate(module)->USub_type); |
| 366 | Py_CLEAR(astmodulestate(module)->UnaryOp_type); |
| 367 | Py_CLEAR(astmodulestate(module)->While_type); |
| 368 | Py_CLEAR(astmodulestate(module)->With_type); |
| 369 | Py_CLEAR(astmodulestate(module)->YieldFrom_type); |
| 370 | Py_CLEAR(astmodulestate(module)->Yield_type); |
| 371 | Py_CLEAR(astmodulestate(module)->__dict__); |
| 372 | Py_CLEAR(astmodulestate(module)->__module__); |
| 373 | Py_CLEAR(astmodulestate(module)->_ast); |
| 374 | Py_CLEAR(astmodulestate(module)->_attributes); |
| 375 | Py_CLEAR(astmodulestate(module)->_fields); |
| 376 | Py_CLEAR(astmodulestate(module)->alias_type); |
| 377 | Py_CLEAR(astmodulestate(module)->annotation); |
| 378 | Py_CLEAR(astmodulestate(module)->arg); |
| 379 | Py_CLEAR(astmodulestate(module)->arg_type); |
| 380 | Py_CLEAR(astmodulestate(module)->args); |
| 381 | Py_CLEAR(astmodulestate(module)->argtypes); |
| 382 | Py_CLEAR(astmodulestate(module)->arguments_type); |
| 383 | Py_CLEAR(astmodulestate(module)->asname); |
| 384 | Py_CLEAR(astmodulestate(module)->attr); |
| 385 | Py_CLEAR(astmodulestate(module)->bases); |
| 386 | Py_CLEAR(astmodulestate(module)->body); |
| 387 | Py_CLEAR(astmodulestate(module)->boolop_type); |
| 388 | Py_CLEAR(astmodulestate(module)->cause); |
| 389 | Py_CLEAR(astmodulestate(module)->cmpop_type); |
| 390 | Py_CLEAR(astmodulestate(module)->col_offset); |
| 391 | Py_CLEAR(astmodulestate(module)->comparators); |
| 392 | Py_CLEAR(astmodulestate(module)->comprehension_type); |
| 393 | Py_CLEAR(astmodulestate(module)->context_expr); |
| 394 | Py_CLEAR(astmodulestate(module)->conversion); |
| 395 | Py_CLEAR(astmodulestate(module)->ctx); |
| 396 | Py_CLEAR(astmodulestate(module)->decorator_list); |
| 397 | Py_CLEAR(astmodulestate(module)->defaults); |
| 398 | Py_CLEAR(astmodulestate(module)->dims); |
| 399 | Py_CLEAR(astmodulestate(module)->elt); |
| 400 | Py_CLEAR(astmodulestate(module)->elts); |
| 401 | Py_CLEAR(astmodulestate(module)->end_col_offset); |
| 402 | Py_CLEAR(astmodulestate(module)->end_lineno); |
| 403 | Py_CLEAR(astmodulestate(module)->exc); |
| 404 | Py_CLEAR(astmodulestate(module)->excepthandler_type); |
| 405 | Py_CLEAR(astmodulestate(module)->expr_context_type); |
| 406 | Py_CLEAR(astmodulestate(module)->expr_type); |
| 407 | Py_CLEAR(astmodulestate(module)->finalbody); |
| 408 | Py_CLEAR(astmodulestate(module)->format_spec); |
| 409 | Py_CLEAR(astmodulestate(module)->func); |
| 410 | Py_CLEAR(astmodulestate(module)->generators); |
| 411 | Py_CLEAR(astmodulestate(module)->handlers); |
| 412 | Py_CLEAR(astmodulestate(module)->id); |
| 413 | Py_CLEAR(astmodulestate(module)->ifs); |
| 414 | Py_CLEAR(astmodulestate(module)->is_async); |
| 415 | Py_CLEAR(astmodulestate(module)->items); |
| 416 | Py_CLEAR(astmodulestate(module)->iter); |
| 417 | Py_CLEAR(astmodulestate(module)->key); |
| 418 | Py_CLEAR(astmodulestate(module)->keys); |
| 419 | Py_CLEAR(astmodulestate(module)->keyword_type); |
| 420 | Py_CLEAR(astmodulestate(module)->keywords); |
| 421 | Py_CLEAR(astmodulestate(module)->kind); |
| 422 | Py_CLEAR(astmodulestate(module)->kw_defaults); |
| 423 | Py_CLEAR(astmodulestate(module)->kwarg); |
| 424 | Py_CLEAR(astmodulestate(module)->kwonlyargs); |
| 425 | Py_CLEAR(astmodulestate(module)->left); |
| 426 | Py_CLEAR(astmodulestate(module)->level); |
| 427 | Py_CLEAR(astmodulestate(module)->lineno); |
| 428 | Py_CLEAR(astmodulestate(module)->lower); |
| 429 | Py_CLEAR(astmodulestate(module)->mod_type); |
| 430 | Py_CLEAR(astmodulestate(module)->module); |
| 431 | Py_CLEAR(astmodulestate(module)->msg); |
| 432 | Py_CLEAR(astmodulestate(module)->name); |
| 433 | Py_CLEAR(astmodulestate(module)->names); |
| 434 | Py_CLEAR(astmodulestate(module)->op); |
| 435 | Py_CLEAR(astmodulestate(module)->operand); |
| 436 | Py_CLEAR(astmodulestate(module)->operator_type); |
| 437 | Py_CLEAR(astmodulestate(module)->ops); |
| 438 | Py_CLEAR(astmodulestate(module)->optional_vars); |
| 439 | Py_CLEAR(astmodulestate(module)->orelse); |
| 440 | Py_CLEAR(astmodulestate(module)->posonlyargs); |
| 441 | Py_CLEAR(astmodulestate(module)->returns); |
| 442 | Py_CLEAR(astmodulestate(module)->right); |
| 443 | Py_CLEAR(astmodulestate(module)->simple); |
| 444 | Py_CLEAR(astmodulestate(module)->slice); |
| 445 | Py_CLEAR(astmodulestate(module)->slice_type); |
| 446 | Py_CLEAR(astmodulestate(module)->step); |
| 447 | Py_CLEAR(astmodulestate(module)->stmt_type); |
| 448 | Py_CLEAR(astmodulestate(module)->tag); |
| 449 | Py_CLEAR(astmodulestate(module)->target); |
| 450 | Py_CLEAR(astmodulestate(module)->targets); |
| 451 | Py_CLEAR(astmodulestate(module)->test); |
| 452 | Py_CLEAR(astmodulestate(module)->type); |
| 453 | Py_CLEAR(astmodulestate(module)->type_comment); |
| 454 | Py_CLEAR(astmodulestate(module)->type_ignore_type); |
| 455 | Py_CLEAR(astmodulestate(module)->type_ignores); |
| 456 | Py_CLEAR(astmodulestate(module)->unaryop_type); |
| 457 | Py_CLEAR(astmodulestate(module)->upper); |
| 458 | Py_CLEAR(astmodulestate(module)->value); |
| 459 | Py_CLEAR(astmodulestate(module)->values); |
| 460 | Py_CLEAR(astmodulestate(module)->vararg); |
| 461 | Py_CLEAR(astmodulestate(module)->withitem_type); |
| 462 | |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | static int astmodule_traverse(PyObject *module, visitproc visit, void* arg) |
| 467 | { |
| 468 | Py_VISIT(astmodulestate(module)->AST_type); |
| 469 | Py_VISIT(astmodulestate(module)->Add_singleton); |
| 470 | Py_VISIT(astmodulestate(module)->Add_type); |
| 471 | Py_VISIT(astmodulestate(module)->And_singleton); |
| 472 | Py_VISIT(astmodulestate(module)->And_type); |
| 473 | Py_VISIT(astmodulestate(module)->AnnAssign_type); |
| 474 | Py_VISIT(astmodulestate(module)->Assert_type); |
| 475 | Py_VISIT(astmodulestate(module)->Assign_type); |
| 476 | Py_VISIT(astmodulestate(module)->AsyncFor_type); |
| 477 | Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type); |
| 478 | Py_VISIT(astmodulestate(module)->AsyncWith_type); |
| 479 | Py_VISIT(astmodulestate(module)->Attribute_type); |
| 480 | Py_VISIT(astmodulestate(module)->AugAssign_type); |
| 481 | Py_VISIT(astmodulestate(module)->AugLoad_singleton); |
| 482 | Py_VISIT(astmodulestate(module)->AugLoad_type); |
| 483 | Py_VISIT(astmodulestate(module)->AugStore_singleton); |
| 484 | Py_VISIT(astmodulestate(module)->AugStore_type); |
| 485 | Py_VISIT(astmodulestate(module)->Await_type); |
| 486 | Py_VISIT(astmodulestate(module)->BinOp_type); |
| 487 | Py_VISIT(astmodulestate(module)->BitAnd_singleton); |
| 488 | Py_VISIT(astmodulestate(module)->BitAnd_type); |
| 489 | Py_VISIT(astmodulestate(module)->BitOr_singleton); |
| 490 | Py_VISIT(astmodulestate(module)->BitOr_type); |
| 491 | Py_VISIT(astmodulestate(module)->BitXor_singleton); |
| 492 | Py_VISIT(astmodulestate(module)->BitXor_type); |
| 493 | Py_VISIT(astmodulestate(module)->BoolOp_type); |
| 494 | Py_VISIT(astmodulestate(module)->Break_type); |
| 495 | Py_VISIT(astmodulestate(module)->Call_type); |
| 496 | Py_VISIT(astmodulestate(module)->ClassDef_type); |
| 497 | Py_VISIT(astmodulestate(module)->Compare_type); |
| 498 | Py_VISIT(astmodulestate(module)->Constant_type); |
| 499 | Py_VISIT(astmodulestate(module)->Continue_type); |
| 500 | Py_VISIT(astmodulestate(module)->Del_singleton); |
| 501 | Py_VISIT(astmodulestate(module)->Del_type); |
| 502 | Py_VISIT(astmodulestate(module)->Delete_type); |
| 503 | Py_VISIT(astmodulestate(module)->DictComp_type); |
| 504 | Py_VISIT(astmodulestate(module)->Dict_type); |
| 505 | Py_VISIT(astmodulestate(module)->Div_singleton); |
| 506 | Py_VISIT(astmodulestate(module)->Div_type); |
| 507 | Py_VISIT(astmodulestate(module)->Eq_singleton); |
| 508 | Py_VISIT(astmodulestate(module)->Eq_type); |
| 509 | Py_VISIT(astmodulestate(module)->ExceptHandler_type); |
| 510 | Py_VISIT(astmodulestate(module)->Expr_type); |
| 511 | Py_VISIT(astmodulestate(module)->Expression_type); |
| 512 | Py_VISIT(astmodulestate(module)->ExtSlice_type); |
| 513 | Py_VISIT(astmodulestate(module)->FloorDiv_singleton); |
| 514 | Py_VISIT(astmodulestate(module)->FloorDiv_type); |
| 515 | Py_VISIT(astmodulestate(module)->For_type); |
| 516 | Py_VISIT(astmodulestate(module)->FormattedValue_type); |
| 517 | Py_VISIT(astmodulestate(module)->FunctionDef_type); |
| 518 | Py_VISIT(astmodulestate(module)->FunctionType_type); |
| 519 | Py_VISIT(astmodulestate(module)->GeneratorExp_type); |
| 520 | Py_VISIT(astmodulestate(module)->Global_type); |
| 521 | Py_VISIT(astmodulestate(module)->GtE_singleton); |
| 522 | Py_VISIT(astmodulestate(module)->GtE_type); |
| 523 | Py_VISIT(astmodulestate(module)->Gt_singleton); |
| 524 | Py_VISIT(astmodulestate(module)->Gt_type); |
| 525 | Py_VISIT(astmodulestate(module)->IfExp_type); |
| 526 | Py_VISIT(astmodulestate(module)->If_type); |
| 527 | Py_VISIT(astmodulestate(module)->ImportFrom_type); |
| 528 | Py_VISIT(astmodulestate(module)->Import_type); |
| 529 | Py_VISIT(astmodulestate(module)->In_singleton); |
| 530 | Py_VISIT(astmodulestate(module)->In_type); |
| 531 | Py_VISIT(astmodulestate(module)->Index_type); |
| 532 | Py_VISIT(astmodulestate(module)->Interactive_type); |
| 533 | Py_VISIT(astmodulestate(module)->Invert_singleton); |
| 534 | Py_VISIT(astmodulestate(module)->Invert_type); |
| 535 | Py_VISIT(astmodulestate(module)->IsNot_singleton); |
| 536 | Py_VISIT(astmodulestate(module)->IsNot_type); |
| 537 | Py_VISIT(astmodulestate(module)->Is_singleton); |
| 538 | Py_VISIT(astmodulestate(module)->Is_type); |
| 539 | Py_VISIT(astmodulestate(module)->JoinedStr_type); |
| 540 | Py_VISIT(astmodulestate(module)->LShift_singleton); |
| 541 | Py_VISIT(astmodulestate(module)->LShift_type); |
| 542 | Py_VISIT(astmodulestate(module)->Lambda_type); |
| 543 | Py_VISIT(astmodulestate(module)->ListComp_type); |
| 544 | Py_VISIT(astmodulestate(module)->List_type); |
| 545 | Py_VISIT(astmodulestate(module)->Load_singleton); |
| 546 | Py_VISIT(astmodulestate(module)->Load_type); |
| 547 | Py_VISIT(astmodulestate(module)->LtE_singleton); |
| 548 | Py_VISIT(astmodulestate(module)->LtE_type); |
| 549 | Py_VISIT(astmodulestate(module)->Lt_singleton); |
| 550 | Py_VISIT(astmodulestate(module)->Lt_type); |
| 551 | Py_VISIT(astmodulestate(module)->MatMult_singleton); |
| 552 | Py_VISIT(astmodulestate(module)->MatMult_type); |
| 553 | Py_VISIT(astmodulestate(module)->Mod_singleton); |
| 554 | Py_VISIT(astmodulestate(module)->Mod_type); |
| 555 | Py_VISIT(astmodulestate(module)->Module_type); |
| 556 | Py_VISIT(astmodulestate(module)->Mult_singleton); |
| 557 | Py_VISIT(astmodulestate(module)->Mult_type); |
| 558 | Py_VISIT(astmodulestate(module)->Name_type); |
| 559 | Py_VISIT(astmodulestate(module)->NamedExpr_type); |
| 560 | Py_VISIT(astmodulestate(module)->Nonlocal_type); |
| 561 | Py_VISIT(astmodulestate(module)->NotEq_singleton); |
| 562 | Py_VISIT(astmodulestate(module)->NotEq_type); |
| 563 | Py_VISIT(astmodulestate(module)->NotIn_singleton); |
| 564 | Py_VISIT(astmodulestate(module)->NotIn_type); |
| 565 | Py_VISIT(astmodulestate(module)->Not_singleton); |
| 566 | Py_VISIT(astmodulestate(module)->Not_type); |
| 567 | Py_VISIT(astmodulestate(module)->Or_singleton); |
| 568 | Py_VISIT(astmodulestate(module)->Or_type); |
| 569 | Py_VISIT(astmodulestate(module)->Param_singleton); |
| 570 | Py_VISIT(astmodulestate(module)->Param_type); |
| 571 | Py_VISIT(astmodulestate(module)->Pass_type); |
| 572 | Py_VISIT(astmodulestate(module)->Pow_singleton); |
| 573 | Py_VISIT(astmodulestate(module)->Pow_type); |
| 574 | Py_VISIT(astmodulestate(module)->RShift_singleton); |
| 575 | Py_VISIT(astmodulestate(module)->RShift_type); |
| 576 | Py_VISIT(astmodulestate(module)->Raise_type); |
| 577 | Py_VISIT(astmodulestate(module)->Return_type); |
| 578 | Py_VISIT(astmodulestate(module)->SetComp_type); |
| 579 | Py_VISIT(astmodulestate(module)->Set_type); |
| 580 | Py_VISIT(astmodulestate(module)->Slice_type); |
| 581 | Py_VISIT(astmodulestate(module)->Starred_type); |
| 582 | Py_VISIT(astmodulestate(module)->Store_singleton); |
| 583 | Py_VISIT(astmodulestate(module)->Store_type); |
| 584 | Py_VISIT(astmodulestate(module)->Sub_singleton); |
| 585 | Py_VISIT(astmodulestate(module)->Sub_type); |
| 586 | Py_VISIT(astmodulestate(module)->Subscript_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 587 | Py_VISIT(astmodulestate(module)->Try_type); |
| 588 | Py_VISIT(astmodulestate(module)->Tuple_type); |
| 589 | Py_VISIT(astmodulestate(module)->TypeIgnore_type); |
| 590 | Py_VISIT(astmodulestate(module)->UAdd_singleton); |
| 591 | Py_VISIT(astmodulestate(module)->UAdd_type); |
| 592 | Py_VISIT(astmodulestate(module)->USub_singleton); |
| 593 | Py_VISIT(astmodulestate(module)->USub_type); |
| 594 | Py_VISIT(astmodulestate(module)->UnaryOp_type); |
| 595 | Py_VISIT(astmodulestate(module)->While_type); |
| 596 | Py_VISIT(astmodulestate(module)->With_type); |
| 597 | Py_VISIT(astmodulestate(module)->YieldFrom_type); |
| 598 | Py_VISIT(astmodulestate(module)->Yield_type); |
| 599 | Py_VISIT(astmodulestate(module)->__dict__); |
| 600 | Py_VISIT(astmodulestate(module)->__module__); |
| 601 | Py_VISIT(astmodulestate(module)->_ast); |
| 602 | Py_VISIT(astmodulestate(module)->_attributes); |
| 603 | Py_VISIT(astmodulestate(module)->_fields); |
| 604 | Py_VISIT(astmodulestate(module)->alias_type); |
| 605 | Py_VISIT(astmodulestate(module)->annotation); |
| 606 | Py_VISIT(astmodulestate(module)->arg); |
| 607 | Py_VISIT(astmodulestate(module)->arg_type); |
| 608 | Py_VISIT(astmodulestate(module)->args); |
| 609 | Py_VISIT(astmodulestate(module)->argtypes); |
| 610 | Py_VISIT(astmodulestate(module)->arguments_type); |
| 611 | Py_VISIT(astmodulestate(module)->asname); |
| 612 | Py_VISIT(astmodulestate(module)->attr); |
| 613 | Py_VISIT(astmodulestate(module)->bases); |
| 614 | Py_VISIT(astmodulestate(module)->body); |
| 615 | Py_VISIT(astmodulestate(module)->boolop_type); |
| 616 | Py_VISIT(astmodulestate(module)->cause); |
| 617 | Py_VISIT(astmodulestate(module)->cmpop_type); |
| 618 | Py_VISIT(astmodulestate(module)->col_offset); |
| 619 | Py_VISIT(astmodulestate(module)->comparators); |
| 620 | Py_VISIT(astmodulestate(module)->comprehension_type); |
| 621 | Py_VISIT(astmodulestate(module)->context_expr); |
| 622 | Py_VISIT(astmodulestate(module)->conversion); |
| 623 | Py_VISIT(astmodulestate(module)->ctx); |
| 624 | Py_VISIT(astmodulestate(module)->decorator_list); |
| 625 | Py_VISIT(astmodulestate(module)->defaults); |
| 626 | Py_VISIT(astmodulestate(module)->dims); |
| 627 | Py_VISIT(astmodulestate(module)->elt); |
| 628 | Py_VISIT(astmodulestate(module)->elts); |
| 629 | Py_VISIT(astmodulestate(module)->end_col_offset); |
| 630 | Py_VISIT(astmodulestate(module)->end_lineno); |
| 631 | Py_VISIT(astmodulestate(module)->exc); |
| 632 | Py_VISIT(astmodulestate(module)->excepthandler_type); |
| 633 | Py_VISIT(astmodulestate(module)->expr_context_type); |
| 634 | Py_VISIT(astmodulestate(module)->expr_type); |
| 635 | Py_VISIT(astmodulestate(module)->finalbody); |
| 636 | Py_VISIT(astmodulestate(module)->format_spec); |
| 637 | Py_VISIT(astmodulestate(module)->func); |
| 638 | Py_VISIT(astmodulestate(module)->generators); |
| 639 | Py_VISIT(astmodulestate(module)->handlers); |
| 640 | Py_VISIT(astmodulestate(module)->id); |
| 641 | Py_VISIT(astmodulestate(module)->ifs); |
| 642 | Py_VISIT(astmodulestate(module)->is_async); |
| 643 | Py_VISIT(astmodulestate(module)->items); |
| 644 | Py_VISIT(astmodulestate(module)->iter); |
| 645 | Py_VISIT(astmodulestate(module)->key); |
| 646 | Py_VISIT(astmodulestate(module)->keys); |
| 647 | Py_VISIT(astmodulestate(module)->keyword_type); |
| 648 | Py_VISIT(astmodulestate(module)->keywords); |
| 649 | Py_VISIT(astmodulestate(module)->kind); |
| 650 | Py_VISIT(astmodulestate(module)->kw_defaults); |
| 651 | Py_VISIT(astmodulestate(module)->kwarg); |
| 652 | Py_VISIT(astmodulestate(module)->kwonlyargs); |
| 653 | Py_VISIT(astmodulestate(module)->left); |
| 654 | Py_VISIT(astmodulestate(module)->level); |
| 655 | Py_VISIT(astmodulestate(module)->lineno); |
| 656 | Py_VISIT(astmodulestate(module)->lower); |
| 657 | Py_VISIT(astmodulestate(module)->mod_type); |
| 658 | Py_VISIT(astmodulestate(module)->module); |
| 659 | Py_VISIT(astmodulestate(module)->msg); |
| 660 | Py_VISIT(astmodulestate(module)->name); |
| 661 | Py_VISIT(astmodulestate(module)->names); |
| 662 | Py_VISIT(astmodulestate(module)->op); |
| 663 | Py_VISIT(astmodulestate(module)->operand); |
| 664 | Py_VISIT(astmodulestate(module)->operator_type); |
| 665 | Py_VISIT(astmodulestate(module)->ops); |
| 666 | Py_VISIT(astmodulestate(module)->optional_vars); |
| 667 | Py_VISIT(astmodulestate(module)->orelse); |
| 668 | Py_VISIT(astmodulestate(module)->posonlyargs); |
| 669 | Py_VISIT(astmodulestate(module)->returns); |
| 670 | Py_VISIT(astmodulestate(module)->right); |
| 671 | Py_VISIT(astmodulestate(module)->simple); |
| 672 | Py_VISIT(astmodulestate(module)->slice); |
| 673 | Py_VISIT(astmodulestate(module)->slice_type); |
| 674 | Py_VISIT(astmodulestate(module)->step); |
| 675 | Py_VISIT(astmodulestate(module)->stmt_type); |
| 676 | Py_VISIT(astmodulestate(module)->tag); |
| 677 | Py_VISIT(astmodulestate(module)->target); |
| 678 | Py_VISIT(astmodulestate(module)->targets); |
| 679 | Py_VISIT(astmodulestate(module)->test); |
| 680 | Py_VISIT(astmodulestate(module)->type); |
| 681 | Py_VISIT(astmodulestate(module)->type_comment); |
| 682 | Py_VISIT(astmodulestate(module)->type_ignore_type); |
| 683 | Py_VISIT(astmodulestate(module)->type_ignores); |
| 684 | Py_VISIT(astmodulestate(module)->unaryop_type); |
| 685 | Py_VISIT(astmodulestate(module)->upper); |
| 686 | Py_VISIT(astmodulestate(module)->value); |
| 687 | Py_VISIT(astmodulestate(module)->values); |
| 688 | Py_VISIT(astmodulestate(module)->vararg); |
| 689 | Py_VISIT(astmodulestate(module)->withitem_type); |
| 690 | |
| 691 | return 0; |
| 692 | } |
| 693 | |
| 694 | static void astmodule_free(void* module) { |
| 695 | astmodule_clear((PyObject*)module); |
| 696 | } |
| 697 | |
| 698 | static struct PyModuleDef _astmodule = { |
| 699 | PyModuleDef_HEAD_INIT, |
| 700 | "_ast", |
| 701 | NULL, |
| 702 | sizeof(astmodulestate), |
| 703 | NULL, |
| 704 | NULL, |
| 705 | astmodule_traverse, |
| 706 | astmodule_clear, |
| 707 | astmodule_free, |
| 708 | }; |
| 709 | |
| 710 | #define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule))) |
| 711 | |
| 712 | static int init_identifiers(void) |
| 713 | { |
| 714 | astmodulestate *state = astmodulestate_global; |
| 715 | if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0; |
| 716 | if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0; |
| 717 | if ((state->_ast = PyUnicode_InternFromString("_ast")) == NULL) return 0; |
| 718 | if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0; |
| 719 | if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0; |
| 720 | if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0; |
| 721 | if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0; |
| 722 | if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0; |
| 723 | if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0; |
| 724 | if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0; |
| 725 | if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0; |
| 726 | if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0; |
| 727 | if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0; |
| 728 | if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0; |
| 729 | if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0; |
| 730 | if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0; |
| 731 | if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0; |
| 732 | if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0; |
| 733 | if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0; |
| 734 | if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0; |
| 735 | if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0; |
| 736 | if ((state->dims = PyUnicode_InternFromString("dims")) == NULL) return 0; |
| 737 | if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0; |
| 738 | if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0; |
| 739 | if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0; |
| 740 | if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0; |
| 741 | if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0; |
| 742 | if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0; |
| 743 | if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0; |
| 744 | if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0; |
| 745 | if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0; |
| 746 | if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0; |
| 747 | if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0; |
| 748 | if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0; |
| 749 | if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0; |
| 750 | if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0; |
| 751 | if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0; |
| 752 | if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0; |
| 753 | if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0; |
| 754 | if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0; |
| 755 | if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0; |
| 756 | if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0; |
| 757 | if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0; |
| 758 | if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0; |
| 759 | if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0; |
| 760 | if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0; |
| 761 | if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0; |
| 762 | if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0; |
| 763 | if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0; |
| 764 | if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0; |
| 765 | if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0; |
| 766 | if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0; |
| 767 | if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0; |
| 768 | if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0; |
| 769 | if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0; |
| 770 | if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0; |
| 771 | if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0; |
| 772 | if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0; |
| 773 | if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0; |
| 774 | if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0; |
| 775 | if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0; |
| 776 | if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0; |
| 777 | if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0; |
| 778 | if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0; |
| 779 | if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0; |
| 780 | if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0; |
| 781 | if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0; |
| 782 | if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0; |
| 783 | if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0; |
| 784 | if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0; |
| 785 | if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0; |
| 786 | if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0; |
| 787 | if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0; |
| 788 | if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0; |
| 789 | return 1; |
| 790 | }; |
| 791 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 792 | static PyObject* ast2obj_mod(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 793 | static const char * const Module_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 794 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 795 | "type_ignores", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 796 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 797 | static const char * const Interactive_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 798 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 799 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 800 | static const char * const Expression_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 801 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 802 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 803 | static const char * const FunctionType_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 804 | "argtypes", |
| 805 | "returns", |
| 806 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 807 | static const char * const stmt_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 808 | "lineno", |
| 809 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 810 | "end_lineno", |
| 811 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 812 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 813 | static PyObject* ast2obj_stmt(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 814 | static const char * const FunctionDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 815 | "name", |
| 816 | "args", |
| 817 | "body", |
| 818 | "decorator_list", |
| 819 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 820 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 821 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 822 | static const char * const AsyncFunctionDef_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 823 | "name", |
| 824 | "args", |
| 825 | "body", |
| 826 | "decorator_list", |
| 827 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 828 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 829 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 830 | static const char * const ClassDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 831 | "name", |
| 832 | "bases", |
| 833 | "keywords", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 834 | "body", |
| 835 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 836 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 837 | static const char * const Return_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 838 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 839 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 840 | static const char * const Delete_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 841 | "targets", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 842 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 843 | static const char * const Assign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 844 | "targets", |
| 845 | "value", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 846 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 847 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 848 | static const char * const AugAssign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 849 | "target", |
| 850 | "op", |
| 851 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 852 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 853 | static const char * const AnnAssign_fields[]={ |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 854 | "target", |
| 855 | "annotation", |
| 856 | "value", |
| 857 | "simple", |
| 858 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 859 | static const char * const For_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 860 | "target", |
| 861 | "iter", |
| 862 | "body", |
| 863 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 864 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 865 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 866 | static const char * const AsyncFor_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 867 | "target", |
| 868 | "iter", |
| 869 | "body", |
| 870 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 871 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 872 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 873 | static const char * const While_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 874 | "test", |
| 875 | "body", |
| 876 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 877 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 878 | static const char * const If_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 879 | "test", |
| 880 | "body", |
| 881 | "orelse", |
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 With_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 884 | "items", |
| 885 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 886 | "type_comment", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 887 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 888 | static const char * const AsyncWith_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 889 | "items", |
| 890 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 891 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 892 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 893 | static const char * const Raise_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 894 | "exc", |
| 895 | "cause", |
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 Try_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 898 | "body", |
| 899 | "handlers", |
| 900 | "orelse", |
| 901 | "finalbody", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 902 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 903 | static const char * const Assert_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 904 | "test", |
| 905 | "msg", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 906 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 907 | static const char * const Import_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 908 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 909 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 910 | static const char * const ImportFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 911 | "module", |
| 912 | "names", |
| 913 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 914 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 915 | static const char * const Global_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 916 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 917 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 918 | static const char * const Nonlocal_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 919 | "names", |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 920 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 921 | static const char * const Expr_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 922 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 923 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 924 | static const char * const expr_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 925 | "lineno", |
| 926 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 927 | "end_lineno", |
| 928 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 929 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 930 | static PyObject* ast2obj_expr(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 931 | static const char * const BoolOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 932 | "op", |
| 933 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 934 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 935 | static const char * const NamedExpr_fields[]={ |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 936 | "target", |
| 937 | "value", |
| 938 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 939 | static const char * const BinOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 940 | "left", |
| 941 | "op", |
| 942 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 943 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 944 | static const char * const UnaryOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 945 | "op", |
| 946 | "operand", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 947 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 948 | static const char * const Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 949 | "args", |
| 950 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 951 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 952 | static const char * const IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 953 | "test", |
| 954 | "body", |
| 955 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 956 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 957 | static const char * const Dict_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 958 | "keys", |
| 959 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 960 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 961 | static const char * const Set_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 962 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 963 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 964 | static const char * const ListComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 965 | "elt", |
| 966 | "generators", |
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 SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 969 | "elt", |
| 970 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 971 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 972 | static const char * const DictComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 973 | "key", |
| 974 | "value", |
| 975 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 976 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 977 | static const char * const GeneratorExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 978 | "elt", |
| 979 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 980 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 981 | static const char * const Await_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 982 | "value", |
| 983 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 984 | static const char * const Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 985 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 986 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 987 | static const char * const YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 988 | "value", |
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 Compare_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 991 | "left", |
| 992 | "ops", |
| 993 | "comparators", |
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 Call_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 996 | "func", |
| 997 | "args", |
| 998 | "keywords", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 999 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1000 | static const char * const FormattedValue_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 1001 | "value", |
| 1002 | "conversion", |
| 1003 | "format_spec", |
| 1004 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1005 | static const char * const JoinedStr_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 1006 | "values", |
| 1007 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1008 | static const char * const Constant_fields[]={ |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1009 | "value", |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 1010 | "kind", |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1011 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1012 | static const char * const Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1013 | "value", |
| 1014 | "attr", |
| 1015 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1016 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1017 | static const char * const Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1018 | "value", |
| 1019 | "slice", |
| 1020 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1021 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1022 | static const char * const Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1023 | "value", |
| 1024 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 1025 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1026 | static const char * const Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1027 | "id", |
| 1028 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1029 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1030 | static const char * const List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1031 | "elts", |
| 1032 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1033 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1034 | static const char * const Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1035 | "elts", |
| 1036 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1037 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1038 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1039 | static PyObject* ast2obj_slice(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1040 | static const char * const Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1041 | "lower", |
| 1042 | "upper", |
| 1043 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1044 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1045 | static const char * const ExtSlice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1046 | "dims", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1047 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1048 | static const char * const Index_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1049 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1050 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1051 | static PyObject* ast2obj_boolop(boolop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1052 | static PyObject* ast2obj_operator(operator_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1053 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1054 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1055 | static PyObject* ast2obj_comprehension(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1056 | static const char * const comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1057 | "target", |
| 1058 | "iter", |
| 1059 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 1060 | "is_async", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1061 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1062 | static const char * const excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1063 | "lineno", |
| 1064 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1065 | "end_lineno", |
| 1066 | "end_col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1067 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1068 | static PyObject* ast2obj_excepthandler(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1069 | static const char * const ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1070 | "type", |
| 1071 | "name", |
| 1072 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1073 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1074 | static PyObject* ast2obj_arguments(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1075 | static const char * const arguments_fields[]={ |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 1076 | "posonlyargs", |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 1077 | "args", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1078 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1079 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1080 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1081 | "kwarg", |
| 1082 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1083 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1084 | static PyObject* ast2obj_arg(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1085 | static const char * const arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1086 | "lineno", |
| 1087 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1088 | "end_lineno", |
| 1089 | "end_col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1090 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1091 | static const char * const arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1092 | "arg", |
| 1093 | "annotation", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1094 | "type_comment", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1095 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1096 | static PyObject* ast2obj_keyword(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1097 | static const char * const keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1098 | "arg", |
| 1099 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1100 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1101 | static PyObject* ast2obj_alias(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1102 | static const char * const alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1103 | "name", |
| 1104 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1105 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1106 | static PyObject* ast2obj_withitem(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1107 | static const char * const withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1108 | "context_expr", |
| 1109 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1110 | }; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1111 | static PyObject* ast2obj_type_ignore(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1112 | static const char * const TypeIgnore_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1113 | "lineno", |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 1114 | "tag", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1115 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1116 | |
| 1117 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1118 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1119 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 1120 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1121 | PyObject *dict; |
| 1122 | } AST_object; |
| 1123 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1124 | static void |
| 1125 | ast_dealloc(AST_object *self) |
| 1126 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1127 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1128 | PyTypeObject *tp = Py_TYPE(self); |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1129 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1130 | Py_CLEAR(self->dict); |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1131 | freefunc free_func = PyType_GetSlot(tp, Py_tp_free); |
| 1132 | assert(free_func != NULL); |
| 1133 | free_func(self); |
| 1134 | Py_DECREF(tp); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1135 | } |
| 1136 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1137 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1138 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 1139 | { |
| 1140 | Py_VISIT(self->dict); |
| 1141 | return 0; |
| 1142 | } |
| 1143 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1144 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1145 | ast_clear(AST_object *self) |
| 1146 | { |
| 1147 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1148 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1152 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 1153 | { |
| 1154 | Py_ssize_t i, numfields = 0; |
| 1155 | int res = -1; |
| 1156 | PyObject *key, *value, *fields; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1157 | if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1158 | goto cleanup; |
| 1159 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1160 | if (fields) { |
| 1161 | numfields = PySequence_Size(fields); |
| 1162 | if (numfields == -1) |
| 1163 | goto cleanup; |
| 1164 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1165 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1166 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1167 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 1168 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 1169 | "%zd positional argument%s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1170 | _PyType_Name(Py_TYPE(self)), |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1171 | numfields, numfields == 1 ? "" : "s"); |
| 1172 | res = -1; |
| 1173 | goto cleanup; |
| 1174 | } |
| 1175 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 1176 | /* cannot be reached when fields is NULL */ |
| 1177 | PyObject *name = PySequence_GetItem(fields, i); |
| 1178 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1179 | res = -1; |
| 1180 | goto cleanup; |
| 1181 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1182 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 1183 | Py_DECREF(name); |
| 1184 | if (res < 0) |
| 1185 | goto cleanup; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1186 | } |
| 1187 | if (kw) { |
| 1188 | i = 0; /* needed by PyDict_Next */ |
| 1189 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 1190 | res = PyObject_SetAttr(self, key, value); |
| 1191 | if (res < 0) |
| 1192 | goto cleanup; |
| 1193 | } |
| 1194 | } |
| 1195 | cleanup: |
| 1196 | Py_XDECREF(fields); |
| 1197 | return res; |
| 1198 | } |
| 1199 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1200 | /* Pickling support */ |
| 1201 | static PyObject * |
| 1202 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 1203 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1204 | PyObject *dict; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1205 | if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1206 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1207 | } |
| 1208 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1209 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1210 | } |
| 1211 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 1212 | } |
| 1213 | |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1214 | static PyMemberDef ast_type_members[] = { |
| 1215 | {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY}, |
| 1216 | {NULL} /* Sentinel */ |
| 1217 | }; |
| 1218 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1219 | static PyMethodDef ast_type_methods[] = { |
| 1220 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 1221 | {NULL} |
| 1222 | }; |
| 1223 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1224 | static PyGetSetDef ast_type_getsets[] = { |
| 1225 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 1226 | {NULL} |
| 1227 | }; |
| 1228 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1229 | static PyType_Slot AST_type_slots[] = { |
| 1230 | {Py_tp_dealloc, ast_dealloc}, |
| 1231 | {Py_tp_getattro, PyObject_GenericGetAttr}, |
| 1232 | {Py_tp_setattro, PyObject_GenericSetAttr}, |
| 1233 | {Py_tp_traverse, ast_traverse}, |
| 1234 | {Py_tp_clear, ast_clear}, |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1235 | {Py_tp_members, ast_type_members}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1236 | {Py_tp_methods, ast_type_methods}, |
| 1237 | {Py_tp_getset, ast_type_getsets}, |
| 1238 | {Py_tp_init, ast_type_init}, |
| 1239 | {Py_tp_alloc, PyType_GenericAlloc}, |
| 1240 | {Py_tp_new, PyType_GenericNew}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1241 | {Py_tp_free, PyObject_GC_Del}, |
| 1242 | {0, 0}, |
| 1243 | }; |
| 1244 | |
| 1245 | static PyType_Spec AST_type_spec = { |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1246 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1247 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1248 | 0, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1249 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
| 1250 | AST_type_slots |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1251 | }; |
| 1252 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1253 | static PyObject * |
| 1254 | make_type(const char *type, PyObject* base, const char* const* fields, int num_fields) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1255 | { |
| 1256 | PyObject *fnames, *result; |
| 1257 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1258 | fnames = PyTuple_New(num_fields); |
| 1259 | if (!fnames) return NULL; |
| 1260 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1261 | PyObject *field = PyUnicode_InternFromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1262 | if (!field) { |
| 1263 | Py_DECREF(fnames); |
| 1264 | return NULL; |
| 1265 | } |
| 1266 | PyTuple_SET_ITEM(fnames, i, field); |
| 1267 | } |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1268 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}", |
| 1269 | type, base, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1270 | astmodulestate_global->_fields, fnames, |
| 1271 | astmodulestate_global->__module__, |
| 1272 | astmodulestate_global->_ast); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1273 | Py_DECREF(fnames); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1274 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1277 | static int |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1278 | 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] | 1279 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1280 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1281 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 1282 | if (!l) |
| 1283 | return 0; |
| 1284 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1285 | s = PyUnicode_InternFromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1286 | if (!s) { |
| 1287 | Py_DECREF(l); |
| 1288 | return 0; |
| 1289 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1290 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1291 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1292 | result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1293 | Py_DECREF(l); |
| 1294 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1297 | /* Conversion AST -> Python */ |
| 1298 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1299 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 1300 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 1301 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1302 | PyObject *result = PyList_New(n); |
| 1303 | PyObject *value; |
| 1304 | if (!result) |
| 1305 | return NULL; |
| 1306 | for (i = 0; i < n; i++) { |
| 1307 | value = func(asdl_seq_GET(seq, i)); |
| 1308 | if (!value) { |
| 1309 | Py_DECREF(result); |
| 1310 | return NULL; |
| 1311 | } |
| 1312 | PyList_SET_ITEM(result, i, value); |
| 1313 | } |
| 1314 | return result; |
| 1315 | } |
| 1316 | |
| 1317 | static PyObject* ast2obj_object(void *o) |
| 1318 | { |
| 1319 | if (!o) |
| 1320 | o = Py_None; |
| 1321 | Py_INCREF((PyObject*)o); |
| 1322 | return (PyObject*)o; |
| 1323 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 1324 | #define ast2obj_singleton ast2obj_object |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1325 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1326 | #define ast2obj_identifier ast2obj_object |
| 1327 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 1328 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1329 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1330 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1331 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 1332 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1335 | /* Conversion Python -> AST */ |
| 1336 | |
| 1337 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 1338 | { |
| 1339 | if (obj == Py_None) |
| 1340 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 1341 | if (obj) { |
| 1342 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1343 | *out = NULL; |
| 1344 | return -1; |
| 1345 | } |
| 1346 | Py_INCREF(obj); |
| 1347 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1348 | *out = obj; |
| 1349 | return 0; |
| 1350 | } |
| 1351 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1352 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 1353 | { |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1354 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1355 | *out = NULL; |
| 1356 | return -1; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1357 | } |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1358 | Py_INCREF(obj); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1359 | *out = obj; |
| 1360 | return 0; |
| 1361 | } |
| 1362 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1363 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1364 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1365 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 1366 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1367 | return 1; |
| 1368 | } |
| 1369 | return obj2ast_object(obj, out, arena); |
| 1370 | } |
| 1371 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1372 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 1373 | { |
| 1374 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
| 1375 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 1376 | return 1; |
| 1377 | } |
| 1378 | return obj2ast_object(obj, out, arena); |
| 1379 | } |
| 1380 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1381 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 1382 | { |
| 1383 | int i; |
| 1384 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 1385 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1386 | return 1; |
| 1387 | } |
| 1388 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 1389 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1390 | if (i == -1 && PyErr_Occurred()) |
| 1391 | return 1; |
| 1392 | *out = i; |
| 1393 | return 0; |
| 1394 | } |
| 1395 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 1396 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1397 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1398 | PyObject *empty_tuple; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1399 | empty_tuple = PyTuple_New(0); |
| 1400 | if (!empty_tuple || |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1401 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 || |
| 1402 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) { |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1403 | Py_XDECREF(empty_tuple); |
| 1404 | return -1; |
| 1405 | } |
| 1406 | Py_DECREF(empty_tuple); |
| 1407 | return 0; |
| 1408 | } |
| 1409 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1410 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1411 | static int init_types(void) |
| 1412 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1413 | PyObject *m; |
| 1414 | if (PyState_FindModule(&_astmodule) == NULL) { |
| 1415 | m = PyModule_Create(&_astmodule); |
| 1416 | if (!m) return 0; |
| 1417 | PyState_AddModule(m, &_astmodule); |
| 1418 | } |
| 1419 | astmodulestate *state = astmodulestate_global; |
| 1420 | if (state->initialized) return 1; |
| 1421 | if (init_identifiers() < 0) return 0; |
| 1422 | state->AST_type = PyType_FromSpec(&AST_type_spec); |
| 1423 | if (!state->AST_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1424 | if (add_ast_fields() < 0) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1425 | state->mod_type = make_type("mod", state->AST_type, NULL, 0); |
| 1426 | if (!state->mod_type) return 0; |
| 1427 | if (!add_attributes(state->mod_type, NULL, 0)) return 0; |
| 1428 | state->Module_type = make_type("Module", state->mod_type, Module_fields, 2); |
| 1429 | if (!state->Module_type) return 0; |
| 1430 | state->Interactive_type = make_type("Interactive", state->mod_type, |
| 1431 | Interactive_fields, 1); |
| 1432 | if (!state->Interactive_type) return 0; |
| 1433 | state->Expression_type = make_type("Expression", state->mod_type, |
| 1434 | Expression_fields, 1); |
| 1435 | if (!state->Expression_type) return 0; |
| 1436 | state->FunctionType_type = make_type("FunctionType", state->mod_type, |
| 1437 | FunctionType_fields, 2); |
| 1438 | if (!state->FunctionType_type) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1439 | state->stmt_type = make_type("stmt", state->AST_type, NULL, 0); |
| 1440 | if (!state->stmt_type) return 0; |
| 1441 | if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0; |
| 1442 | state->FunctionDef_type = make_type("FunctionDef", state->stmt_type, |
| 1443 | FunctionDef_fields, 6); |
| 1444 | if (!state->FunctionDef_type) return 0; |
| 1445 | state->AsyncFunctionDef_type = make_type("AsyncFunctionDef", |
| 1446 | state->stmt_type, |
| 1447 | AsyncFunctionDef_fields, 6); |
| 1448 | if (!state->AsyncFunctionDef_type) return 0; |
| 1449 | state->ClassDef_type = make_type("ClassDef", state->stmt_type, |
| 1450 | ClassDef_fields, 5); |
| 1451 | if (!state->ClassDef_type) return 0; |
| 1452 | state->Return_type = make_type("Return", state->stmt_type, Return_fields, |
| 1453 | 1); |
| 1454 | if (!state->Return_type) return 0; |
| 1455 | state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, |
| 1456 | 1); |
| 1457 | if (!state->Delete_type) return 0; |
| 1458 | state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, |
| 1459 | 3); |
| 1460 | if (!state->Assign_type) return 0; |
| 1461 | state->AugAssign_type = make_type("AugAssign", state->stmt_type, |
| 1462 | AugAssign_fields, 3); |
| 1463 | if (!state->AugAssign_type) return 0; |
| 1464 | state->AnnAssign_type = make_type("AnnAssign", state->stmt_type, |
| 1465 | AnnAssign_fields, 4); |
| 1466 | if (!state->AnnAssign_type) return 0; |
| 1467 | state->For_type = make_type("For", state->stmt_type, For_fields, 5); |
| 1468 | if (!state->For_type) return 0; |
| 1469 | state->AsyncFor_type = make_type("AsyncFor", state->stmt_type, |
| 1470 | AsyncFor_fields, 5); |
| 1471 | if (!state->AsyncFor_type) return 0; |
| 1472 | state->While_type = make_type("While", state->stmt_type, While_fields, 3); |
| 1473 | if (!state->While_type) return 0; |
| 1474 | state->If_type = make_type("If", state->stmt_type, If_fields, 3); |
| 1475 | if (!state->If_type) return 0; |
| 1476 | state->With_type = make_type("With", state->stmt_type, With_fields, 3); |
| 1477 | if (!state->With_type) return 0; |
| 1478 | state->AsyncWith_type = make_type("AsyncWith", state->stmt_type, |
| 1479 | AsyncWith_fields, 3); |
| 1480 | if (!state->AsyncWith_type) return 0; |
| 1481 | state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2); |
| 1482 | if (!state->Raise_type) return 0; |
| 1483 | state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4); |
| 1484 | if (!state->Try_type) return 0; |
| 1485 | state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, |
| 1486 | 2); |
| 1487 | if (!state->Assert_type) return 0; |
| 1488 | state->Import_type = make_type("Import", state->stmt_type, Import_fields, |
| 1489 | 1); |
| 1490 | if (!state->Import_type) return 0; |
| 1491 | state->ImportFrom_type = make_type("ImportFrom", state->stmt_type, |
| 1492 | ImportFrom_fields, 3); |
| 1493 | if (!state->ImportFrom_type) return 0; |
| 1494 | state->Global_type = make_type("Global", state->stmt_type, Global_fields, |
| 1495 | 1); |
| 1496 | if (!state->Global_type) return 0; |
| 1497 | state->Nonlocal_type = make_type("Nonlocal", state->stmt_type, |
| 1498 | Nonlocal_fields, 1); |
| 1499 | if (!state->Nonlocal_type) return 0; |
| 1500 | state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1); |
| 1501 | if (!state->Expr_type) return 0; |
| 1502 | state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0); |
| 1503 | if (!state->Pass_type) return 0; |
| 1504 | state->Break_type = make_type("Break", state->stmt_type, NULL, 0); |
| 1505 | if (!state->Break_type) return 0; |
| 1506 | state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0); |
| 1507 | if (!state->Continue_type) return 0; |
| 1508 | state->expr_type = make_type("expr", state->AST_type, NULL, 0); |
| 1509 | if (!state->expr_type) return 0; |
| 1510 | if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0; |
| 1511 | state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, |
| 1512 | 2); |
| 1513 | if (!state->BoolOp_type) return 0; |
| 1514 | state->NamedExpr_type = make_type("NamedExpr", state->expr_type, |
| 1515 | NamedExpr_fields, 2); |
| 1516 | if (!state->NamedExpr_type) return 0; |
| 1517 | state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3); |
| 1518 | if (!state->BinOp_type) return 0; |
| 1519 | state->UnaryOp_type = make_type("UnaryOp", state->expr_type, |
| 1520 | UnaryOp_fields, 2); |
| 1521 | if (!state->UnaryOp_type) return 0; |
| 1522 | state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, |
| 1523 | 2); |
| 1524 | if (!state->Lambda_type) return 0; |
| 1525 | state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3); |
| 1526 | if (!state->IfExp_type) return 0; |
| 1527 | state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2); |
| 1528 | if (!state->Dict_type) return 0; |
| 1529 | state->Set_type = make_type("Set", state->expr_type, Set_fields, 1); |
| 1530 | if (!state->Set_type) return 0; |
| 1531 | state->ListComp_type = make_type("ListComp", state->expr_type, |
| 1532 | ListComp_fields, 2); |
| 1533 | if (!state->ListComp_type) return 0; |
| 1534 | state->SetComp_type = make_type("SetComp", state->expr_type, |
| 1535 | SetComp_fields, 2); |
| 1536 | if (!state->SetComp_type) return 0; |
| 1537 | state->DictComp_type = make_type("DictComp", state->expr_type, |
| 1538 | DictComp_fields, 3); |
| 1539 | if (!state->DictComp_type) return 0; |
| 1540 | state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type, |
| 1541 | GeneratorExp_fields, 2); |
| 1542 | if (!state->GeneratorExp_type) return 0; |
| 1543 | state->Await_type = make_type("Await", state->expr_type, Await_fields, 1); |
| 1544 | if (!state->Await_type) return 0; |
| 1545 | state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1); |
| 1546 | if (!state->Yield_type) return 0; |
| 1547 | state->YieldFrom_type = make_type("YieldFrom", state->expr_type, |
| 1548 | YieldFrom_fields, 1); |
| 1549 | if (!state->YieldFrom_type) return 0; |
| 1550 | state->Compare_type = make_type("Compare", state->expr_type, |
| 1551 | Compare_fields, 3); |
| 1552 | if (!state->Compare_type) return 0; |
| 1553 | state->Call_type = make_type("Call", state->expr_type, Call_fields, 3); |
| 1554 | if (!state->Call_type) return 0; |
| 1555 | state->FormattedValue_type = make_type("FormattedValue", state->expr_type, |
| 1556 | FormattedValue_fields, 3); |
| 1557 | if (!state->FormattedValue_type) return 0; |
| 1558 | state->JoinedStr_type = make_type("JoinedStr", state->expr_type, |
| 1559 | JoinedStr_fields, 1); |
| 1560 | if (!state->JoinedStr_type) return 0; |
| 1561 | state->Constant_type = make_type("Constant", state->expr_type, |
| 1562 | Constant_fields, 2); |
| 1563 | if (!state->Constant_type) return 0; |
| 1564 | state->Attribute_type = make_type("Attribute", state->expr_type, |
| 1565 | Attribute_fields, 3); |
| 1566 | if (!state->Attribute_type) return 0; |
| 1567 | state->Subscript_type = make_type("Subscript", state->expr_type, |
| 1568 | Subscript_fields, 3); |
| 1569 | if (!state->Subscript_type) return 0; |
| 1570 | state->Starred_type = make_type("Starred", state->expr_type, |
| 1571 | Starred_fields, 2); |
| 1572 | if (!state->Starred_type) return 0; |
| 1573 | state->Name_type = make_type("Name", state->expr_type, Name_fields, 2); |
| 1574 | if (!state->Name_type) return 0; |
| 1575 | state->List_type = make_type("List", state->expr_type, List_fields, 2); |
| 1576 | if (!state->List_type) return 0; |
| 1577 | state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2); |
| 1578 | if (!state->Tuple_type) return 0; |
| 1579 | state->expr_context_type = make_type("expr_context", state->AST_type, NULL, |
| 1580 | 0); |
| 1581 | if (!state->expr_context_type) return 0; |
| 1582 | if (!add_attributes(state->expr_context_type, NULL, 0)) return 0; |
| 1583 | state->Load_type = make_type("Load", state->expr_context_type, NULL, 0); |
| 1584 | if (!state->Load_type) return 0; |
| 1585 | state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type, |
| 1586 | NULL, NULL); |
| 1587 | if (!state->Load_singleton) return 0; |
| 1588 | state->Store_type = make_type("Store", state->expr_context_type, NULL, 0); |
| 1589 | if (!state->Store_type) return 0; |
| 1590 | state->Store_singleton = PyType_GenericNew((PyTypeObject |
| 1591 | *)state->Store_type, NULL, NULL); |
| 1592 | if (!state->Store_singleton) return 0; |
| 1593 | state->Del_type = make_type("Del", state->expr_context_type, NULL, 0); |
| 1594 | if (!state->Del_type) return 0; |
| 1595 | state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type, |
| 1596 | NULL, NULL); |
| 1597 | if (!state->Del_singleton) return 0; |
| 1598 | state->AugLoad_type = make_type("AugLoad", state->expr_context_type, NULL, |
| 1599 | 0); |
| 1600 | if (!state->AugLoad_type) return 0; |
| 1601 | state->AugLoad_singleton = PyType_GenericNew((PyTypeObject |
| 1602 | *)state->AugLoad_type, NULL, |
| 1603 | NULL); |
| 1604 | if (!state->AugLoad_singleton) return 0; |
| 1605 | state->AugStore_type = make_type("AugStore", state->expr_context_type, |
| 1606 | NULL, 0); |
| 1607 | if (!state->AugStore_type) return 0; |
| 1608 | state->AugStore_singleton = PyType_GenericNew((PyTypeObject |
| 1609 | *)state->AugStore_type, NULL, |
| 1610 | NULL); |
| 1611 | if (!state->AugStore_singleton) return 0; |
| 1612 | state->Param_type = make_type("Param", state->expr_context_type, NULL, 0); |
| 1613 | if (!state->Param_type) return 0; |
| 1614 | state->Param_singleton = PyType_GenericNew((PyTypeObject |
| 1615 | *)state->Param_type, NULL, NULL); |
| 1616 | if (!state->Param_singleton) return 0; |
| 1617 | state->slice_type = make_type("slice", state->AST_type, NULL, 0); |
| 1618 | if (!state->slice_type) return 0; |
| 1619 | if (!add_attributes(state->slice_type, NULL, 0)) return 0; |
| 1620 | state->Slice_type = make_type("Slice", state->slice_type, Slice_fields, 3); |
| 1621 | if (!state->Slice_type) return 0; |
| 1622 | state->ExtSlice_type = make_type("ExtSlice", state->slice_type, |
| 1623 | ExtSlice_fields, 1); |
| 1624 | if (!state->ExtSlice_type) return 0; |
| 1625 | state->Index_type = make_type("Index", state->slice_type, Index_fields, 1); |
| 1626 | if (!state->Index_type) return 0; |
| 1627 | state->boolop_type = make_type("boolop", state->AST_type, NULL, 0); |
| 1628 | if (!state->boolop_type) return 0; |
| 1629 | if (!add_attributes(state->boolop_type, NULL, 0)) return 0; |
| 1630 | state->And_type = make_type("And", state->boolop_type, NULL, 0); |
| 1631 | if (!state->And_type) return 0; |
| 1632 | state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type, |
| 1633 | NULL, NULL); |
| 1634 | if (!state->And_singleton) return 0; |
| 1635 | state->Or_type = make_type("Or", state->boolop_type, NULL, 0); |
| 1636 | if (!state->Or_type) return 0; |
| 1637 | state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type, |
| 1638 | NULL, NULL); |
| 1639 | if (!state->Or_singleton) return 0; |
| 1640 | state->operator_type = make_type("operator", state->AST_type, NULL, 0); |
| 1641 | if (!state->operator_type) return 0; |
| 1642 | if (!add_attributes(state->operator_type, NULL, 0)) return 0; |
| 1643 | state->Add_type = make_type("Add", state->operator_type, NULL, 0); |
| 1644 | if (!state->Add_type) return 0; |
| 1645 | state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type, |
| 1646 | NULL, NULL); |
| 1647 | if (!state->Add_singleton) return 0; |
| 1648 | state->Sub_type = make_type("Sub", state->operator_type, NULL, 0); |
| 1649 | if (!state->Sub_type) return 0; |
| 1650 | state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type, |
| 1651 | NULL, NULL); |
| 1652 | if (!state->Sub_singleton) return 0; |
| 1653 | state->Mult_type = make_type("Mult", state->operator_type, NULL, 0); |
| 1654 | if (!state->Mult_type) return 0; |
| 1655 | state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type, |
| 1656 | NULL, NULL); |
| 1657 | if (!state->Mult_singleton) return 0; |
| 1658 | state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0); |
| 1659 | if (!state->MatMult_type) return 0; |
| 1660 | state->MatMult_singleton = PyType_GenericNew((PyTypeObject |
| 1661 | *)state->MatMult_type, NULL, |
| 1662 | NULL); |
| 1663 | if (!state->MatMult_singleton) return 0; |
| 1664 | state->Div_type = make_type("Div", state->operator_type, NULL, 0); |
| 1665 | if (!state->Div_type) return 0; |
| 1666 | state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type, |
| 1667 | NULL, NULL); |
| 1668 | if (!state->Div_singleton) return 0; |
| 1669 | state->Mod_type = make_type("Mod", state->operator_type, NULL, 0); |
| 1670 | if (!state->Mod_type) return 0; |
| 1671 | state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type, |
| 1672 | NULL, NULL); |
| 1673 | if (!state->Mod_singleton) return 0; |
| 1674 | state->Pow_type = make_type("Pow", state->operator_type, NULL, 0); |
| 1675 | if (!state->Pow_type) return 0; |
| 1676 | state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type, |
| 1677 | NULL, NULL); |
| 1678 | if (!state->Pow_singleton) return 0; |
| 1679 | state->LShift_type = make_type("LShift", state->operator_type, NULL, 0); |
| 1680 | if (!state->LShift_type) return 0; |
| 1681 | state->LShift_singleton = PyType_GenericNew((PyTypeObject |
| 1682 | *)state->LShift_type, NULL, |
| 1683 | NULL); |
| 1684 | if (!state->LShift_singleton) return 0; |
| 1685 | state->RShift_type = make_type("RShift", state->operator_type, NULL, 0); |
| 1686 | if (!state->RShift_type) return 0; |
| 1687 | state->RShift_singleton = PyType_GenericNew((PyTypeObject |
| 1688 | *)state->RShift_type, NULL, |
| 1689 | NULL); |
| 1690 | if (!state->RShift_singleton) return 0; |
| 1691 | state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0); |
| 1692 | if (!state->BitOr_type) return 0; |
| 1693 | state->BitOr_singleton = PyType_GenericNew((PyTypeObject |
| 1694 | *)state->BitOr_type, NULL, NULL); |
| 1695 | if (!state->BitOr_singleton) return 0; |
| 1696 | state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0); |
| 1697 | if (!state->BitXor_type) return 0; |
| 1698 | state->BitXor_singleton = PyType_GenericNew((PyTypeObject |
| 1699 | *)state->BitXor_type, NULL, |
| 1700 | NULL); |
| 1701 | if (!state->BitXor_singleton) return 0; |
| 1702 | state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0); |
| 1703 | if (!state->BitAnd_type) return 0; |
| 1704 | state->BitAnd_singleton = PyType_GenericNew((PyTypeObject |
| 1705 | *)state->BitAnd_type, NULL, |
| 1706 | NULL); |
| 1707 | if (!state->BitAnd_singleton) return 0; |
| 1708 | state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0); |
| 1709 | if (!state->FloorDiv_type) return 0; |
| 1710 | state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject |
| 1711 | *)state->FloorDiv_type, NULL, |
| 1712 | NULL); |
| 1713 | if (!state->FloorDiv_singleton) return 0; |
| 1714 | state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0); |
| 1715 | if (!state->unaryop_type) return 0; |
| 1716 | if (!add_attributes(state->unaryop_type, NULL, 0)) return 0; |
| 1717 | state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0); |
| 1718 | if (!state->Invert_type) return 0; |
| 1719 | state->Invert_singleton = PyType_GenericNew((PyTypeObject |
| 1720 | *)state->Invert_type, NULL, |
| 1721 | NULL); |
| 1722 | if (!state->Invert_singleton) return 0; |
| 1723 | state->Not_type = make_type("Not", state->unaryop_type, NULL, 0); |
| 1724 | if (!state->Not_type) return 0; |
| 1725 | state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type, |
| 1726 | NULL, NULL); |
| 1727 | if (!state->Not_singleton) return 0; |
| 1728 | state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0); |
| 1729 | if (!state->UAdd_type) return 0; |
| 1730 | state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type, |
| 1731 | NULL, NULL); |
| 1732 | if (!state->UAdd_singleton) return 0; |
| 1733 | state->USub_type = make_type("USub", state->unaryop_type, NULL, 0); |
| 1734 | if (!state->USub_type) return 0; |
| 1735 | state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type, |
| 1736 | NULL, NULL); |
| 1737 | if (!state->USub_singleton) return 0; |
| 1738 | state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0); |
| 1739 | if (!state->cmpop_type) return 0; |
| 1740 | if (!add_attributes(state->cmpop_type, NULL, 0)) return 0; |
| 1741 | state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0); |
| 1742 | if (!state->Eq_type) return 0; |
| 1743 | state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type, |
| 1744 | NULL, NULL); |
| 1745 | if (!state->Eq_singleton) return 0; |
| 1746 | state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0); |
| 1747 | if (!state->NotEq_type) return 0; |
| 1748 | state->NotEq_singleton = PyType_GenericNew((PyTypeObject |
| 1749 | *)state->NotEq_type, NULL, NULL); |
| 1750 | if (!state->NotEq_singleton) return 0; |
| 1751 | state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0); |
| 1752 | if (!state->Lt_type) return 0; |
| 1753 | state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type, |
| 1754 | NULL, NULL); |
| 1755 | if (!state->Lt_singleton) return 0; |
| 1756 | state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0); |
| 1757 | if (!state->LtE_type) return 0; |
| 1758 | state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type, |
| 1759 | NULL, NULL); |
| 1760 | if (!state->LtE_singleton) return 0; |
| 1761 | state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0); |
| 1762 | if (!state->Gt_type) return 0; |
| 1763 | state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type, |
| 1764 | NULL, NULL); |
| 1765 | if (!state->Gt_singleton) return 0; |
| 1766 | state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0); |
| 1767 | if (!state->GtE_type) return 0; |
| 1768 | state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type, |
| 1769 | NULL, NULL); |
| 1770 | if (!state->GtE_singleton) return 0; |
| 1771 | state->Is_type = make_type("Is", state->cmpop_type, NULL, 0); |
| 1772 | if (!state->Is_type) return 0; |
| 1773 | state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type, |
| 1774 | NULL, NULL); |
| 1775 | if (!state->Is_singleton) return 0; |
| 1776 | state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0); |
| 1777 | if (!state->IsNot_type) return 0; |
| 1778 | state->IsNot_singleton = PyType_GenericNew((PyTypeObject |
| 1779 | *)state->IsNot_type, NULL, NULL); |
| 1780 | if (!state->IsNot_singleton) return 0; |
| 1781 | state->In_type = make_type("In", state->cmpop_type, NULL, 0); |
| 1782 | if (!state->In_type) return 0; |
| 1783 | state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type, |
| 1784 | NULL, NULL); |
| 1785 | if (!state->In_singleton) return 0; |
| 1786 | state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0); |
| 1787 | if (!state->NotIn_type) return 0; |
| 1788 | state->NotIn_singleton = PyType_GenericNew((PyTypeObject |
| 1789 | *)state->NotIn_type, NULL, NULL); |
| 1790 | if (!state->NotIn_singleton) return 0; |
| 1791 | state->comprehension_type = make_type("comprehension", state->AST_type, |
| 1792 | comprehension_fields, 4); |
| 1793 | if (!state->comprehension_type) return 0; |
| 1794 | if (!add_attributes(state->comprehension_type, NULL, 0)) return 0; |
| 1795 | state->excepthandler_type = make_type("excepthandler", state->AST_type, |
| 1796 | NULL, 0); |
| 1797 | if (!state->excepthandler_type) return 0; |
| 1798 | if (!add_attributes(state->excepthandler_type, excepthandler_attributes, |
| 1799 | 4)) return 0; |
| 1800 | state->ExceptHandler_type = make_type("ExceptHandler", |
| 1801 | state->excepthandler_type, |
| 1802 | ExceptHandler_fields, 3); |
| 1803 | if (!state->ExceptHandler_type) return 0; |
| 1804 | state->arguments_type = make_type("arguments", state->AST_type, |
| 1805 | arguments_fields, 7); |
| 1806 | if (!state->arguments_type) return 0; |
| 1807 | if (!add_attributes(state->arguments_type, NULL, 0)) return 0; |
| 1808 | state->arg_type = make_type("arg", state->AST_type, arg_fields, 3); |
| 1809 | if (!state->arg_type) return 0; |
| 1810 | if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0; |
| 1811 | state->keyword_type = make_type("keyword", state->AST_type, keyword_fields, |
| 1812 | 2); |
| 1813 | if (!state->keyword_type) return 0; |
| 1814 | if (!add_attributes(state->keyword_type, NULL, 0)) return 0; |
| 1815 | state->alias_type = make_type("alias", state->AST_type, alias_fields, 2); |
| 1816 | if (!state->alias_type) return 0; |
| 1817 | if (!add_attributes(state->alias_type, NULL, 0)) return 0; |
| 1818 | state->withitem_type = make_type("withitem", state->AST_type, |
| 1819 | withitem_fields, 2); |
| 1820 | if (!state->withitem_type) return 0; |
| 1821 | if (!add_attributes(state->withitem_type, NULL, 0)) return 0; |
| 1822 | state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, |
| 1823 | 0); |
| 1824 | if (!state->type_ignore_type) return 0; |
| 1825 | if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0; |
| 1826 | state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type, |
| 1827 | TypeIgnore_fields, 2); |
| 1828 | if (!state->TypeIgnore_type) return 0; |
| 1829 | state->initialized = 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1830 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1831 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1832 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1833 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1834 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1835 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1836 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1837 | arena); |
| 1838 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1839 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1840 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1841 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1842 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1843 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1844 | arena); |
| 1845 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1846 | arena); |
| 1847 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1848 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1849 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1850 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1851 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1852 | static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* |
| 1853 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1854 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1855 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1856 | Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1857 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1858 | mod_ty p; |
| 1859 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1860 | if (!p) |
| 1861 | return NULL; |
| 1862 | p->kind = Module_kind; |
| 1863 | p->v.Module.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1864 | p->v.Module.type_ignores = type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1865 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1869 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1870 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1871 | mod_ty p; |
| 1872 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1873 | if (!p) |
| 1874 | return NULL; |
| 1875 | p->kind = Interactive_kind; |
| 1876 | p->v.Interactive.body = body; |
| 1877 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1881 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1882 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1883 | mod_ty p; |
| 1884 | if (!body) { |
| 1885 | PyErr_SetString(PyExc_ValueError, |
| 1886 | "field body is required for Expression"); |
| 1887 | return NULL; |
| 1888 | } |
| 1889 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1890 | if (!p) |
| 1891 | return NULL; |
| 1892 | p->kind = Expression_kind; |
| 1893 | p->v.Expression.body = body; |
| 1894 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1898 | FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena) |
| 1899 | { |
| 1900 | mod_ty p; |
| 1901 | if (!returns) { |
| 1902 | PyErr_SetString(PyExc_ValueError, |
| 1903 | "field returns is required for FunctionType"); |
| 1904 | return NULL; |
| 1905 | } |
| 1906 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1907 | if (!p) |
| 1908 | return NULL; |
| 1909 | p->kind = FunctionType_kind; |
| 1910 | p->v.FunctionType.argtypes = argtypes; |
| 1911 | p->v.FunctionType.returns = returns; |
| 1912 | return p; |
| 1913 | } |
| 1914 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1915 | stmt_ty |
| 1916 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1917 | decorator_list, expr_ty returns, string type_comment, int lineno, |
| 1918 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1919 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1920 | stmt_ty p; |
| 1921 | if (!name) { |
| 1922 | PyErr_SetString(PyExc_ValueError, |
| 1923 | "field name is required for FunctionDef"); |
| 1924 | return NULL; |
| 1925 | } |
| 1926 | if (!args) { |
| 1927 | PyErr_SetString(PyExc_ValueError, |
| 1928 | "field args is required for FunctionDef"); |
| 1929 | return NULL; |
| 1930 | } |
| 1931 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1932 | if (!p) |
| 1933 | return NULL; |
| 1934 | p->kind = FunctionDef_kind; |
| 1935 | p->v.FunctionDef.name = name; |
| 1936 | p->v.FunctionDef.args = args; |
| 1937 | p->v.FunctionDef.body = body; |
| 1938 | p->v.FunctionDef.decorator_list = decorator_list; |
| 1939 | p->v.FunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1940 | p->v.FunctionDef.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1941 | p->lineno = lineno; |
| 1942 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1943 | p->end_lineno = end_lineno; |
| 1944 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1945 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1949 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1950 | * decorator_list, expr_ty returns, string type_comment, int |
| 1951 | lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1952 | PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1953 | { |
| 1954 | stmt_ty p; |
| 1955 | if (!name) { |
| 1956 | PyErr_SetString(PyExc_ValueError, |
| 1957 | "field name is required for AsyncFunctionDef"); |
| 1958 | return NULL; |
| 1959 | } |
| 1960 | if (!args) { |
| 1961 | PyErr_SetString(PyExc_ValueError, |
| 1962 | "field args is required for AsyncFunctionDef"); |
| 1963 | return NULL; |
| 1964 | } |
| 1965 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1966 | if (!p) |
| 1967 | return NULL; |
| 1968 | p->kind = AsyncFunctionDef_kind; |
| 1969 | p->v.AsyncFunctionDef.name = name; |
| 1970 | p->v.AsyncFunctionDef.args = args; |
| 1971 | p->v.AsyncFunctionDef.body = body; |
| 1972 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 1973 | p->v.AsyncFunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1974 | p->v.AsyncFunctionDef.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1975 | p->lineno = lineno; |
| 1976 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1977 | p->end_lineno = end_lineno; |
| 1978 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1979 | return p; |
| 1980 | } |
| 1981 | |
| 1982 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 1983 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1984 | body, asdl_seq * decorator_list, int lineno, int col_offset, int |
| 1985 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1986 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1987 | stmt_ty p; |
| 1988 | if (!name) { |
| 1989 | PyErr_SetString(PyExc_ValueError, |
| 1990 | "field name is required for ClassDef"); |
| 1991 | return NULL; |
| 1992 | } |
| 1993 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1994 | if (!p) |
| 1995 | return NULL; |
| 1996 | p->kind = ClassDef_kind; |
| 1997 | p->v.ClassDef.name = name; |
| 1998 | p->v.ClassDef.bases = bases; |
| 1999 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2000 | p->v.ClassDef.body = body; |
| 2001 | p->v.ClassDef.decorator_list = decorator_list; |
| 2002 | p->lineno = lineno; |
| 2003 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2004 | p->end_lineno = end_lineno; |
| 2005 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2006 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2010 | Return(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2011 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2012 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2013 | stmt_ty p; |
| 2014 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2015 | if (!p) |
| 2016 | return NULL; |
| 2017 | p->kind = Return_kind; |
| 2018 | p->v.Return.value = value; |
| 2019 | p->lineno = lineno; |
| 2020 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2021 | p->end_lineno = end_lineno; |
| 2022 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2023 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2027 | Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int |
| 2028 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2029 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2030 | stmt_ty p; |
| 2031 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2032 | if (!p) |
| 2033 | return NULL; |
| 2034 | p->kind = Delete_kind; |
| 2035 | p->v.Delete.targets = targets; |
| 2036 | p->lineno = lineno; |
| 2037 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2038 | p->end_lineno = end_lineno; |
| 2039 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2040 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2044 | Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int |
| 2045 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2046 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2047 | stmt_ty p; |
| 2048 | if (!value) { |
| 2049 | PyErr_SetString(PyExc_ValueError, |
| 2050 | "field value is required for Assign"); |
| 2051 | return NULL; |
| 2052 | } |
| 2053 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2054 | if (!p) |
| 2055 | return NULL; |
| 2056 | p->kind = Assign_kind; |
| 2057 | p->v.Assign.targets = targets; |
| 2058 | p->v.Assign.value = value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2059 | p->v.Assign.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2060 | p->lineno = lineno; |
| 2061 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2062 | p->end_lineno = end_lineno; |
| 2063 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2064 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2068 | 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] | 2069 | col_offset, int end_lineno, int end_col_offset, 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 | stmt_ty p; |
| 2072 | if (!target) { |
| 2073 | PyErr_SetString(PyExc_ValueError, |
| 2074 | "field target is required for AugAssign"); |
| 2075 | return NULL; |
| 2076 | } |
| 2077 | if (!op) { |
| 2078 | PyErr_SetString(PyExc_ValueError, |
| 2079 | "field op is required for AugAssign"); |
| 2080 | return NULL; |
| 2081 | } |
| 2082 | if (!value) { |
| 2083 | PyErr_SetString(PyExc_ValueError, |
| 2084 | "field value is required for AugAssign"); |
| 2085 | return NULL; |
| 2086 | } |
| 2087 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2088 | if (!p) |
| 2089 | return NULL; |
| 2090 | p->kind = AugAssign_kind; |
| 2091 | p->v.AugAssign.target = target; |
| 2092 | p->v.AugAssign.op = op; |
| 2093 | p->v.AugAssign.value = value; |
| 2094 | p->lineno = lineno; |
| 2095 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2096 | p->end_lineno = end_lineno; |
| 2097 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2098 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2102 | 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] | 2103 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2104 | *arena) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2105 | { |
| 2106 | stmt_ty p; |
| 2107 | if (!target) { |
| 2108 | PyErr_SetString(PyExc_ValueError, |
| 2109 | "field target is required for AnnAssign"); |
| 2110 | return NULL; |
| 2111 | } |
| 2112 | if (!annotation) { |
| 2113 | PyErr_SetString(PyExc_ValueError, |
| 2114 | "field annotation is required for AnnAssign"); |
| 2115 | return NULL; |
| 2116 | } |
| 2117 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2118 | if (!p) |
| 2119 | return NULL; |
| 2120 | p->kind = AnnAssign_kind; |
| 2121 | p->v.AnnAssign.target = target; |
| 2122 | p->v.AnnAssign.annotation = annotation; |
| 2123 | p->v.AnnAssign.value = value; |
| 2124 | p->v.AnnAssign.simple = simple; |
| 2125 | p->lineno = lineno; |
| 2126 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2127 | p->end_lineno = end_lineno; |
| 2128 | p->end_col_offset = end_col_offset; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2129 | return p; |
| 2130 | } |
| 2131 | |
| 2132 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2133 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string |
| 2134 | type_comment, int lineno, int col_offset, int end_lineno, int |
| 2135 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2136 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2137 | stmt_ty p; |
| 2138 | if (!target) { |
| 2139 | PyErr_SetString(PyExc_ValueError, |
| 2140 | "field target is required for For"); |
| 2141 | return NULL; |
| 2142 | } |
| 2143 | if (!iter) { |
| 2144 | PyErr_SetString(PyExc_ValueError, |
| 2145 | "field iter is required for For"); |
| 2146 | return NULL; |
| 2147 | } |
| 2148 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2149 | if (!p) |
| 2150 | return NULL; |
| 2151 | p->kind = For_kind; |
| 2152 | p->v.For.target = target; |
| 2153 | p->v.For.iter = iter; |
| 2154 | p->v.For.body = body; |
| 2155 | p->v.For.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2156 | p->v.For.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2157 | p->lineno = lineno; |
| 2158 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2159 | p->end_lineno = end_lineno; |
| 2160 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2161 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2165 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, |
| 2166 | string type_comment, int lineno, int col_offset, int end_lineno, int |
| 2167 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2168 | { |
| 2169 | stmt_ty p; |
| 2170 | if (!target) { |
| 2171 | PyErr_SetString(PyExc_ValueError, |
| 2172 | "field target is required for AsyncFor"); |
| 2173 | return NULL; |
| 2174 | } |
| 2175 | if (!iter) { |
| 2176 | PyErr_SetString(PyExc_ValueError, |
| 2177 | "field iter is required for AsyncFor"); |
| 2178 | return NULL; |
| 2179 | } |
| 2180 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2181 | if (!p) |
| 2182 | return NULL; |
| 2183 | p->kind = AsyncFor_kind; |
| 2184 | p->v.AsyncFor.target = target; |
| 2185 | p->v.AsyncFor.iter = iter; |
| 2186 | p->v.AsyncFor.body = body; |
| 2187 | p->v.AsyncFor.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2188 | p->v.AsyncFor.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2189 | p->lineno = lineno; |
| 2190 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2191 | p->end_lineno = end_lineno; |
| 2192 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2193 | return p; |
| 2194 | } |
| 2195 | |
| 2196 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2197 | 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] | 2198 | col_offset, int 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 (!test) { |
| 2202 | PyErr_SetString(PyExc_ValueError, |
| 2203 | "field test is required for While"); |
| 2204 | return NULL; |
| 2205 | } |
| 2206 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2207 | if (!p) |
| 2208 | return NULL; |
| 2209 | p->kind = While_kind; |
| 2210 | p->v.While.test = test; |
| 2211 | p->v.While.body = body; |
| 2212 | p->v.While.orelse = orelse; |
| 2213 | p->lineno = lineno; |
| 2214 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2215 | p->end_lineno = end_lineno; |
| 2216 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2217 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2221 | 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] | 2222 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2223 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2224 | stmt_ty p; |
| 2225 | if (!test) { |
| 2226 | PyErr_SetString(PyExc_ValueError, |
| 2227 | "field test is required for If"); |
| 2228 | return NULL; |
| 2229 | } |
| 2230 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2231 | if (!p) |
| 2232 | return NULL; |
| 2233 | p->kind = If_kind; |
| 2234 | p->v.If.test = test; |
| 2235 | p->v.If.body = body; |
| 2236 | p->v.If.orelse = orelse; |
| 2237 | p->lineno = lineno; |
| 2238 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2239 | p->end_lineno = end_lineno; |
| 2240 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2241 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2242 | } |
| 2243 | |
| 2244 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2245 | With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int |
| 2246 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2247 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2248 | stmt_ty p; |
| 2249 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2250 | if (!p) |
| 2251 | return NULL; |
| 2252 | p->kind = With_kind; |
| 2253 | p->v.With.items = items; |
| 2254 | p->v.With.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2255 | p->v.With.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2256 | p->lineno = lineno; |
| 2257 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2258 | p->end_lineno = end_lineno; |
| 2259 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2260 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2264 | AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, |
| 2265 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2266 | { |
| 2267 | stmt_ty p; |
| 2268 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2269 | if (!p) |
| 2270 | return NULL; |
| 2271 | p->kind = AsyncWith_kind; |
| 2272 | p->v.AsyncWith.items = items; |
| 2273 | p->v.AsyncWith.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2274 | p->v.AsyncWith.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2275 | p->lineno = lineno; |
| 2276 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2277 | p->end_lineno = end_lineno; |
| 2278 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2279 | return p; |
| 2280 | } |
| 2281 | |
| 2282 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2283 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, |
| 2284 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2285 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2286 | stmt_ty p; |
| 2287 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2288 | if (!p) |
| 2289 | return NULL; |
| 2290 | p->kind = Raise_kind; |
| 2291 | p->v.Raise.exc = exc; |
| 2292 | p->v.Raise.cause = cause; |
| 2293 | p->lineno = lineno; |
| 2294 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2295 | p->end_lineno = end_lineno; |
| 2296 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2297 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2301 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2302 | finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2303 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2304 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2305 | stmt_ty p; |
| 2306 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2307 | if (!p) |
| 2308 | return NULL; |
| 2309 | p->kind = Try_kind; |
| 2310 | p->v.Try.body = body; |
| 2311 | p->v.Try.handlers = handlers; |
| 2312 | p->v.Try.orelse = orelse; |
| 2313 | p->v.Try.finalbody = finalbody; |
| 2314 | p->lineno = lineno; |
| 2315 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2316 | p->end_lineno = end_lineno; |
| 2317 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2318 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2322 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, |
| 2323 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2324 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2325 | stmt_ty p; |
| 2326 | if (!test) { |
| 2327 | PyErr_SetString(PyExc_ValueError, |
| 2328 | "field test is required for Assert"); |
| 2329 | return NULL; |
| 2330 | } |
| 2331 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2332 | if (!p) |
| 2333 | return NULL; |
| 2334 | p->kind = Assert_kind; |
| 2335 | p->v.Assert.test = test; |
| 2336 | p->v.Assert.msg = msg; |
| 2337 | p->lineno = lineno; |
| 2338 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2339 | p->end_lineno = end_lineno; |
| 2340 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2341 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2345 | Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2346 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2347 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2348 | stmt_ty p; |
| 2349 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2350 | if (!p) |
| 2351 | return NULL; |
| 2352 | p->kind = Import_kind; |
| 2353 | p->v.Import.names = names; |
| 2354 | p->lineno = lineno; |
| 2355 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2356 | p->end_lineno = end_lineno; |
| 2357 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2358 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2362 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2363 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2364 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2365 | stmt_ty p; |
| 2366 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2367 | if (!p) |
| 2368 | return NULL; |
| 2369 | p->kind = ImportFrom_kind; |
| 2370 | p->v.ImportFrom.module = module; |
| 2371 | p->v.ImportFrom.names = names; |
| 2372 | p->v.ImportFrom.level = level; |
| 2373 | p->lineno = lineno; |
| 2374 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2375 | p->end_lineno = end_lineno; |
| 2376 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2377 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2381 | Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2382 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2383 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2384 | stmt_ty p; |
| 2385 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2386 | if (!p) |
| 2387 | return NULL; |
| 2388 | p->kind = Global_kind; |
| 2389 | p->v.Global.names = names; |
| 2390 | p->lineno = lineno; |
| 2391 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2392 | p->end_lineno = end_lineno; |
| 2393 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2394 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2398 | Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2399 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2400 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2401 | stmt_ty p; |
| 2402 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2403 | if (!p) |
| 2404 | return NULL; |
| 2405 | p->kind = Nonlocal_kind; |
| 2406 | p->v.Nonlocal.names = names; |
| 2407 | p->lineno = lineno; |
| 2408 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2409 | p->end_lineno = end_lineno; |
| 2410 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2411 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2415 | Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2416 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2417 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2418 | stmt_ty p; |
| 2419 | if (!value) { |
| 2420 | PyErr_SetString(PyExc_ValueError, |
| 2421 | "field value is required for Expr"); |
| 2422 | return NULL; |
| 2423 | } |
| 2424 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2425 | if (!p) |
| 2426 | return NULL; |
| 2427 | p->kind = Expr_kind; |
| 2428 | p->v.Expr.value = value; |
| 2429 | p->lineno = lineno; |
| 2430 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2431 | p->end_lineno = end_lineno; |
| 2432 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2433 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2437 | Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2438 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2439 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2440 | stmt_ty p; |
| 2441 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2442 | if (!p) |
| 2443 | return NULL; |
| 2444 | p->kind = Pass_kind; |
| 2445 | p->lineno = lineno; |
| 2446 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2447 | p->end_lineno = end_lineno; |
| 2448 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2449 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2453 | Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2454 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2455 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2456 | stmt_ty p; |
| 2457 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2458 | if (!p) |
| 2459 | return NULL; |
| 2460 | p->kind = Break_kind; |
| 2461 | p->lineno = lineno; |
| 2462 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2463 | p->end_lineno = end_lineno; |
| 2464 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2465 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2469 | Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2470 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2471 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2472 | stmt_ty p; |
| 2473 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2474 | if (!p) |
| 2475 | return NULL; |
| 2476 | p->kind = Continue_kind; |
| 2477 | p->lineno = lineno; |
| 2478 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2479 | p->end_lineno = end_lineno; |
| 2480 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2481 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2485 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int |
| 2486 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2487 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2488 | expr_ty p; |
| 2489 | if (!op) { |
| 2490 | PyErr_SetString(PyExc_ValueError, |
| 2491 | "field op is required for BoolOp"); |
| 2492 | return NULL; |
| 2493 | } |
| 2494 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2495 | if (!p) |
| 2496 | return NULL; |
| 2497 | p->kind = BoolOp_kind; |
| 2498 | p->v.BoolOp.op = op; |
| 2499 | p->v.BoolOp.values = values; |
| 2500 | p->lineno = lineno; |
| 2501 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2502 | p->end_lineno = end_lineno; |
| 2503 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2504 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2505 | } |
| 2506 | |
| 2507 | expr_ty |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2508 | NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int |
| 2509 | end_lineno, int end_col_offset, PyArena *arena) |
| 2510 | { |
| 2511 | expr_ty p; |
| 2512 | if (!target) { |
| 2513 | PyErr_SetString(PyExc_ValueError, |
| 2514 | "field target is required for NamedExpr"); |
| 2515 | return NULL; |
| 2516 | } |
| 2517 | if (!value) { |
| 2518 | PyErr_SetString(PyExc_ValueError, |
| 2519 | "field value is required for NamedExpr"); |
| 2520 | return NULL; |
| 2521 | } |
| 2522 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2523 | if (!p) |
| 2524 | return NULL; |
| 2525 | p->kind = NamedExpr_kind; |
| 2526 | p->v.NamedExpr.target = target; |
| 2527 | p->v.NamedExpr.value = value; |
| 2528 | p->lineno = lineno; |
| 2529 | p->col_offset = col_offset; |
| 2530 | p->end_lineno = end_lineno; |
| 2531 | p->end_col_offset = end_col_offset; |
| 2532 | return p; |
| 2533 | } |
| 2534 | |
| 2535 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2536 | 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] | 2537 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2538 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2539 | expr_ty p; |
| 2540 | if (!left) { |
| 2541 | PyErr_SetString(PyExc_ValueError, |
| 2542 | "field left is required for BinOp"); |
| 2543 | return NULL; |
| 2544 | } |
| 2545 | if (!op) { |
| 2546 | PyErr_SetString(PyExc_ValueError, |
| 2547 | "field op is required for BinOp"); |
| 2548 | return NULL; |
| 2549 | } |
| 2550 | if (!right) { |
| 2551 | PyErr_SetString(PyExc_ValueError, |
| 2552 | "field right is required for BinOp"); |
| 2553 | return NULL; |
| 2554 | } |
| 2555 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2556 | if (!p) |
| 2557 | return NULL; |
| 2558 | p->kind = BinOp_kind; |
| 2559 | p->v.BinOp.left = left; |
| 2560 | p->v.BinOp.op = op; |
| 2561 | p->v.BinOp.right = right; |
| 2562 | p->lineno = lineno; |
| 2563 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2564 | p->end_lineno = end_lineno; |
| 2565 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2566 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2567 | } |
| 2568 | |
| 2569 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2570 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int |
| 2571 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2572 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2573 | expr_ty p; |
| 2574 | if (!op) { |
| 2575 | PyErr_SetString(PyExc_ValueError, |
| 2576 | "field op is required for UnaryOp"); |
| 2577 | return NULL; |
| 2578 | } |
| 2579 | if (!operand) { |
| 2580 | PyErr_SetString(PyExc_ValueError, |
| 2581 | "field operand is required for UnaryOp"); |
| 2582 | return NULL; |
| 2583 | } |
| 2584 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2585 | if (!p) |
| 2586 | return NULL; |
| 2587 | p->kind = UnaryOp_kind; |
| 2588 | p->v.UnaryOp.op = op; |
| 2589 | p->v.UnaryOp.operand = operand; |
| 2590 | p->lineno = lineno; |
| 2591 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2592 | p->end_lineno = end_lineno; |
| 2593 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2594 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2595 | } |
| 2596 | |
| 2597 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2598 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int |
| 2599 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2600 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2601 | expr_ty p; |
| 2602 | if (!args) { |
| 2603 | PyErr_SetString(PyExc_ValueError, |
| 2604 | "field args is required for Lambda"); |
| 2605 | return NULL; |
| 2606 | } |
| 2607 | if (!body) { |
| 2608 | PyErr_SetString(PyExc_ValueError, |
| 2609 | "field body is required for Lambda"); |
| 2610 | return NULL; |
| 2611 | } |
| 2612 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2613 | if (!p) |
| 2614 | return NULL; |
| 2615 | p->kind = Lambda_kind; |
| 2616 | p->v.Lambda.args = args; |
| 2617 | p->v.Lambda.body = body; |
| 2618 | p->lineno = lineno; |
| 2619 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2620 | p->end_lineno = end_lineno; |
| 2621 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2622 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2626 | 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] | 2627 | int end_lineno, int end_col_offset, PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2628 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2629 | expr_ty p; |
| 2630 | if (!test) { |
| 2631 | PyErr_SetString(PyExc_ValueError, |
| 2632 | "field test is required for IfExp"); |
| 2633 | return NULL; |
| 2634 | } |
| 2635 | if (!body) { |
| 2636 | PyErr_SetString(PyExc_ValueError, |
| 2637 | "field body is required for IfExp"); |
| 2638 | return NULL; |
| 2639 | } |
| 2640 | if (!orelse) { |
| 2641 | PyErr_SetString(PyExc_ValueError, |
| 2642 | "field orelse is required for IfExp"); |
| 2643 | return NULL; |
| 2644 | } |
| 2645 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2646 | if (!p) |
| 2647 | return NULL; |
| 2648 | p->kind = IfExp_kind; |
| 2649 | p->v.IfExp.test = test; |
| 2650 | p->v.IfExp.body = body; |
| 2651 | p->v.IfExp.orelse = orelse; |
| 2652 | p->lineno = lineno; |
| 2653 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2654 | p->end_lineno = end_lineno; |
| 2655 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2656 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2660 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int |
| 2661 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2662 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2663 | expr_ty p; |
| 2664 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2665 | if (!p) |
| 2666 | return NULL; |
| 2667 | p->kind = Dict_kind; |
| 2668 | p->v.Dict.keys = keys; |
| 2669 | p->v.Dict.values = values; |
| 2670 | p->lineno = lineno; |
| 2671 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2672 | p->end_lineno = end_lineno; |
| 2673 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2674 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2675 | } |
| 2676 | |
| 2677 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2678 | Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int |
| 2679 | end_col_offset, PyArena *arena) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2680 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2681 | expr_ty p; |
| 2682 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2683 | if (!p) |
| 2684 | return NULL; |
| 2685 | p->kind = Set_kind; |
| 2686 | p->v.Set.elts = elts; |
| 2687 | p->lineno = lineno; |
| 2688 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2689 | p->end_lineno = end_lineno; |
| 2690 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2691 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2695 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2696 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2697 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2698 | expr_ty p; |
| 2699 | if (!elt) { |
| 2700 | PyErr_SetString(PyExc_ValueError, |
| 2701 | "field elt is required for ListComp"); |
| 2702 | return NULL; |
| 2703 | } |
| 2704 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2705 | if (!p) |
| 2706 | return NULL; |
| 2707 | p->kind = ListComp_kind; |
| 2708 | p->v.ListComp.elt = elt; |
| 2709 | p->v.ListComp.generators = generators; |
| 2710 | p->lineno = lineno; |
| 2711 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2712 | p->end_lineno = end_lineno; |
| 2713 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2714 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2715 | } |
| 2716 | |
| 2717 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2718 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2719 | end_lineno, int end_col_offset, PyArena *arena) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2720 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2721 | expr_ty p; |
| 2722 | if (!elt) { |
| 2723 | PyErr_SetString(PyExc_ValueError, |
| 2724 | "field elt is required for SetComp"); |
| 2725 | return NULL; |
| 2726 | } |
| 2727 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2728 | if (!p) |
| 2729 | return NULL; |
| 2730 | p->kind = SetComp_kind; |
| 2731 | p->v.SetComp.elt = elt; |
| 2732 | p->v.SetComp.generators = generators; |
| 2733 | p->lineno = lineno; |
| 2734 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2735 | p->end_lineno = end_lineno; |
| 2736 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2737 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2741 | 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] | 2742 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2743 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2744 | expr_ty p; |
| 2745 | if (!key) { |
| 2746 | PyErr_SetString(PyExc_ValueError, |
| 2747 | "field key is required for DictComp"); |
| 2748 | return NULL; |
| 2749 | } |
| 2750 | if (!value) { |
| 2751 | PyErr_SetString(PyExc_ValueError, |
| 2752 | "field value is required for DictComp"); |
| 2753 | return NULL; |
| 2754 | } |
| 2755 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2756 | if (!p) |
| 2757 | return NULL; |
| 2758 | p->kind = DictComp_kind; |
| 2759 | p->v.DictComp.key = key; |
| 2760 | p->v.DictComp.value = value; |
| 2761 | p->v.DictComp.generators = generators; |
| 2762 | p->lineno = lineno; |
| 2763 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2764 | p->end_lineno = end_lineno; |
| 2765 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2766 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2770 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2771 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2772 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2773 | expr_ty p; |
| 2774 | if (!elt) { |
| 2775 | PyErr_SetString(PyExc_ValueError, |
| 2776 | "field elt is required for GeneratorExp"); |
| 2777 | return NULL; |
| 2778 | } |
| 2779 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2780 | if (!p) |
| 2781 | return NULL; |
| 2782 | p->kind = GeneratorExp_kind; |
| 2783 | p->v.GeneratorExp.elt = elt; |
| 2784 | p->v.GeneratorExp.generators = generators; |
| 2785 | p->lineno = lineno; |
| 2786 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2787 | p->end_lineno = end_lineno; |
| 2788 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2789 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2793 | Await(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2794 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2795 | { |
| 2796 | expr_ty p; |
| 2797 | if (!value) { |
| 2798 | PyErr_SetString(PyExc_ValueError, |
| 2799 | "field value is required for Await"); |
| 2800 | return NULL; |
| 2801 | } |
| 2802 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2803 | if (!p) |
| 2804 | return NULL; |
| 2805 | p->kind = Await_kind; |
| 2806 | p->v.Await.value = value; |
| 2807 | p->lineno = lineno; |
| 2808 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2809 | p->end_lineno = end_lineno; |
| 2810 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2811 | return p; |
| 2812 | } |
| 2813 | |
| 2814 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2815 | Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2816 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2817 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2818 | expr_ty p; |
| 2819 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2820 | if (!p) |
| 2821 | return NULL; |
| 2822 | p->kind = Yield_kind; |
| 2823 | p->v.Yield.value = value; |
| 2824 | p->lineno = lineno; |
| 2825 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2826 | p->end_lineno = end_lineno; |
| 2827 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2828 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2829 | } |
| 2830 | |
| 2831 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2832 | YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2833 | end_col_offset, PyArena *arena) |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2834 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2835 | expr_ty p; |
| 2836 | if (!value) { |
| 2837 | PyErr_SetString(PyExc_ValueError, |
| 2838 | "field value is required for YieldFrom"); |
| 2839 | return NULL; |
| 2840 | } |
| 2841 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2842 | if (!p) |
| 2843 | return NULL; |
| 2844 | p->kind = YieldFrom_kind; |
| 2845 | p->v.YieldFrom.value = value; |
| 2846 | p->lineno = lineno; |
| 2847 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2848 | p->end_lineno = end_lineno; |
| 2849 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2850 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2854 | 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] | 2855 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2856 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2857 | expr_ty p; |
| 2858 | if (!left) { |
| 2859 | PyErr_SetString(PyExc_ValueError, |
| 2860 | "field left is required for Compare"); |
| 2861 | return NULL; |
| 2862 | } |
| 2863 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2864 | if (!p) |
| 2865 | return NULL; |
| 2866 | p->kind = Compare_kind; |
| 2867 | p->v.Compare.left = left; |
| 2868 | p->v.Compare.ops = ops; |
| 2869 | p->v.Compare.comparators = comparators; |
| 2870 | p->lineno = lineno; |
| 2871 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2872 | p->end_lineno = end_lineno; |
| 2873 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2874 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2878 | 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] | 2879 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2880 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2881 | expr_ty p; |
| 2882 | if (!func) { |
| 2883 | PyErr_SetString(PyExc_ValueError, |
| 2884 | "field func is required for Call"); |
| 2885 | return NULL; |
| 2886 | } |
| 2887 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2888 | if (!p) |
| 2889 | return NULL; |
| 2890 | p->kind = Call_kind; |
| 2891 | p->v.Call.func = func; |
| 2892 | p->v.Call.args = args; |
| 2893 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2894 | p->lineno = lineno; |
| 2895 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2896 | p->end_lineno = end_lineno; |
| 2897 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2898 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | expr_ty |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 2902 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
| 2903 | int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2904 | *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2905 | { |
| 2906 | expr_ty p; |
| 2907 | if (!value) { |
| 2908 | PyErr_SetString(PyExc_ValueError, |
| 2909 | "field value is required for FormattedValue"); |
| 2910 | return NULL; |
| 2911 | } |
| 2912 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2913 | if (!p) |
| 2914 | return NULL; |
| 2915 | p->kind = FormattedValue_kind; |
| 2916 | p->v.FormattedValue.value = value; |
| 2917 | p->v.FormattedValue.conversion = conversion; |
| 2918 | p->v.FormattedValue.format_spec = format_spec; |
| 2919 | p->lineno = lineno; |
| 2920 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2921 | p->end_lineno = end_lineno; |
| 2922 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2923 | return p; |
| 2924 | } |
| 2925 | |
| 2926 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2927 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 2928 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2929 | { |
| 2930 | expr_ty p; |
| 2931 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2932 | if (!p) |
| 2933 | return NULL; |
| 2934 | p->kind = JoinedStr_kind; |
| 2935 | p->v.JoinedStr.values = values; |
| 2936 | p->lineno = lineno; |
| 2937 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2938 | p->end_lineno = end_lineno; |
| 2939 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2940 | return p; |
| 2941 | } |
| 2942 | |
| 2943 | expr_ty |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 2944 | Constant(constant value, string kind, int lineno, int col_offset, int |
| 2945 | end_lineno, int end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2946 | { |
| 2947 | expr_ty p; |
| 2948 | if (!value) { |
| 2949 | PyErr_SetString(PyExc_ValueError, |
| 2950 | "field value is required for Constant"); |
| 2951 | return NULL; |
| 2952 | } |
| 2953 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2954 | if (!p) |
| 2955 | return NULL; |
| 2956 | p->kind = Constant_kind; |
| 2957 | p->v.Constant.value = value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 2958 | p->v.Constant.kind = kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2959 | p->lineno = lineno; |
| 2960 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2961 | p->end_lineno = end_lineno; |
| 2962 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2963 | return p; |
| 2964 | } |
| 2965 | |
| 2966 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2967 | 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] | 2968 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2969 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2970 | expr_ty p; |
| 2971 | if (!value) { |
| 2972 | PyErr_SetString(PyExc_ValueError, |
| 2973 | "field value is required for Attribute"); |
| 2974 | return NULL; |
| 2975 | } |
| 2976 | if (!attr) { |
| 2977 | PyErr_SetString(PyExc_ValueError, |
| 2978 | "field attr is required for Attribute"); |
| 2979 | return NULL; |
| 2980 | } |
| 2981 | if (!ctx) { |
| 2982 | PyErr_SetString(PyExc_ValueError, |
| 2983 | "field ctx is required for Attribute"); |
| 2984 | return NULL; |
| 2985 | } |
| 2986 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2987 | if (!p) |
| 2988 | return NULL; |
| 2989 | p->kind = Attribute_kind; |
| 2990 | p->v.Attribute.value = value; |
| 2991 | p->v.Attribute.attr = attr; |
| 2992 | p->v.Attribute.ctx = ctx; |
| 2993 | p->lineno = lineno; |
| 2994 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2995 | p->end_lineno = end_lineno; |
| 2996 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2997 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3001 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3002 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3003 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3004 | expr_ty p; |
| 3005 | if (!value) { |
| 3006 | PyErr_SetString(PyExc_ValueError, |
| 3007 | "field value is required for Subscript"); |
| 3008 | return NULL; |
| 3009 | } |
| 3010 | if (!slice) { |
| 3011 | PyErr_SetString(PyExc_ValueError, |
| 3012 | "field slice is required for Subscript"); |
| 3013 | return NULL; |
| 3014 | } |
| 3015 | if (!ctx) { |
| 3016 | PyErr_SetString(PyExc_ValueError, |
| 3017 | "field ctx is required for Subscript"); |
| 3018 | return NULL; |
| 3019 | } |
| 3020 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3021 | if (!p) |
| 3022 | return NULL; |
| 3023 | p->kind = Subscript_kind; |
| 3024 | p->v.Subscript.value = value; |
| 3025 | p->v.Subscript.slice = slice; |
| 3026 | p->v.Subscript.ctx = ctx; |
| 3027 | p->lineno = lineno; |
| 3028 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3029 | p->end_lineno = end_lineno; |
| 3030 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3031 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3035 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 3036 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3037 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3038 | expr_ty p; |
| 3039 | if (!value) { |
| 3040 | PyErr_SetString(PyExc_ValueError, |
| 3041 | "field value is required for Starred"); |
| 3042 | return NULL; |
| 3043 | } |
| 3044 | if (!ctx) { |
| 3045 | PyErr_SetString(PyExc_ValueError, |
| 3046 | "field ctx is required for Starred"); |
| 3047 | return NULL; |
| 3048 | } |
| 3049 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3050 | if (!p) |
| 3051 | return NULL; |
| 3052 | p->kind = Starred_kind; |
| 3053 | p->v.Starred.value = value; |
| 3054 | p->v.Starred.ctx = ctx; |
| 3055 | p->lineno = lineno; |
| 3056 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3057 | p->end_lineno = end_lineno; |
| 3058 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3059 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3063 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 3064 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3065 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3066 | expr_ty p; |
| 3067 | if (!id) { |
| 3068 | PyErr_SetString(PyExc_ValueError, |
| 3069 | "field id is required for Name"); |
| 3070 | return NULL; |
| 3071 | } |
| 3072 | if (!ctx) { |
| 3073 | PyErr_SetString(PyExc_ValueError, |
| 3074 | "field ctx is required for Name"); |
| 3075 | return NULL; |
| 3076 | } |
| 3077 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3078 | if (!p) |
| 3079 | return NULL; |
| 3080 | p->kind = Name_kind; |
| 3081 | p->v.Name.id = id; |
| 3082 | p->v.Name.ctx = ctx; |
| 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 |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3091 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3092 | 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 (!ctx) { |
| 3096 | PyErr_SetString(PyExc_ValueError, |
| 3097 | "field ctx is required for List"); |
| 3098 | return NULL; |
| 3099 | } |
| 3100 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3101 | if (!p) |
| 3102 | return NULL; |
| 3103 | p->kind = List_kind; |
| 3104 | p->v.List.elts = elts; |
| 3105 | p->v.List.ctx = ctx; |
| 3106 | p->lineno = lineno; |
| 3107 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3108 | p->end_lineno = end_lineno; |
| 3109 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3110 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3111 | } |
| 3112 | |
| 3113 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3114 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3115 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3116 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3117 | expr_ty p; |
| 3118 | if (!ctx) { |
| 3119 | PyErr_SetString(PyExc_ValueError, |
| 3120 | "field ctx is required for Tuple"); |
| 3121 | return NULL; |
| 3122 | } |
| 3123 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3124 | if (!p) |
| 3125 | return NULL; |
| 3126 | p->kind = Tuple_kind; |
| 3127 | p->v.Tuple.elts = elts; |
| 3128 | p->v.Tuple.ctx = ctx; |
| 3129 | p->lineno = lineno; |
| 3130 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3131 | p->end_lineno = end_lineno; |
| 3132 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3133 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3134 | } |
| 3135 | |
| 3136 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3137 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3138 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3139 | slice_ty p; |
| 3140 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3141 | if (!p) |
| 3142 | return NULL; |
| 3143 | p->kind = Slice_kind; |
| 3144 | p->v.Slice.lower = lower; |
| 3145 | p->v.Slice.upper = upper; |
| 3146 | p->v.Slice.step = step; |
| 3147 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3148 | } |
| 3149 | |
| 3150 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3151 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3152 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3153 | slice_ty p; |
| 3154 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3155 | if (!p) |
| 3156 | return NULL; |
| 3157 | p->kind = ExtSlice_kind; |
| 3158 | p->v.ExtSlice.dims = dims; |
| 3159 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3163 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3164 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3165 | slice_ty p; |
| 3166 | if (!value) { |
| 3167 | PyErr_SetString(PyExc_ValueError, |
| 3168 | "field value is required for Index"); |
| 3169 | return NULL; |
| 3170 | } |
| 3171 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3172 | if (!p) |
| 3173 | return NULL; |
| 3174 | p->kind = Index_kind; |
| 3175 | p->v.Index.value = value; |
| 3176 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3177 | } |
| 3178 | |
| 3179 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3180 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 3181 | 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 | comprehension_ty p; |
| 3184 | if (!target) { |
| 3185 | PyErr_SetString(PyExc_ValueError, |
| 3186 | "field target is required for comprehension"); |
| 3187 | return NULL; |
| 3188 | } |
| 3189 | if (!iter) { |
| 3190 | PyErr_SetString(PyExc_ValueError, |
| 3191 | "field iter is required for comprehension"); |
| 3192 | return NULL; |
| 3193 | } |
| 3194 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3195 | if (!p) |
| 3196 | return NULL; |
| 3197 | p->target = target; |
| 3198 | p->iter = iter; |
| 3199 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3200 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3201 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3202 | } |
| 3203 | |
| 3204 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3205 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3206 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3207 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3208 | excepthandler_ty p; |
| 3209 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3210 | if (!p) |
| 3211 | return NULL; |
| 3212 | p->kind = ExceptHandler_kind; |
| 3213 | p->v.ExceptHandler.type = type; |
| 3214 | p->v.ExceptHandler.name = name; |
| 3215 | p->v.ExceptHandler.body = body; |
| 3216 | p->lineno = lineno; |
| 3217 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3218 | p->end_lineno = end_lineno; |
| 3219 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3220 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3221 | } |
| 3222 | |
| 3223 | arguments_ty |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3224 | arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq * |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3225 | kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq * |
| 3226 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3227 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3228 | arguments_ty p; |
| 3229 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3230 | if (!p) |
| 3231 | return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3232 | p->posonlyargs = posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3233 | p->args = args; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3234 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3235 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3236 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3237 | p->kwarg = kwarg; |
| 3238 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3239 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3240 | } |
| 3241 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3242 | arg_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3243 | arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int |
| 3244 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3245 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3246 | arg_ty p; |
| 3247 | if (!arg) { |
| 3248 | PyErr_SetString(PyExc_ValueError, |
| 3249 | "field arg is required for arg"); |
| 3250 | return NULL; |
| 3251 | } |
| 3252 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3253 | if (!p) |
| 3254 | return NULL; |
| 3255 | p->arg = arg; |
| 3256 | p->annotation = annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3257 | p->type_comment = type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 3258 | p->lineno = lineno; |
| 3259 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3260 | p->end_lineno = end_lineno; |
| 3261 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3262 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3263 | } |
| 3264 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3265 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3266 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3267 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3268 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3269 | if (!value) { |
| 3270 | PyErr_SetString(PyExc_ValueError, |
| 3271 | "field value is required for keyword"); |
| 3272 | return NULL; |
| 3273 | } |
| 3274 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3275 | if (!p) |
| 3276 | return NULL; |
| 3277 | p->arg = arg; |
| 3278 | p->value = value; |
| 3279 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3283 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3284 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3285 | alias_ty p; |
| 3286 | if (!name) { |
| 3287 | PyErr_SetString(PyExc_ValueError, |
| 3288 | "field name is required for alias"); |
| 3289 | return NULL; |
| 3290 | } |
| 3291 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3292 | if (!p) |
| 3293 | return NULL; |
| 3294 | p->name = name; |
| 3295 | p->asname = asname; |
| 3296 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3297 | } |
| 3298 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3299 | withitem_ty |
| 3300 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 3301 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3302 | withitem_ty p; |
| 3303 | if (!context_expr) { |
| 3304 | PyErr_SetString(PyExc_ValueError, |
| 3305 | "field context_expr is required for withitem"); |
| 3306 | return NULL; |
| 3307 | } |
| 3308 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3309 | if (!p) |
| 3310 | return NULL; |
| 3311 | p->context_expr = context_expr; |
| 3312 | p->optional_vars = optional_vars; |
| 3313 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3314 | } |
| 3315 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3316 | type_ignore_ty |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3317 | TypeIgnore(int lineno, string tag, PyArena *arena) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3318 | { |
| 3319 | type_ignore_ty p; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3320 | if (!tag) { |
| 3321 | PyErr_SetString(PyExc_ValueError, |
| 3322 | "field tag is required for TypeIgnore"); |
| 3323 | return NULL; |
| 3324 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3325 | p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3326 | if (!p) |
| 3327 | return NULL; |
| 3328 | p->kind = TypeIgnore_kind; |
| 3329 | p->v.TypeIgnore.lineno = lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3330 | p->v.TypeIgnore.tag = tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3331 | return p; |
| 3332 | } |
| 3333 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3334 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3335 | PyObject* |
| 3336 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3337 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3338 | mod_ty o = (mod_ty)_o; |
| 3339 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3340 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3341 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3342 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3343 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3344 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3345 | switch (o->kind) { |
| 3346 | case Module_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3347 | tp = (PyTypeObject *)astmodulestate_global->Module_type; |
| 3348 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3349 | if (!result) goto failed; |
| 3350 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 3351 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3352 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3353 | goto failed; |
| 3354 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3355 | value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); |
| 3356 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3357 | if (PyObject_SetAttr(result, astmodulestate_global->type_ignores, |
| 3358 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3359 | goto failed; |
| 3360 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3361 | break; |
| 3362 | case Interactive_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3363 | tp = (PyTypeObject *)astmodulestate_global->Interactive_type; |
| 3364 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3365 | if (!result) goto failed; |
| 3366 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 3367 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3368 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3369 | goto failed; |
| 3370 | Py_DECREF(value); |
| 3371 | break; |
| 3372 | case Expression_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3373 | tp = (PyTypeObject *)astmodulestate_global->Expression_type; |
| 3374 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3375 | if (!result) goto failed; |
| 3376 | value = ast2obj_expr(o->v.Expression.body); |
| 3377 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3378 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3379 | goto failed; |
| 3380 | Py_DECREF(value); |
| 3381 | break; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3382 | case FunctionType_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3383 | tp = (PyTypeObject *)astmodulestate_global->FunctionType_type; |
| 3384 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3385 | if (!result) goto failed; |
| 3386 | value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); |
| 3387 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3388 | if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) == |
| 3389 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3390 | goto failed; |
| 3391 | Py_DECREF(value); |
| 3392 | value = ast2obj_expr(o->v.FunctionType.returns); |
| 3393 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3394 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3395 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3396 | goto failed; |
| 3397 | Py_DECREF(value); |
| 3398 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3399 | } |
| 3400 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3401 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3402 | Py_XDECREF(value); |
| 3403 | Py_XDECREF(result); |
| 3404 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3405 | } |
| 3406 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3407 | PyObject* |
| 3408 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3409 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3410 | stmt_ty o = (stmt_ty)_o; |
| 3411 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3412 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3413 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3414 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3415 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3416 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3417 | switch (o->kind) { |
| 3418 | case FunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3419 | tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type; |
| 3420 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3421 | if (!result) goto failed; |
| 3422 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3423 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3424 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3425 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3426 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3427 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3428 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3429 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3430 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3431 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3432 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 3433 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3434 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3435 | goto failed; |
| 3436 | Py_DECREF(value); |
| 3437 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 3438 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3439 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3440 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3441 | goto failed; |
| 3442 | Py_DECREF(value); |
| 3443 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 3444 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3445 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3446 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3447 | goto failed; |
| 3448 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3449 | value = ast2obj_string(o->v.FunctionDef.type_comment); |
| 3450 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3451 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3452 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3453 | goto failed; |
| 3454 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3455 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3456 | case AsyncFunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3457 | tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type; |
| 3458 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3459 | if (!result) goto failed; |
| 3460 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 3461 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3462 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3463 | goto failed; |
| 3464 | Py_DECREF(value); |
| 3465 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 3466 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3467 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3468 | goto failed; |
| 3469 | Py_DECREF(value); |
| 3470 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 3471 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3472 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3473 | goto failed; |
| 3474 | Py_DECREF(value); |
| 3475 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 3476 | ast2obj_expr); |
| 3477 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3478 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3479 | value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3480 | goto failed; |
| 3481 | Py_DECREF(value); |
| 3482 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 3483 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3484 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3485 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3486 | goto failed; |
| 3487 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3488 | value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); |
| 3489 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3490 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3491 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3492 | goto failed; |
| 3493 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3494 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3495 | case ClassDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3496 | tp = (PyTypeObject *)astmodulestate_global->ClassDef_type; |
| 3497 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3498 | if (!result) goto failed; |
| 3499 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 3500 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3501 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3502 | goto failed; |
| 3503 | Py_DECREF(value); |
| 3504 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 3505 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3506 | if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3507 | goto failed; |
| 3508 | Py_DECREF(value); |
| 3509 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 3510 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3511 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 3512 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3513 | goto failed; |
| 3514 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3515 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 3516 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3517 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3518 | goto failed; |
| 3519 | Py_DECREF(value); |
| 3520 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 3521 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3522 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3523 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3524 | goto failed; |
| 3525 | Py_DECREF(value); |
| 3526 | break; |
| 3527 | case Return_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3528 | tp = (PyTypeObject *)astmodulestate_global->Return_type; |
| 3529 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3530 | if (!result) goto failed; |
| 3531 | value = ast2obj_expr(o->v.Return.value); |
| 3532 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3533 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3534 | goto failed; |
| 3535 | Py_DECREF(value); |
| 3536 | break; |
| 3537 | case Delete_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3538 | tp = (PyTypeObject *)astmodulestate_global->Delete_type; |
| 3539 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3540 | if (!result) goto failed; |
| 3541 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 3542 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3543 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3544 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3545 | goto failed; |
| 3546 | Py_DECREF(value); |
| 3547 | break; |
| 3548 | case Assign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3549 | tp = (PyTypeObject *)astmodulestate_global->Assign_type; |
| 3550 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3551 | if (!result) goto failed; |
| 3552 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 3553 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3554 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3555 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3556 | goto failed; |
| 3557 | Py_DECREF(value); |
| 3558 | value = ast2obj_expr(o->v.Assign.value); |
| 3559 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3560 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3561 | goto failed; |
| 3562 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3563 | value = ast2obj_string(o->v.Assign.type_comment); |
| 3564 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3565 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3566 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3567 | goto failed; |
| 3568 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3569 | break; |
| 3570 | case AugAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3571 | tp = (PyTypeObject *)astmodulestate_global->AugAssign_type; |
| 3572 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3573 | if (!result) goto failed; |
| 3574 | value = ast2obj_expr(o->v.AugAssign.target); |
| 3575 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3576 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3577 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3578 | goto failed; |
| 3579 | Py_DECREF(value); |
| 3580 | value = ast2obj_operator(o->v.AugAssign.op); |
| 3581 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3582 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3583 | goto failed; |
| 3584 | Py_DECREF(value); |
| 3585 | value = ast2obj_expr(o->v.AugAssign.value); |
| 3586 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3587 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3588 | goto failed; |
| 3589 | Py_DECREF(value); |
| 3590 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3591 | case AnnAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3592 | tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type; |
| 3593 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3594 | if (!result) goto failed; |
| 3595 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 3596 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3597 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3598 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3599 | goto failed; |
| 3600 | Py_DECREF(value); |
| 3601 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 3602 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3603 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) |
| 3604 | == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3605 | goto failed; |
| 3606 | Py_DECREF(value); |
| 3607 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 3608 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3609 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3610 | goto failed; |
| 3611 | Py_DECREF(value); |
| 3612 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 3613 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3614 | if (PyObject_SetAttr(result, astmodulestate_global->simple, value) == |
| 3615 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3616 | goto failed; |
| 3617 | Py_DECREF(value); |
| 3618 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3619 | case For_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3620 | tp = (PyTypeObject *)astmodulestate_global->For_type; |
| 3621 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3622 | if (!result) goto failed; |
| 3623 | value = ast2obj_expr(o->v.For.target); |
| 3624 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3625 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3626 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3627 | goto failed; |
| 3628 | Py_DECREF(value); |
| 3629 | value = ast2obj_expr(o->v.For.iter); |
| 3630 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3631 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3632 | goto failed; |
| 3633 | Py_DECREF(value); |
| 3634 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 3635 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3636 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3637 | goto failed; |
| 3638 | Py_DECREF(value); |
| 3639 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 3640 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3641 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3642 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3643 | goto failed; |
| 3644 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3645 | value = ast2obj_string(o->v.For.type_comment); |
| 3646 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3647 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3648 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3649 | goto failed; |
| 3650 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3651 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3652 | case AsyncFor_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3653 | tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type; |
| 3654 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3655 | if (!result) goto failed; |
| 3656 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 3657 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3658 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3659 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3660 | goto failed; |
| 3661 | Py_DECREF(value); |
| 3662 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 3663 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3664 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3665 | goto failed; |
| 3666 | Py_DECREF(value); |
| 3667 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 3668 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3669 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3670 | goto failed; |
| 3671 | Py_DECREF(value); |
| 3672 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 3673 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3674 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3675 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3676 | goto failed; |
| 3677 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3678 | value = ast2obj_string(o->v.AsyncFor.type_comment); |
| 3679 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3680 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3681 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3682 | goto failed; |
| 3683 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3684 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3685 | case While_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3686 | tp = (PyTypeObject *)astmodulestate_global->While_type; |
| 3687 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3688 | if (!result) goto failed; |
| 3689 | value = ast2obj_expr(o->v.While.test); |
| 3690 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3691 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3692 | goto failed; |
| 3693 | Py_DECREF(value); |
| 3694 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 3695 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3696 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3697 | goto failed; |
| 3698 | Py_DECREF(value); |
| 3699 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 3700 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3701 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3702 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3703 | goto failed; |
| 3704 | Py_DECREF(value); |
| 3705 | break; |
| 3706 | case If_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3707 | tp = (PyTypeObject *)astmodulestate_global->If_type; |
| 3708 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3709 | if (!result) goto failed; |
| 3710 | value = ast2obj_expr(o->v.If.test); |
| 3711 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3712 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3713 | goto failed; |
| 3714 | Py_DECREF(value); |
| 3715 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 3716 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3717 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3718 | goto failed; |
| 3719 | Py_DECREF(value); |
| 3720 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 3721 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3722 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3723 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3724 | goto failed; |
| 3725 | Py_DECREF(value); |
| 3726 | break; |
| 3727 | case With_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3728 | tp = (PyTypeObject *)astmodulestate_global->With_type; |
| 3729 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3730 | if (!result) goto failed; |
| 3731 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 3732 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3733 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3734 | goto failed; |
| 3735 | Py_DECREF(value); |
| 3736 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 3737 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3738 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3739 | goto failed; |
| 3740 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3741 | value = ast2obj_string(o->v.With.type_comment); |
| 3742 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3743 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3744 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3745 | goto failed; |
| 3746 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3747 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3748 | case AsyncWith_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3749 | tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type; |
| 3750 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3751 | if (!result) goto failed; |
| 3752 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 3753 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3754 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3755 | goto failed; |
| 3756 | Py_DECREF(value); |
| 3757 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 3758 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3759 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3760 | goto failed; |
| 3761 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3762 | value = ast2obj_string(o->v.AsyncWith.type_comment); |
| 3763 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3764 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3765 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3766 | goto failed; |
| 3767 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3768 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3769 | case Raise_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3770 | tp = (PyTypeObject *)astmodulestate_global->Raise_type; |
| 3771 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3772 | if (!result) goto failed; |
| 3773 | value = ast2obj_expr(o->v.Raise.exc); |
| 3774 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3775 | if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3776 | goto failed; |
| 3777 | Py_DECREF(value); |
| 3778 | value = ast2obj_expr(o->v.Raise.cause); |
| 3779 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3780 | if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3781 | goto failed; |
| 3782 | Py_DECREF(value); |
| 3783 | break; |
| 3784 | case Try_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3785 | tp = (PyTypeObject *)astmodulestate_global->Try_type; |
| 3786 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3787 | if (!result) goto failed; |
| 3788 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 3789 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3790 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3791 | goto failed; |
| 3792 | Py_DECREF(value); |
| 3793 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 3794 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3795 | if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) == |
| 3796 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3797 | goto failed; |
| 3798 | Py_DECREF(value); |
| 3799 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 3800 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3801 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3802 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3803 | goto failed; |
| 3804 | Py_DECREF(value); |
| 3805 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 3806 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3807 | if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value) |
| 3808 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3809 | goto failed; |
| 3810 | Py_DECREF(value); |
| 3811 | break; |
| 3812 | case Assert_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3813 | tp = (PyTypeObject *)astmodulestate_global->Assert_type; |
| 3814 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3815 | if (!result) goto failed; |
| 3816 | value = ast2obj_expr(o->v.Assert.test); |
| 3817 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3818 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3819 | goto failed; |
| 3820 | Py_DECREF(value); |
| 3821 | value = ast2obj_expr(o->v.Assert.msg); |
| 3822 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3823 | if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3824 | goto failed; |
| 3825 | Py_DECREF(value); |
| 3826 | break; |
| 3827 | case Import_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3828 | tp = (PyTypeObject *)astmodulestate_global->Import_type; |
| 3829 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3830 | if (!result) goto failed; |
| 3831 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 3832 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3833 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3834 | goto failed; |
| 3835 | Py_DECREF(value); |
| 3836 | break; |
| 3837 | case ImportFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3838 | tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type; |
| 3839 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3840 | if (!result) goto failed; |
| 3841 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 3842 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3843 | if (PyObject_SetAttr(result, astmodulestate_global->module, value) == |
| 3844 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3845 | goto failed; |
| 3846 | Py_DECREF(value); |
| 3847 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 3848 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3849 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3850 | goto failed; |
| 3851 | Py_DECREF(value); |
| 3852 | value = ast2obj_int(o->v.ImportFrom.level); |
| 3853 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3854 | if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3855 | goto failed; |
| 3856 | Py_DECREF(value); |
| 3857 | break; |
| 3858 | case Global_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3859 | tp = (PyTypeObject *)astmodulestate_global->Global_type; |
| 3860 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3861 | if (!result) goto failed; |
| 3862 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 3863 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3864 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3865 | goto failed; |
| 3866 | Py_DECREF(value); |
| 3867 | break; |
| 3868 | case Nonlocal_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3869 | tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type; |
| 3870 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3871 | if (!result) goto failed; |
| 3872 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 3873 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3874 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3875 | goto failed; |
| 3876 | Py_DECREF(value); |
| 3877 | break; |
| 3878 | case Expr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3879 | tp = (PyTypeObject *)astmodulestate_global->Expr_type; |
| 3880 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3881 | if (!result) goto failed; |
| 3882 | value = ast2obj_expr(o->v.Expr.value); |
| 3883 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3884 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3885 | goto failed; |
| 3886 | Py_DECREF(value); |
| 3887 | break; |
| 3888 | case Pass_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3889 | tp = (PyTypeObject *)astmodulestate_global->Pass_type; |
| 3890 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3891 | if (!result) goto failed; |
| 3892 | break; |
| 3893 | case Break_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3894 | tp = (PyTypeObject *)astmodulestate_global->Break_type; |
| 3895 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3896 | if (!result) goto failed; |
| 3897 | break; |
| 3898 | case Continue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3899 | tp = (PyTypeObject *)astmodulestate_global->Continue_type; |
| 3900 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3901 | if (!result) goto failed; |
| 3902 | break; |
| 3903 | } |
| 3904 | value = ast2obj_int(o->lineno); |
| 3905 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3906 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3907 | goto failed; |
| 3908 | Py_DECREF(value); |
| 3909 | value = ast2obj_int(o->col_offset); |
| 3910 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3911 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3912 | goto failed; |
| 3913 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3914 | value = ast2obj_int(o->end_lineno); |
| 3915 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3916 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3917 | goto failed; |
| 3918 | Py_DECREF(value); |
| 3919 | value = ast2obj_int(o->end_col_offset); |
| 3920 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3921 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 3922 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3923 | goto failed; |
| 3924 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3925 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3926 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3927 | Py_XDECREF(value); |
| 3928 | Py_XDECREF(result); |
| 3929 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3930 | } |
| 3931 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3932 | PyObject* |
| 3933 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3934 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3935 | expr_ty o = (expr_ty)_o; |
| 3936 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3937 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3938 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3939 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3940 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3941 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3942 | switch (o->kind) { |
| 3943 | case BoolOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3944 | tp = (PyTypeObject *)astmodulestate_global->BoolOp_type; |
| 3945 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3946 | if (!result) goto failed; |
| 3947 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 3948 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3949 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3950 | goto failed; |
| 3951 | Py_DECREF(value); |
| 3952 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 3953 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3954 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 3955 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3956 | goto failed; |
| 3957 | Py_DECREF(value); |
| 3958 | break; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3959 | case NamedExpr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3960 | tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type; |
| 3961 | result = PyType_GenericNew(tp, NULL, NULL); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3962 | if (!result) goto failed; |
| 3963 | value = ast2obj_expr(o->v.NamedExpr.target); |
| 3964 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3965 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3966 | -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3967 | goto failed; |
| 3968 | Py_DECREF(value); |
| 3969 | value = ast2obj_expr(o->v.NamedExpr.value); |
| 3970 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3971 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3972 | goto failed; |
| 3973 | Py_DECREF(value); |
| 3974 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3975 | case BinOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3976 | tp = (PyTypeObject *)astmodulestate_global->BinOp_type; |
| 3977 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3978 | if (!result) goto failed; |
| 3979 | value = ast2obj_expr(o->v.BinOp.left); |
| 3980 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3981 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3982 | goto failed; |
| 3983 | Py_DECREF(value); |
| 3984 | value = ast2obj_operator(o->v.BinOp.op); |
| 3985 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3986 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3987 | goto failed; |
| 3988 | Py_DECREF(value); |
| 3989 | value = ast2obj_expr(o->v.BinOp.right); |
| 3990 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3991 | if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3992 | goto failed; |
| 3993 | Py_DECREF(value); |
| 3994 | break; |
| 3995 | case UnaryOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3996 | tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type; |
| 3997 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3998 | if (!result) goto failed; |
| 3999 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 4000 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4001 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4002 | goto failed; |
| 4003 | Py_DECREF(value); |
| 4004 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 4005 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4006 | if (PyObject_SetAttr(result, astmodulestate_global->operand, value) == |
| 4007 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4008 | goto failed; |
| 4009 | Py_DECREF(value); |
| 4010 | break; |
| 4011 | case Lambda_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4012 | tp = (PyTypeObject *)astmodulestate_global->Lambda_type; |
| 4013 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4014 | if (!result) goto failed; |
| 4015 | value = ast2obj_arguments(o->v.Lambda.args); |
| 4016 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4017 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4018 | goto failed; |
| 4019 | Py_DECREF(value); |
| 4020 | value = ast2obj_expr(o->v.Lambda.body); |
| 4021 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4022 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4023 | goto failed; |
| 4024 | Py_DECREF(value); |
| 4025 | break; |
| 4026 | case IfExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4027 | tp = (PyTypeObject *)astmodulestate_global->IfExp_type; |
| 4028 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4029 | if (!result) goto failed; |
| 4030 | value = ast2obj_expr(o->v.IfExp.test); |
| 4031 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4032 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4033 | goto failed; |
| 4034 | Py_DECREF(value); |
| 4035 | value = ast2obj_expr(o->v.IfExp.body); |
| 4036 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4037 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4038 | goto failed; |
| 4039 | Py_DECREF(value); |
| 4040 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 4041 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4042 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 4043 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4044 | goto failed; |
| 4045 | Py_DECREF(value); |
| 4046 | break; |
| 4047 | case Dict_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4048 | tp = (PyTypeObject *)astmodulestate_global->Dict_type; |
| 4049 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4050 | if (!result) goto failed; |
| 4051 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 4052 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4053 | if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4054 | goto failed; |
| 4055 | Py_DECREF(value); |
| 4056 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 4057 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4058 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4059 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4060 | goto failed; |
| 4061 | Py_DECREF(value); |
| 4062 | break; |
| 4063 | case Set_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4064 | tp = (PyTypeObject *)astmodulestate_global->Set_type; |
| 4065 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4066 | if (!result) goto failed; |
| 4067 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 4068 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4069 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4070 | goto failed; |
| 4071 | Py_DECREF(value); |
| 4072 | break; |
| 4073 | case ListComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4074 | tp = (PyTypeObject *)astmodulestate_global->ListComp_type; |
| 4075 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4076 | if (!result) goto failed; |
| 4077 | value = ast2obj_expr(o->v.ListComp.elt); |
| 4078 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4079 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4080 | goto failed; |
| 4081 | Py_DECREF(value); |
| 4082 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 4083 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4084 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4085 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4086 | goto failed; |
| 4087 | Py_DECREF(value); |
| 4088 | break; |
| 4089 | case SetComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4090 | tp = (PyTypeObject *)astmodulestate_global->SetComp_type; |
| 4091 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4092 | if (!result) goto failed; |
| 4093 | value = ast2obj_expr(o->v.SetComp.elt); |
| 4094 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4095 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4096 | goto failed; |
| 4097 | Py_DECREF(value); |
| 4098 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 4099 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4100 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4101 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4102 | goto failed; |
| 4103 | Py_DECREF(value); |
| 4104 | break; |
| 4105 | case DictComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4106 | tp = (PyTypeObject *)astmodulestate_global->DictComp_type; |
| 4107 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4108 | if (!result) goto failed; |
| 4109 | value = ast2obj_expr(o->v.DictComp.key); |
| 4110 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4111 | if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4112 | goto failed; |
| 4113 | Py_DECREF(value); |
| 4114 | value = ast2obj_expr(o->v.DictComp.value); |
| 4115 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4116 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4117 | goto failed; |
| 4118 | Py_DECREF(value); |
| 4119 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 4120 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4121 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4122 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4123 | goto failed; |
| 4124 | Py_DECREF(value); |
| 4125 | break; |
| 4126 | case GeneratorExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4127 | tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type; |
| 4128 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4129 | if (!result) goto failed; |
| 4130 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 4131 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4132 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4133 | goto failed; |
| 4134 | Py_DECREF(value); |
| 4135 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 4136 | ast2obj_comprehension); |
| 4137 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4138 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4139 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4140 | goto failed; |
| 4141 | Py_DECREF(value); |
| 4142 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4143 | case Await_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4144 | tp = (PyTypeObject *)astmodulestate_global->Await_type; |
| 4145 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4146 | if (!result) goto failed; |
| 4147 | value = ast2obj_expr(o->v.Await.value); |
| 4148 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4149 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4150 | goto failed; |
| 4151 | Py_DECREF(value); |
| 4152 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4153 | case Yield_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4154 | tp = (PyTypeObject *)astmodulestate_global->Yield_type; |
| 4155 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4156 | if (!result) goto failed; |
| 4157 | value = ast2obj_expr(o->v.Yield.value); |
| 4158 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4159 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4160 | goto failed; |
| 4161 | Py_DECREF(value); |
| 4162 | break; |
| 4163 | case YieldFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4164 | tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type; |
| 4165 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4166 | if (!result) goto failed; |
| 4167 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 4168 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4169 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4170 | goto failed; |
| 4171 | Py_DECREF(value); |
| 4172 | break; |
| 4173 | case Compare_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4174 | tp = (PyTypeObject *)astmodulestate_global->Compare_type; |
| 4175 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4176 | if (!result) goto failed; |
| 4177 | value = ast2obj_expr(o->v.Compare.left); |
| 4178 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4179 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4180 | goto failed; |
| 4181 | Py_DECREF(value); |
| 4182 | { |
| 4183 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 4184 | value = PyList_New(n); |
| 4185 | if (!value) goto failed; |
| 4186 | for(i = 0; i < n; i++) |
| 4187 | 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] | 4188 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 4189 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4190 | if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4191 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4192 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4193 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 4194 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4195 | if (PyObject_SetAttr(result, astmodulestate_global->comparators, value) |
| 4196 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4197 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4198 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4199 | break; |
| 4200 | case Call_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4201 | tp = (PyTypeObject *)astmodulestate_global->Call_type; |
| 4202 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4203 | if (!result) goto failed; |
| 4204 | value = ast2obj_expr(o->v.Call.func); |
| 4205 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4206 | if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4207 | goto failed; |
| 4208 | Py_DECREF(value); |
| 4209 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 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_list(o->v.Call.keywords, ast2obj_keyword); |
| 4215 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4216 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 4217 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4218 | goto failed; |
| 4219 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4220 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4221 | case FormattedValue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4222 | tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type; |
| 4223 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4224 | if (!result) goto failed; |
| 4225 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 4226 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4227 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4228 | goto failed; |
| 4229 | Py_DECREF(value); |
| 4230 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 4231 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4232 | if (PyObject_SetAttr(result, astmodulestate_global->conversion, value) |
| 4233 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4234 | goto failed; |
| 4235 | Py_DECREF(value); |
| 4236 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 4237 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4238 | if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value) |
| 4239 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4240 | goto failed; |
| 4241 | Py_DECREF(value); |
| 4242 | break; |
| 4243 | case JoinedStr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4244 | tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type; |
| 4245 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4246 | if (!result) goto failed; |
| 4247 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 4248 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4249 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4250 | -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4251 | goto failed; |
| 4252 | Py_DECREF(value); |
| 4253 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4254 | case Constant_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4255 | tp = (PyTypeObject *)astmodulestate_global->Constant_type; |
| 4256 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4257 | if (!result) goto failed; |
| 4258 | value = ast2obj_constant(o->v.Constant.value); |
| 4259 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4260 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4261 | goto failed; |
| 4262 | Py_DECREF(value); |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4263 | value = ast2obj_string(o->v.Constant.kind); |
| 4264 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4265 | if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1) |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4266 | goto failed; |
| 4267 | Py_DECREF(value); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4268 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4269 | case Attribute_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4270 | tp = (PyTypeObject *)astmodulestate_global->Attribute_type; |
| 4271 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4272 | if (!result) goto failed; |
| 4273 | value = ast2obj_expr(o->v.Attribute.value); |
| 4274 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4275 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4276 | goto failed; |
| 4277 | Py_DECREF(value); |
| 4278 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 4279 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4280 | if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4281 | goto failed; |
| 4282 | Py_DECREF(value); |
| 4283 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 4284 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4285 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4286 | goto failed; |
| 4287 | Py_DECREF(value); |
| 4288 | break; |
| 4289 | case Subscript_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4290 | tp = (PyTypeObject *)astmodulestate_global->Subscript_type; |
| 4291 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4292 | if (!result) goto failed; |
| 4293 | value = ast2obj_expr(o->v.Subscript.value); |
| 4294 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4295 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4296 | goto failed; |
| 4297 | Py_DECREF(value); |
| 4298 | value = ast2obj_slice(o->v.Subscript.slice); |
| 4299 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4300 | if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4301 | goto failed; |
| 4302 | Py_DECREF(value); |
| 4303 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 4304 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4305 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4306 | goto failed; |
| 4307 | Py_DECREF(value); |
| 4308 | break; |
| 4309 | case Starred_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4310 | tp = (PyTypeObject *)astmodulestate_global->Starred_type; |
| 4311 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4312 | if (!result) goto failed; |
| 4313 | value = ast2obj_expr(o->v.Starred.value); |
| 4314 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4315 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4316 | goto failed; |
| 4317 | Py_DECREF(value); |
| 4318 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 4319 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4320 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4321 | goto failed; |
| 4322 | Py_DECREF(value); |
| 4323 | break; |
| 4324 | case Name_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4325 | tp = (PyTypeObject *)astmodulestate_global->Name_type; |
| 4326 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4327 | if (!result) goto failed; |
| 4328 | value = ast2obj_identifier(o->v.Name.id); |
| 4329 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4330 | if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4331 | goto failed; |
| 4332 | Py_DECREF(value); |
| 4333 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 4334 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4335 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4336 | goto failed; |
| 4337 | Py_DECREF(value); |
| 4338 | break; |
| 4339 | case List_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4340 | tp = (PyTypeObject *)astmodulestate_global->List_type; |
| 4341 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4342 | if (!result) goto failed; |
| 4343 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 4344 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4345 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4346 | goto failed; |
| 4347 | Py_DECREF(value); |
| 4348 | value = ast2obj_expr_context(o->v.List.ctx); |
| 4349 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4350 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4351 | goto failed; |
| 4352 | Py_DECREF(value); |
| 4353 | break; |
| 4354 | case Tuple_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4355 | tp = (PyTypeObject *)astmodulestate_global->Tuple_type; |
| 4356 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4357 | if (!result) goto failed; |
| 4358 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 4359 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4360 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4361 | goto failed; |
| 4362 | Py_DECREF(value); |
| 4363 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 4364 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4365 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4366 | goto failed; |
| 4367 | Py_DECREF(value); |
| 4368 | break; |
| 4369 | } |
| 4370 | value = ast2obj_int(o->lineno); |
| 4371 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4372 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4373 | goto failed; |
| 4374 | Py_DECREF(value); |
| 4375 | value = ast2obj_int(o->col_offset); |
| 4376 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4377 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4378 | goto failed; |
| 4379 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4380 | value = ast2obj_int(o->end_lineno); |
| 4381 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4382 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4383 | goto failed; |
| 4384 | Py_DECREF(value); |
| 4385 | value = ast2obj_int(o->end_col_offset); |
| 4386 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4387 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4388 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4389 | goto failed; |
| 4390 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4391 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4392 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4393 | Py_XDECREF(value); |
| 4394 | Py_XDECREF(result); |
| 4395 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4396 | } |
| 4397 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4398 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4399 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4400 | switch(o) { |
| 4401 | case Load: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4402 | Py_INCREF(astmodulestate_global->Load_singleton); |
| 4403 | return astmodulestate_global->Load_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4404 | case Store: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4405 | Py_INCREF(astmodulestate_global->Store_singleton); |
| 4406 | return astmodulestate_global->Store_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4407 | case Del: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4408 | Py_INCREF(astmodulestate_global->Del_singleton); |
| 4409 | return astmodulestate_global->Del_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4410 | case AugLoad: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4411 | Py_INCREF(astmodulestate_global->AugLoad_singleton); |
| 4412 | return astmodulestate_global->AugLoad_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4413 | case AugStore: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4414 | Py_INCREF(astmodulestate_global->AugStore_singleton); |
| 4415 | return astmodulestate_global->AugStore_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4416 | case Param: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4417 | Py_INCREF(astmodulestate_global->Param_singleton); |
| 4418 | return astmodulestate_global->Param_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4419 | default: |
| 4420 | /* should never happen, but just in case ... */ |
| 4421 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 4422 | return NULL; |
| 4423 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4424 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4425 | PyObject* |
| 4426 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4427 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4428 | slice_ty o = (slice_ty)_o; |
| 4429 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4430 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4431 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4432 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4433 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4434 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4435 | switch (o->kind) { |
| 4436 | case Slice_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4437 | tp = (PyTypeObject *)astmodulestate_global->Slice_type; |
| 4438 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4439 | if (!result) goto failed; |
| 4440 | value = ast2obj_expr(o->v.Slice.lower); |
| 4441 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4442 | if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4443 | goto failed; |
| 4444 | Py_DECREF(value); |
| 4445 | value = ast2obj_expr(o->v.Slice.upper); |
| 4446 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4447 | if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4448 | goto failed; |
| 4449 | Py_DECREF(value); |
| 4450 | value = ast2obj_expr(o->v.Slice.step); |
| 4451 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4452 | if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4453 | goto failed; |
| 4454 | Py_DECREF(value); |
| 4455 | break; |
| 4456 | case ExtSlice_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4457 | tp = (PyTypeObject *)astmodulestate_global->ExtSlice_type; |
| 4458 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4459 | if (!result) goto failed; |
| 4460 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 4461 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4462 | if (PyObject_SetAttr(result, astmodulestate_global->dims, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4463 | goto failed; |
| 4464 | Py_DECREF(value); |
| 4465 | break; |
| 4466 | case Index_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4467 | tp = (PyTypeObject *)astmodulestate_global->Index_type; |
| 4468 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4469 | if (!result) goto failed; |
| 4470 | value = ast2obj_expr(o->v.Index.value); |
| 4471 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4472 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4473 | goto failed; |
| 4474 | Py_DECREF(value); |
| 4475 | break; |
| 4476 | } |
| 4477 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4478 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4479 | Py_XDECREF(value); |
| 4480 | Py_XDECREF(result); |
| 4481 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4482 | } |
| 4483 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4484 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4485 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4486 | switch(o) { |
| 4487 | case And: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4488 | Py_INCREF(astmodulestate_global->And_singleton); |
| 4489 | return astmodulestate_global->And_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4490 | case Or: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4491 | Py_INCREF(astmodulestate_global->Or_singleton); |
| 4492 | return astmodulestate_global->Or_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4493 | default: |
| 4494 | /* should never happen, but just in case ... */ |
| 4495 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 4496 | return NULL; |
| 4497 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4498 | } |
| 4499 | PyObject* ast2obj_operator(operator_ty o) |
| 4500 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4501 | switch(o) { |
| 4502 | case Add: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4503 | Py_INCREF(astmodulestate_global->Add_singleton); |
| 4504 | return astmodulestate_global->Add_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4505 | case Sub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4506 | Py_INCREF(astmodulestate_global->Sub_singleton); |
| 4507 | return astmodulestate_global->Sub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4508 | case Mult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4509 | Py_INCREF(astmodulestate_global->Mult_singleton); |
| 4510 | return astmodulestate_global->Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 4511 | case MatMult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4512 | Py_INCREF(astmodulestate_global->MatMult_singleton); |
| 4513 | return astmodulestate_global->MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4514 | case Div: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4515 | Py_INCREF(astmodulestate_global->Div_singleton); |
| 4516 | return astmodulestate_global->Div_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4517 | case Mod: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4518 | Py_INCREF(astmodulestate_global->Mod_singleton); |
| 4519 | return astmodulestate_global->Mod_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4520 | case Pow: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4521 | Py_INCREF(astmodulestate_global->Pow_singleton); |
| 4522 | return astmodulestate_global->Pow_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4523 | case LShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4524 | Py_INCREF(astmodulestate_global->LShift_singleton); |
| 4525 | return astmodulestate_global->LShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4526 | case RShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4527 | Py_INCREF(astmodulestate_global->RShift_singleton); |
| 4528 | return astmodulestate_global->RShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4529 | case BitOr: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4530 | Py_INCREF(astmodulestate_global->BitOr_singleton); |
| 4531 | return astmodulestate_global->BitOr_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4532 | case BitXor: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4533 | Py_INCREF(astmodulestate_global->BitXor_singleton); |
| 4534 | return astmodulestate_global->BitXor_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4535 | case BitAnd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4536 | Py_INCREF(astmodulestate_global->BitAnd_singleton); |
| 4537 | return astmodulestate_global->BitAnd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4538 | case FloorDiv: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4539 | Py_INCREF(astmodulestate_global->FloorDiv_singleton); |
| 4540 | return astmodulestate_global->FloorDiv_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4541 | default: |
| 4542 | /* should never happen, but just in case ... */ |
| 4543 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 4544 | return NULL; |
| 4545 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4546 | } |
| 4547 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 4548 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4549 | switch(o) { |
| 4550 | case Invert: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4551 | Py_INCREF(astmodulestate_global->Invert_singleton); |
| 4552 | return astmodulestate_global->Invert_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4553 | case Not: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4554 | Py_INCREF(astmodulestate_global->Not_singleton); |
| 4555 | return astmodulestate_global->Not_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4556 | case UAdd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4557 | Py_INCREF(astmodulestate_global->UAdd_singleton); |
| 4558 | return astmodulestate_global->UAdd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4559 | case USub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4560 | Py_INCREF(astmodulestate_global->USub_singleton); |
| 4561 | return astmodulestate_global->USub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4562 | default: |
| 4563 | /* should never happen, but just in case ... */ |
| 4564 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 4565 | return NULL; |
| 4566 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4567 | } |
| 4568 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 4569 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4570 | switch(o) { |
| 4571 | case Eq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4572 | Py_INCREF(astmodulestate_global->Eq_singleton); |
| 4573 | return astmodulestate_global->Eq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4574 | case NotEq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4575 | Py_INCREF(astmodulestate_global->NotEq_singleton); |
| 4576 | return astmodulestate_global->NotEq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4577 | case Lt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4578 | Py_INCREF(astmodulestate_global->Lt_singleton); |
| 4579 | return astmodulestate_global->Lt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4580 | case LtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4581 | Py_INCREF(astmodulestate_global->LtE_singleton); |
| 4582 | return astmodulestate_global->LtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4583 | case Gt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4584 | Py_INCREF(astmodulestate_global->Gt_singleton); |
| 4585 | return astmodulestate_global->Gt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4586 | case GtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4587 | Py_INCREF(astmodulestate_global->GtE_singleton); |
| 4588 | return astmodulestate_global->GtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4589 | case Is: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4590 | Py_INCREF(astmodulestate_global->Is_singleton); |
| 4591 | return astmodulestate_global->Is_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4592 | case IsNot: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4593 | Py_INCREF(astmodulestate_global->IsNot_singleton); |
| 4594 | return astmodulestate_global->IsNot_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4595 | case In: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4596 | Py_INCREF(astmodulestate_global->In_singleton); |
| 4597 | return astmodulestate_global->In_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4598 | case NotIn: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4599 | Py_INCREF(astmodulestate_global->NotIn_singleton); |
| 4600 | return astmodulestate_global->NotIn_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4601 | default: |
| 4602 | /* should never happen, but just in case ... */ |
| 4603 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 4604 | return NULL; |
| 4605 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4606 | } |
| 4607 | PyObject* |
| 4608 | ast2obj_comprehension(void* _o) |
| 4609 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4610 | comprehension_ty o = (comprehension_ty)_o; |
| 4611 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4612 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4613 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4614 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4615 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4616 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4617 | tp = (PyTypeObject *)astmodulestate_global->comprehension_type; |
| 4618 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4619 | if (!result) return NULL; |
| 4620 | value = ast2obj_expr(o->target); |
| 4621 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4622 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4623 | goto failed; |
| 4624 | Py_DECREF(value); |
| 4625 | value = ast2obj_expr(o->iter); |
| 4626 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4627 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4628 | goto failed; |
| 4629 | Py_DECREF(value); |
| 4630 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 4631 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4632 | if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4633 | goto failed; |
| 4634 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4635 | value = ast2obj_int(o->is_async); |
| 4636 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4637 | if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1) |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4638 | goto failed; |
| 4639 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4640 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4641 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4642 | Py_XDECREF(value); |
| 4643 | Py_XDECREF(result); |
| 4644 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4645 | } |
| 4646 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4647 | PyObject* |
| 4648 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4649 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4650 | excepthandler_ty o = (excepthandler_ty)_o; |
| 4651 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4652 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4653 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4654 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4655 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4656 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4657 | switch (o->kind) { |
| 4658 | case ExceptHandler_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4659 | tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type; |
| 4660 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4661 | if (!result) goto failed; |
| 4662 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4663 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4664 | if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4665 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4666 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4667 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4668 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4669 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4670 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4671 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4672 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 4673 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4674 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4675 | goto failed; |
| 4676 | Py_DECREF(value); |
| 4677 | break; |
| 4678 | } |
| 4679 | value = ast2obj_int(o->lineno); |
| 4680 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4681 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4682 | goto failed; |
| 4683 | Py_DECREF(value); |
| 4684 | value = ast2obj_int(o->col_offset); |
| 4685 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4686 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4687 | goto failed; |
| 4688 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4689 | value = ast2obj_int(o->end_lineno); |
| 4690 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4691 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4692 | goto failed; |
| 4693 | Py_DECREF(value); |
| 4694 | value = ast2obj_int(o->end_col_offset); |
| 4695 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4696 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4697 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4698 | goto failed; |
| 4699 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4700 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4701 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4702 | Py_XDECREF(value); |
| 4703 | Py_XDECREF(result); |
| 4704 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4705 | } |
| 4706 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4707 | PyObject* |
| 4708 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4709 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4710 | arguments_ty o = (arguments_ty)_o; |
| 4711 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4712 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4713 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4714 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4715 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4716 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4717 | tp = (PyTypeObject *)astmodulestate_global->arguments_type; |
| 4718 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4719 | if (!result) return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4720 | value = ast2obj_list(o->posonlyargs, ast2obj_arg); |
| 4721 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4722 | if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) == |
| 4723 | -1) |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4724 | goto failed; |
| 4725 | Py_DECREF(value); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4726 | value = ast2obj_list(o->args, ast2obj_arg); |
| 4727 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4728 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4729 | goto failed; |
| 4730 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4731 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4732 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4733 | if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4734 | goto failed; |
| 4735 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4736 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 4737 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4738 | if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) == |
| 4739 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4740 | goto failed; |
| 4741 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4742 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4743 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4744 | if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) == |
| 4745 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4746 | goto failed; |
| 4747 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4748 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4749 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4750 | if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4751 | goto failed; |
| 4752 | Py_DECREF(value); |
| 4753 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 4754 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4755 | if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4756 | goto failed; |
| 4757 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4758 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4759 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4760 | Py_XDECREF(value); |
| 4761 | Py_XDECREF(result); |
| 4762 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4763 | } |
| 4764 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4765 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4766 | ast2obj_arg(void* _o) |
| 4767 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4768 | arg_ty o = (arg_ty)_o; |
| 4769 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4770 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4771 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4772 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4773 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4774 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4775 | tp = (PyTypeObject *)astmodulestate_global->arg_type; |
| 4776 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4777 | if (!result) return NULL; |
| 4778 | value = ast2obj_identifier(o->arg); |
| 4779 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4780 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4781 | goto failed; |
| 4782 | Py_DECREF(value); |
| 4783 | value = ast2obj_expr(o->annotation); |
| 4784 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4785 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) == |
| 4786 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4787 | goto failed; |
| 4788 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4789 | value = ast2obj_string(o->type_comment); |
| 4790 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4791 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) == |
| 4792 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4793 | goto failed; |
| 4794 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4795 | value = ast2obj_int(o->lineno); |
| 4796 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4797 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4798 | goto failed; |
| 4799 | Py_DECREF(value); |
| 4800 | value = ast2obj_int(o->col_offset); |
| 4801 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4802 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4803 | goto failed; |
| 4804 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4805 | value = ast2obj_int(o->end_lineno); |
| 4806 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4807 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4808 | goto failed; |
| 4809 | Py_DECREF(value); |
| 4810 | value = ast2obj_int(o->end_col_offset); |
| 4811 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4812 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4813 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4814 | goto failed; |
| 4815 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4816 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4817 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4818 | Py_XDECREF(value); |
| 4819 | Py_XDECREF(result); |
| 4820 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4821 | } |
| 4822 | |
| 4823 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4824 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4825 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4826 | keyword_ty o = (keyword_ty)_o; |
| 4827 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4828 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4829 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4830 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4831 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4832 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4833 | tp = (PyTypeObject *)astmodulestate_global->keyword_type; |
| 4834 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4835 | if (!result) return NULL; |
| 4836 | value = ast2obj_identifier(o->arg); |
| 4837 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4838 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4839 | goto failed; |
| 4840 | Py_DECREF(value); |
| 4841 | value = ast2obj_expr(o->value); |
| 4842 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4843 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4844 | goto failed; |
| 4845 | Py_DECREF(value); |
| 4846 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4847 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4848 | Py_XDECREF(value); |
| 4849 | Py_XDECREF(result); |
| 4850 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4851 | } |
| 4852 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4853 | PyObject* |
| 4854 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4855 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4856 | alias_ty o = (alias_ty)_o; |
| 4857 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4858 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4859 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4860 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4861 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4862 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4863 | tp = (PyTypeObject *)astmodulestate_global->alias_type; |
| 4864 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4865 | if (!result) return NULL; |
| 4866 | value = ast2obj_identifier(o->name); |
| 4867 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4868 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4869 | goto failed; |
| 4870 | Py_DECREF(value); |
| 4871 | value = ast2obj_identifier(o->asname); |
| 4872 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4873 | if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4874 | goto failed; |
| 4875 | Py_DECREF(value); |
| 4876 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4877 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4878 | Py_XDECREF(value); |
| 4879 | Py_XDECREF(result); |
| 4880 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4881 | } |
| 4882 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4883 | PyObject* |
| 4884 | ast2obj_withitem(void* _o) |
| 4885 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4886 | withitem_ty o = (withitem_ty)_o; |
| 4887 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4888 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4889 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4890 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4891 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4892 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4893 | tp = (PyTypeObject *)astmodulestate_global->withitem_type; |
| 4894 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4895 | if (!result) return NULL; |
| 4896 | value = ast2obj_expr(o->context_expr); |
| 4897 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4898 | if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) == |
| 4899 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4900 | goto failed; |
| 4901 | Py_DECREF(value); |
| 4902 | value = ast2obj_expr(o->optional_vars); |
| 4903 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4904 | if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value) |
| 4905 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4906 | goto failed; |
| 4907 | Py_DECREF(value); |
| 4908 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4909 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4910 | Py_XDECREF(value); |
| 4911 | Py_XDECREF(result); |
| 4912 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4913 | } |
| 4914 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4915 | PyObject* |
| 4916 | ast2obj_type_ignore(void* _o) |
| 4917 | { |
| 4918 | type_ignore_ty o = (type_ignore_ty)_o; |
| 4919 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4920 | PyTypeObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4921 | if (!o) { |
| 4922 | Py_RETURN_NONE; |
| 4923 | } |
| 4924 | |
| 4925 | switch (o->kind) { |
| 4926 | case TypeIgnore_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4927 | tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type; |
| 4928 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4929 | if (!result) goto failed; |
| 4930 | value = ast2obj_int(o->v.TypeIgnore.lineno); |
| 4931 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4932 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) == |
| 4933 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4934 | goto failed; |
| 4935 | Py_DECREF(value); |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 4936 | value = ast2obj_string(o->v.TypeIgnore.tag); |
| 4937 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4938 | if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1) |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 4939 | goto failed; |
| 4940 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4941 | break; |
| 4942 | } |
| 4943 | return result; |
| 4944 | failed: |
| 4945 | Py_XDECREF(value); |
| 4946 | Py_XDECREF(result); |
| 4947 | return NULL; |
| 4948 | } |
| 4949 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4950 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4951 | int |
| 4952 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 4953 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4954 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4955 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4956 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4957 | PyObject *tp; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4958 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4959 | if (obj == Py_None) { |
| 4960 | *out = NULL; |
| 4961 | return 0; |
| 4962 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4963 | tp = astmodulestate_global->Module_type; |
| 4964 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4965 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4966 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4967 | } |
| 4968 | if (isinstance) { |
| 4969 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4970 | asdl_seq* type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4971 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4972 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4973 | return 1; |
| 4974 | } |
| 4975 | if (tmp == NULL) { |
| 4976 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 4977 | return 1; |
| 4978 | } |
| 4979 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4980 | int res; |
| 4981 | Py_ssize_t len; |
| 4982 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4983 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4984 | 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] | 4985 | goto failed; |
| 4986 | } |
| 4987 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4988 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4989 | if (body == NULL) goto failed; |
| 4990 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4991 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 4992 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 4993 | Py_INCREF(tmp2); |
| 4994 | res = obj2ast_stmt(tmp2, &val, arena); |
| 4995 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4996 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4997 | if (len != PyList_GET_SIZE(tmp)) { |
| 4998 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 4999 | goto failed; |
| 5000 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5001 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5002 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5003 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5004 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5005 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores, |
| 5006 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5007 | return 1; |
| 5008 | } |
| 5009 | if (tmp == NULL) { |
| 5010 | PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module"); |
| 5011 | return 1; |
| 5012 | } |
| 5013 | else { |
| 5014 | int res; |
| 5015 | Py_ssize_t len; |
| 5016 | Py_ssize_t i; |
| 5017 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5018 | 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] | 5019 | goto failed; |
| 5020 | } |
| 5021 | len = PyList_GET_SIZE(tmp); |
| 5022 | type_ignores = _Py_asdl_seq_new(len, arena); |
| 5023 | if (type_ignores == NULL) goto failed; |
| 5024 | for (i = 0; i < len; i++) { |
| 5025 | type_ignore_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5026 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5027 | Py_INCREF(tmp2); |
| 5028 | res = obj2ast_type_ignore(tmp2, &val, arena); |
| 5029 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5030 | if (res != 0) goto failed; |
| 5031 | if (len != PyList_GET_SIZE(tmp)) { |
| 5032 | PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration"); |
| 5033 | goto failed; |
| 5034 | } |
| 5035 | asdl_seq_SET(type_ignores, i, val); |
| 5036 | } |
| 5037 | Py_CLEAR(tmp); |
| 5038 | } |
| 5039 | *out = Module(body, type_ignores, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5040 | if (*out == NULL) goto failed; |
| 5041 | return 0; |
| 5042 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5043 | tp = astmodulestate_global->Interactive_type; |
| 5044 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5045 | if (isinstance == -1) { |
| 5046 | return 1; |
| 5047 | } |
| 5048 | if (isinstance) { |
| 5049 | asdl_seq* body; |
| 5050 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5051 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5052 | return 1; |
| 5053 | } |
| 5054 | if (tmp == NULL) { |
| 5055 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 5056 | return 1; |
| 5057 | } |
| 5058 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5059 | int res; |
| 5060 | Py_ssize_t len; |
| 5061 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5062 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5063 | 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] | 5064 | goto failed; |
| 5065 | } |
| 5066 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5067 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5068 | if (body == NULL) goto failed; |
| 5069 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5070 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5071 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5072 | Py_INCREF(tmp2); |
| 5073 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5074 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5075 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5076 | if (len != PyList_GET_SIZE(tmp)) { |
| 5077 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 5078 | goto failed; |
| 5079 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5080 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5081 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5082 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5083 | } |
| 5084 | *out = Interactive(body, arena); |
| 5085 | if (*out == NULL) goto failed; |
| 5086 | return 0; |
| 5087 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5088 | tp = astmodulestate_global->Expression_type; |
| 5089 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5090 | if (isinstance == -1) { |
| 5091 | return 1; |
| 5092 | } |
| 5093 | if (isinstance) { |
| 5094 | expr_ty body; |
| 5095 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5096 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5097 | return 1; |
| 5098 | } |
| 5099 | if (tmp == NULL) { |
| 5100 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 5101 | return 1; |
| 5102 | } |
| 5103 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5104 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5105 | res = obj2ast_expr(tmp, &body, arena); |
| 5106 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5107 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5108 | } |
| 5109 | *out = Expression(body, arena); |
| 5110 | if (*out == NULL) goto failed; |
| 5111 | return 0; |
| 5112 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5113 | tp = astmodulestate_global->FunctionType_type; |
| 5114 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5115 | if (isinstance == -1) { |
| 5116 | return 1; |
| 5117 | } |
| 5118 | if (isinstance) { |
| 5119 | asdl_seq* argtypes; |
| 5120 | expr_ty returns; |
| 5121 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5122 | if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) < |
| 5123 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5124 | return 1; |
| 5125 | } |
| 5126 | if (tmp == NULL) { |
| 5127 | PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType"); |
| 5128 | return 1; |
| 5129 | } |
| 5130 | else { |
| 5131 | int res; |
| 5132 | Py_ssize_t len; |
| 5133 | Py_ssize_t i; |
| 5134 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5135 | 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] | 5136 | goto failed; |
| 5137 | } |
| 5138 | len = PyList_GET_SIZE(tmp); |
| 5139 | argtypes = _Py_asdl_seq_new(len, arena); |
| 5140 | if (argtypes == NULL) goto failed; |
| 5141 | for (i = 0; i < len; i++) { |
| 5142 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5143 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5144 | Py_INCREF(tmp2); |
| 5145 | res = obj2ast_expr(tmp2, &val, arena); |
| 5146 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5147 | if (res != 0) goto failed; |
| 5148 | if (len != PyList_GET_SIZE(tmp)) { |
| 5149 | PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration"); |
| 5150 | goto failed; |
| 5151 | } |
| 5152 | asdl_seq_SET(argtypes, i, val); |
| 5153 | } |
| 5154 | Py_CLEAR(tmp); |
| 5155 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5156 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5157 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5158 | return 1; |
| 5159 | } |
| 5160 | if (tmp == NULL) { |
| 5161 | PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType"); |
| 5162 | return 1; |
| 5163 | } |
| 5164 | else { |
| 5165 | int res; |
| 5166 | res = obj2ast_expr(tmp, &returns, arena); |
| 5167 | if (res != 0) goto failed; |
| 5168 | Py_CLEAR(tmp); |
| 5169 | } |
| 5170 | *out = FunctionType(argtypes, returns, arena); |
| 5171 | if (*out == NULL) goto failed; |
| 5172 | return 0; |
| 5173 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5174 | |
| 5175 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 5176 | failed: |
| 5177 | Py_XDECREF(tmp); |
| 5178 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5179 | } |
| 5180 | |
| 5181 | int |
| 5182 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 5183 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5184 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5185 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5186 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5187 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5188 | int lineno; |
| 5189 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5190 | int end_lineno; |
| 5191 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5192 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5193 | if (obj == Py_None) { |
| 5194 | *out = NULL; |
| 5195 | return 0; |
| 5196 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5197 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5198 | return 1; |
| 5199 | } |
| 5200 | if (tmp == NULL) { |
| 5201 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 5202 | return 1; |
| 5203 | } |
| 5204 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5205 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5206 | res = obj2ast_int(tmp, &lineno, arena); |
| 5207 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5208 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5209 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5210 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 5211 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5212 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5213 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5214 | if (tmp == NULL) { |
| 5215 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 5216 | return 1; |
| 5217 | } |
| 5218 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5219 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5220 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5221 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5222 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5223 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5224 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 5225 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5226 | return 1; |
| 5227 | } |
| 5228 | if (tmp == NULL || tmp == Py_None) { |
| 5229 | Py_CLEAR(tmp); |
| 5230 | end_lineno = 0; |
| 5231 | } |
| 5232 | else { |
| 5233 | int res; |
| 5234 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 5235 | if (res != 0) goto failed; |
| 5236 | Py_CLEAR(tmp); |
| 5237 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5238 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 5239 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5240 | return 1; |
| 5241 | } |
| 5242 | if (tmp == NULL || tmp == Py_None) { |
| 5243 | Py_CLEAR(tmp); |
| 5244 | end_col_offset = 0; |
| 5245 | } |
| 5246 | else { |
| 5247 | int res; |
| 5248 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 5249 | if (res != 0) goto failed; |
| 5250 | Py_CLEAR(tmp); |
| 5251 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5252 | tp = astmodulestate_global->FunctionDef_type; |
| 5253 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5254 | if (isinstance == -1) { |
| 5255 | return 1; |
| 5256 | } |
| 5257 | if (isinstance) { |
| 5258 | identifier name; |
| 5259 | arguments_ty args; |
| 5260 | asdl_seq* body; |
| 5261 | asdl_seq* decorator_list; |
| 5262 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5263 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5264 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5265 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5266 | return 1; |
| 5267 | } |
| 5268 | if (tmp == NULL) { |
| 5269 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 5270 | return 1; |
| 5271 | } |
| 5272 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5273 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5274 | res = obj2ast_identifier(tmp, &name, arena); |
| 5275 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5276 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5277 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5278 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5279 | return 1; |
| 5280 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5281 | if (tmp == NULL) { |
| 5282 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 5283 | return 1; |
| 5284 | } |
| 5285 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5286 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5287 | res = obj2ast_arguments(tmp, &args, arena); |
| 5288 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5289 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5290 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5291 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5292 | return 1; |
| 5293 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5294 | if (tmp == NULL) { |
| 5295 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 5296 | return 1; |
| 5297 | } |
| 5298 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5299 | int res; |
| 5300 | Py_ssize_t len; |
| 5301 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5302 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5303 | 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] | 5304 | goto failed; |
| 5305 | } |
| 5306 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5307 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5308 | if (body == NULL) goto failed; |
| 5309 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5310 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5311 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5312 | Py_INCREF(tmp2); |
| 5313 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5314 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5315 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5316 | if (len != PyList_GET_SIZE(tmp)) { |
| 5317 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 5318 | goto failed; |
| 5319 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5320 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5321 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5322 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5323 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5324 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5325 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5326 | return 1; |
| 5327 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5328 | if (tmp == NULL) { |
| 5329 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 5330 | return 1; |
| 5331 | } |
| 5332 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5333 | int res; |
| 5334 | Py_ssize_t len; |
| 5335 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5336 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5337 | 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] | 5338 | goto failed; |
| 5339 | } |
| 5340 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5341 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5342 | if (decorator_list == NULL) goto failed; |
| 5343 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5344 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5345 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5346 | Py_INCREF(tmp2); |
| 5347 | res = obj2ast_expr(tmp2, &val, arena); |
| 5348 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5349 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5350 | if (len != PyList_GET_SIZE(tmp)) { |
| 5351 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 5352 | goto failed; |
| 5353 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5354 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5355 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5356 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5357 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5358 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5359 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5360 | return 1; |
| 5361 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5362 | if (tmp == NULL || tmp == Py_None) { |
| 5363 | Py_CLEAR(tmp); |
| 5364 | returns = NULL; |
| 5365 | } |
| 5366 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5367 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5368 | res = obj2ast_expr(tmp, &returns, arena); |
| 5369 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5370 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5371 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5372 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5373 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5374 | return 1; |
| 5375 | } |
| 5376 | if (tmp == NULL || tmp == Py_None) { |
| 5377 | Py_CLEAR(tmp); |
| 5378 | type_comment = NULL; |
| 5379 | } |
| 5380 | else { |
| 5381 | int res; |
| 5382 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5383 | if (res != 0) goto failed; |
| 5384 | Py_CLEAR(tmp); |
| 5385 | } |
| 5386 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 5387 | type_comment, lineno, col_offset, end_lineno, |
| 5388 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5389 | if (*out == NULL) goto failed; |
| 5390 | return 0; |
| 5391 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5392 | tp = astmodulestate_global->AsyncFunctionDef_type; |
| 5393 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5394 | if (isinstance == -1) { |
| 5395 | return 1; |
| 5396 | } |
| 5397 | if (isinstance) { |
| 5398 | identifier name; |
| 5399 | arguments_ty args; |
| 5400 | asdl_seq* body; |
| 5401 | asdl_seq* decorator_list; |
| 5402 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5403 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5404 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5405 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5406 | return 1; |
| 5407 | } |
| 5408 | if (tmp == NULL) { |
| 5409 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 5410 | return 1; |
| 5411 | } |
| 5412 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5413 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5414 | res = obj2ast_identifier(tmp, &name, arena); |
| 5415 | if (res != 0) goto failed; |
| 5416 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5417 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5418 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5419 | return 1; |
| 5420 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5421 | if (tmp == NULL) { |
| 5422 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 5423 | return 1; |
| 5424 | } |
| 5425 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5426 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5427 | res = obj2ast_arguments(tmp, &args, arena); |
| 5428 | if (res != 0) goto failed; |
| 5429 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5430 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5431 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5432 | return 1; |
| 5433 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5434 | if (tmp == NULL) { |
| 5435 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 5436 | return 1; |
| 5437 | } |
| 5438 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5439 | int res; |
| 5440 | Py_ssize_t len; |
| 5441 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5442 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5443 | 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] | 5444 | goto failed; |
| 5445 | } |
| 5446 | len = PyList_GET_SIZE(tmp); |
| 5447 | body = _Py_asdl_seq_new(len, arena); |
| 5448 | if (body == NULL) goto failed; |
| 5449 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5450 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5451 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5452 | Py_INCREF(tmp2); |
| 5453 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5454 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5455 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5456 | if (len != PyList_GET_SIZE(tmp)) { |
| 5457 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 5458 | goto failed; |
| 5459 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5460 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5461 | } |
| 5462 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5463 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5464 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5465 | &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5466 | return 1; |
| 5467 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5468 | if (tmp == NULL) { |
| 5469 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 5470 | return 1; |
| 5471 | } |
| 5472 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5473 | int res; |
| 5474 | Py_ssize_t len; |
| 5475 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5476 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5477 | 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] | 5478 | goto failed; |
| 5479 | } |
| 5480 | len = PyList_GET_SIZE(tmp); |
| 5481 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 5482 | if (decorator_list == NULL) goto failed; |
| 5483 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5484 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5485 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5486 | Py_INCREF(tmp2); |
| 5487 | res = obj2ast_expr(tmp2, &val, arena); |
| 5488 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5489 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5490 | if (len != PyList_GET_SIZE(tmp)) { |
| 5491 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 5492 | goto failed; |
| 5493 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5494 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5495 | } |
| 5496 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5497 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5498 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5499 | 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5500 | return 1; |
| 5501 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5502 | if (tmp == NULL || tmp == Py_None) { |
| 5503 | Py_CLEAR(tmp); |
| 5504 | returns = NULL; |
| 5505 | } |
| 5506 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5507 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5508 | res = obj2ast_expr(tmp, &returns, arena); |
| 5509 | if (res != 0) goto failed; |
| 5510 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5511 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5512 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5513 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5514 | return 1; |
| 5515 | } |
| 5516 | if (tmp == NULL || tmp == Py_None) { |
| 5517 | Py_CLEAR(tmp); |
| 5518 | type_comment = NULL; |
| 5519 | } |
| 5520 | else { |
| 5521 | int res; |
| 5522 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5523 | if (res != 0) goto failed; |
| 5524 | Py_CLEAR(tmp); |
| 5525 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5526 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5527 | type_comment, lineno, col_offset, end_lineno, |
| 5528 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5529 | if (*out == NULL) goto failed; |
| 5530 | return 0; |
| 5531 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5532 | tp = astmodulestate_global->ClassDef_type; |
| 5533 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5534 | if (isinstance == -1) { |
| 5535 | return 1; |
| 5536 | } |
| 5537 | if (isinstance) { |
| 5538 | identifier name; |
| 5539 | asdl_seq* bases; |
| 5540 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5541 | asdl_seq* body; |
| 5542 | asdl_seq* decorator_list; |
| 5543 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5544 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5545 | return 1; |
| 5546 | } |
| 5547 | if (tmp == NULL) { |
| 5548 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 5549 | return 1; |
| 5550 | } |
| 5551 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5552 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5553 | res = obj2ast_identifier(tmp, &name, arena); |
| 5554 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5555 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5556 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5557 | if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5558 | return 1; |
| 5559 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5560 | if (tmp == NULL) { |
| 5561 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 5562 | return 1; |
| 5563 | } |
| 5564 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5565 | int res; |
| 5566 | Py_ssize_t len; |
| 5567 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5568 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5569 | 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] | 5570 | goto failed; |
| 5571 | } |
| 5572 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5573 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5574 | if (bases == NULL) goto failed; |
| 5575 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5576 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5577 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5578 | Py_INCREF(tmp2); |
| 5579 | res = obj2ast_expr(tmp2, &val, arena); |
| 5580 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5581 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5582 | if (len != PyList_GET_SIZE(tmp)) { |
| 5583 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 5584 | goto failed; |
| 5585 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5586 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5587 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5588 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5589 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5590 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 5591 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5592 | return 1; |
| 5593 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5594 | if (tmp == NULL) { |
| 5595 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 5596 | return 1; |
| 5597 | } |
| 5598 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5599 | int res; |
| 5600 | Py_ssize_t len; |
| 5601 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5602 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5603 | 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] | 5604 | goto failed; |
| 5605 | } |
| 5606 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5607 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5608 | if (keywords == NULL) goto failed; |
| 5609 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5610 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5611 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5612 | Py_INCREF(tmp2); |
| 5613 | res = obj2ast_keyword(tmp2, &val, arena); |
| 5614 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5615 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5616 | if (len != PyList_GET_SIZE(tmp)) { |
| 5617 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 5618 | goto failed; |
| 5619 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5620 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5621 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5622 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5623 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5624 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5625 | return 1; |
| 5626 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5627 | if (tmp == NULL) { |
| 5628 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 5629 | return 1; |
| 5630 | } |
| 5631 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5632 | int res; |
| 5633 | Py_ssize_t len; |
| 5634 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5635 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5636 | 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] | 5637 | goto failed; |
| 5638 | } |
| 5639 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5640 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5641 | if (body == NULL) goto failed; |
| 5642 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5643 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5644 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5645 | Py_INCREF(tmp2); |
| 5646 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5647 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5648 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5649 | if (len != PyList_GET_SIZE(tmp)) { |
| 5650 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 5651 | goto failed; |
| 5652 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5653 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5654 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5655 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5656 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5657 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5658 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5659 | return 1; |
| 5660 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5661 | if (tmp == NULL) { |
| 5662 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 5663 | return 1; |
| 5664 | } |
| 5665 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5666 | int res; |
| 5667 | Py_ssize_t len; |
| 5668 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5669 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5670 | 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] | 5671 | goto failed; |
| 5672 | } |
| 5673 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5674 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5675 | if (decorator_list == NULL) goto failed; |
| 5676 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5677 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5678 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5679 | Py_INCREF(tmp2); |
| 5680 | res = obj2ast_expr(tmp2, &val, arena); |
| 5681 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5682 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5683 | if (len != PyList_GET_SIZE(tmp)) { |
| 5684 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
| 5685 | goto failed; |
| 5686 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5687 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5688 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5689 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5690 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 5691 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5692 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5693 | if (*out == NULL) goto failed; |
| 5694 | return 0; |
| 5695 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5696 | tp = astmodulestate_global->Return_type; |
| 5697 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5698 | if (isinstance == -1) { |
| 5699 | return 1; |
| 5700 | } |
| 5701 | if (isinstance) { |
| 5702 | expr_ty value; |
| 5703 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5704 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5705 | return 1; |
| 5706 | } |
| 5707 | if (tmp == NULL || tmp == Py_None) { |
| 5708 | Py_CLEAR(tmp); |
| 5709 | value = NULL; |
| 5710 | } |
| 5711 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5712 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5713 | res = obj2ast_expr(tmp, &value, arena); |
| 5714 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5715 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5716 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5717 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 5718 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5719 | if (*out == NULL) goto failed; |
| 5720 | return 0; |
| 5721 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5722 | tp = astmodulestate_global->Delete_type; |
| 5723 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5724 | if (isinstance == -1) { |
| 5725 | return 1; |
| 5726 | } |
| 5727 | if (isinstance) { |
| 5728 | asdl_seq* targets; |
| 5729 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5730 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5731 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5732 | return 1; |
| 5733 | } |
| 5734 | if (tmp == NULL) { |
| 5735 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 5736 | return 1; |
| 5737 | } |
| 5738 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5739 | int res; |
| 5740 | Py_ssize_t len; |
| 5741 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5742 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5743 | 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] | 5744 | goto failed; |
| 5745 | } |
| 5746 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5747 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5748 | if (targets == NULL) goto failed; |
| 5749 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5750 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5751 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5752 | Py_INCREF(tmp2); |
| 5753 | res = obj2ast_expr(tmp2, &val, arena); |
| 5754 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5755 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5756 | if (len != PyList_GET_SIZE(tmp)) { |
| 5757 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 5758 | goto failed; |
| 5759 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5760 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5761 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5762 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5763 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5764 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 5765 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5766 | if (*out == NULL) goto failed; |
| 5767 | return 0; |
| 5768 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5769 | tp = astmodulestate_global->Assign_type; |
| 5770 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5771 | if (isinstance == -1) { |
| 5772 | return 1; |
| 5773 | } |
| 5774 | if (isinstance) { |
| 5775 | asdl_seq* targets; |
| 5776 | expr_ty value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5777 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5778 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5779 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5780 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5781 | return 1; |
| 5782 | } |
| 5783 | if (tmp == NULL) { |
| 5784 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 5785 | return 1; |
| 5786 | } |
| 5787 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5788 | int res; |
| 5789 | Py_ssize_t len; |
| 5790 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5791 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5792 | 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] | 5793 | goto failed; |
| 5794 | } |
| 5795 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5796 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5797 | if (targets == NULL) goto failed; |
| 5798 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5799 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5800 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5801 | Py_INCREF(tmp2); |
| 5802 | res = obj2ast_expr(tmp2, &val, arena); |
| 5803 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5804 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5805 | if (len != PyList_GET_SIZE(tmp)) { |
| 5806 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 5807 | goto failed; |
| 5808 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5809 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5810 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5811 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5812 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5813 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5814 | return 1; |
| 5815 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5816 | if (tmp == NULL) { |
| 5817 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 5818 | return 1; |
| 5819 | } |
| 5820 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5821 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5822 | res = obj2ast_expr(tmp, &value, arena); |
| 5823 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5824 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5825 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5826 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5827 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5828 | return 1; |
| 5829 | } |
| 5830 | if (tmp == NULL || tmp == Py_None) { |
| 5831 | Py_CLEAR(tmp); |
| 5832 | type_comment = NULL; |
| 5833 | } |
| 5834 | else { |
| 5835 | int res; |
| 5836 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5837 | if (res != 0) goto failed; |
| 5838 | Py_CLEAR(tmp); |
| 5839 | } |
| 5840 | *out = Assign(targets, value, type_comment, lineno, col_offset, |
| 5841 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5842 | if (*out == NULL) goto failed; |
| 5843 | return 0; |
| 5844 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5845 | tp = astmodulestate_global->AugAssign_type; |
| 5846 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5847 | if (isinstance == -1) { |
| 5848 | return 1; |
| 5849 | } |
| 5850 | if (isinstance) { |
| 5851 | expr_ty target; |
| 5852 | operator_ty op; |
| 5853 | expr_ty value; |
| 5854 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5855 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 5856 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5857 | return 1; |
| 5858 | } |
| 5859 | if (tmp == NULL) { |
| 5860 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 5861 | return 1; |
| 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, &target, arena); |
| 5866 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5867 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5868 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5869 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5870 | return 1; |
| 5871 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5872 | if (tmp == NULL) { |
| 5873 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 5874 | return 1; |
| 5875 | } |
| 5876 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5877 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5878 | res = obj2ast_operator(tmp, &op, arena); |
| 5879 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5880 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5881 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5882 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5883 | return 1; |
| 5884 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5885 | if (tmp == NULL) { |
| 5886 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 5887 | return 1; |
| 5888 | } |
| 5889 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5890 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5891 | res = obj2ast_expr(tmp, &value, arena); |
| 5892 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5893 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5894 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5895 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 5896 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5897 | if (*out == NULL) goto failed; |
| 5898 | return 0; |
| 5899 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5900 | tp = astmodulestate_global->AnnAssign_type; |
| 5901 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5902 | if (isinstance == -1) { |
| 5903 | return 1; |
| 5904 | } |
| 5905 | if (isinstance) { |
| 5906 | expr_ty target; |
| 5907 | expr_ty annotation; |
| 5908 | expr_ty value; |
| 5909 | int simple; |
| 5910 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5911 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 5912 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5913 | return 1; |
| 5914 | } |
| 5915 | if (tmp == NULL) { |
| 5916 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 5917 | return 1; |
| 5918 | } |
| 5919 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5920 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5921 | res = obj2ast_expr(tmp, &target, arena); |
| 5922 | if (res != 0) goto failed; |
| 5923 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5924 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5925 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) |
| 5926 | < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5927 | return 1; |
| 5928 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5929 | if (tmp == NULL) { |
| 5930 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 5931 | return 1; |
| 5932 | } |
| 5933 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5934 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5935 | res = obj2ast_expr(tmp, &annotation, arena); |
| 5936 | if (res != 0) goto failed; |
| 5937 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5938 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5939 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5940 | return 1; |
| 5941 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5942 | if (tmp == NULL || tmp == Py_None) { |
| 5943 | Py_CLEAR(tmp); |
| 5944 | value = NULL; |
| 5945 | } |
| 5946 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5947 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5948 | res = obj2ast_expr(tmp, &value, arena); |
| 5949 | if (res != 0) goto failed; |
| 5950 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5951 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5952 | if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0) |
| 5953 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5954 | return 1; |
| 5955 | } |
| 5956 | if (tmp == NULL) { |
| 5957 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 5958 | return 1; |
| 5959 | } |
| 5960 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5961 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5962 | res = obj2ast_int(tmp, &simple, arena); |
| 5963 | if (res != 0) goto failed; |
| 5964 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5965 | } |
| 5966 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5967 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5968 | if (*out == NULL) goto failed; |
| 5969 | return 0; |
| 5970 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5971 | tp = astmodulestate_global->For_type; |
| 5972 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5973 | if (isinstance == -1) { |
| 5974 | return 1; |
| 5975 | } |
| 5976 | if (isinstance) { |
| 5977 | expr_ty target; |
| 5978 | expr_ty iter; |
| 5979 | asdl_seq* body; |
| 5980 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5981 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5982 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5983 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 5984 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5985 | return 1; |
| 5986 | } |
| 5987 | if (tmp == NULL) { |
| 5988 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 5989 | return 1; |
| 5990 | } |
| 5991 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5992 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5993 | res = obj2ast_expr(tmp, &target, arena); |
| 5994 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5995 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5996 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5997 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5998 | return 1; |
| 5999 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6000 | if (tmp == NULL) { |
| 6001 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 6002 | return 1; |
| 6003 | } |
| 6004 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6005 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6006 | res = obj2ast_expr(tmp, &iter, arena); |
| 6007 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6008 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6009 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6010 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6011 | return 1; |
| 6012 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6013 | if (tmp == NULL) { |
| 6014 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 6015 | return 1; |
| 6016 | } |
| 6017 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6018 | int res; |
| 6019 | Py_ssize_t len; |
| 6020 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6021 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6022 | 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] | 6023 | goto failed; |
| 6024 | } |
| 6025 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6026 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6027 | if (body == NULL) goto failed; |
| 6028 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6029 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6030 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6031 | Py_INCREF(tmp2); |
| 6032 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6033 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6034 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6035 | if (len != PyList_GET_SIZE(tmp)) { |
| 6036 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 6037 | goto failed; |
| 6038 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6039 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6040 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6041 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6042 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6043 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6044 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6045 | return 1; |
| 6046 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6047 | if (tmp == NULL) { |
| 6048 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 6049 | return 1; |
| 6050 | } |
| 6051 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6052 | int res; |
| 6053 | Py_ssize_t len; |
| 6054 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6055 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6056 | 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] | 6057 | goto failed; |
| 6058 | } |
| 6059 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6060 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6061 | if (orelse == NULL) goto failed; |
| 6062 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6063 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6064 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6065 | Py_INCREF(tmp2); |
| 6066 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6067 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6068 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6069 | if (len != PyList_GET_SIZE(tmp)) { |
| 6070 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 6071 | goto failed; |
| 6072 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6073 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6074 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6075 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6076 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6077 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6078 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6079 | return 1; |
| 6080 | } |
| 6081 | if (tmp == NULL || tmp == Py_None) { |
| 6082 | Py_CLEAR(tmp); |
| 6083 | type_comment = NULL; |
| 6084 | } |
| 6085 | else { |
| 6086 | int res; |
| 6087 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6088 | if (res != 0) goto failed; |
| 6089 | Py_CLEAR(tmp); |
| 6090 | } |
| 6091 | *out = For(target, iter, body, orelse, type_comment, lineno, |
| 6092 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6093 | if (*out == NULL) goto failed; |
| 6094 | return 0; |
| 6095 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6096 | tp = astmodulestate_global->AsyncFor_type; |
| 6097 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6098 | if (isinstance == -1) { |
| 6099 | return 1; |
| 6100 | } |
| 6101 | if (isinstance) { |
| 6102 | expr_ty target; |
| 6103 | expr_ty iter; |
| 6104 | asdl_seq* body; |
| 6105 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6106 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6107 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6108 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6109 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6110 | return 1; |
| 6111 | } |
| 6112 | if (tmp == NULL) { |
| 6113 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 6114 | return 1; |
| 6115 | } |
| 6116 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6117 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6118 | res = obj2ast_expr(tmp, &target, arena); |
| 6119 | if (res != 0) goto failed; |
| 6120 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6121 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6122 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6123 | return 1; |
| 6124 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6125 | if (tmp == NULL) { |
| 6126 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 6127 | return 1; |
| 6128 | } |
| 6129 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6130 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6131 | res = obj2ast_expr(tmp, &iter, arena); |
| 6132 | if (res != 0) goto failed; |
| 6133 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6134 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6135 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6136 | return 1; |
| 6137 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6138 | if (tmp == NULL) { |
| 6139 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 6140 | return 1; |
| 6141 | } |
| 6142 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6143 | int res; |
| 6144 | Py_ssize_t len; |
| 6145 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6146 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6147 | 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] | 6148 | goto failed; |
| 6149 | } |
| 6150 | len = PyList_GET_SIZE(tmp); |
| 6151 | body = _Py_asdl_seq_new(len, arena); |
| 6152 | if (body == NULL) goto failed; |
| 6153 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6154 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6155 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6156 | Py_INCREF(tmp2); |
| 6157 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6158 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6159 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6160 | if (len != PyList_GET_SIZE(tmp)) { |
| 6161 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 6162 | goto failed; |
| 6163 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6164 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6165 | } |
| 6166 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6167 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6168 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6169 | { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6170 | return 1; |
| 6171 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6172 | if (tmp == NULL) { |
| 6173 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 6174 | return 1; |
| 6175 | } |
| 6176 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6177 | int res; |
| 6178 | Py_ssize_t len; |
| 6179 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6180 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6181 | 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] | 6182 | goto failed; |
| 6183 | } |
| 6184 | len = PyList_GET_SIZE(tmp); |
| 6185 | orelse = _Py_asdl_seq_new(len, arena); |
| 6186 | if (orelse == NULL) goto failed; |
| 6187 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6188 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6189 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6190 | Py_INCREF(tmp2); |
| 6191 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6192 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6193 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6194 | if (len != PyList_GET_SIZE(tmp)) { |
| 6195 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 6196 | goto failed; |
| 6197 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6198 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6199 | } |
| 6200 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6201 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6202 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6203 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6204 | return 1; |
| 6205 | } |
| 6206 | if (tmp == NULL || tmp == Py_None) { |
| 6207 | Py_CLEAR(tmp); |
| 6208 | type_comment = NULL; |
| 6209 | } |
| 6210 | else { |
| 6211 | int res; |
| 6212 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6213 | if (res != 0) goto failed; |
| 6214 | Py_CLEAR(tmp); |
| 6215 | } |
| 6216 | *out = AsyncFor(target, iter, body, orelse, type_comment, lineno, |
| 6217 | col_offset, end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6218 | if (*out == NULL) goto failed; |
| 6219 | return 0; |
| 6220 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6221 | tp = astmodulestate_global->While_type; |
| 6222 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6223 | if (isinstance == -1) { |
| 6224 | return 1; |
| 6225 | } |
| 6226 | if (isinstance) { |
| 6227 | expr_ty test; |
| 6228 | asdl_seq* body; |
| 6229 | asdl_seq* orelse; |
| 6230 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6231 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6232 | return 1; |
| 6233 | } |
| 6234 | if (tmp == NULL) { |
| 6235 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 6236 | return 1; |
| 6237 | } |
| 6238 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6239 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6240 | res = obj2ast_expr(tmp, &test, arena); |
| 6241 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6242 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6243 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6244 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6245 | return 1; |
| 6246 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6247 | if (tmp == NULL) { |
| 6248 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 6249 | return 1; |
| 6250 | } |
| 6251 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6252 | int res; |
| 6253 | Py_ssize_t len; |
| 6254 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6255 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6256 | 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] | 6257 | goto failed; |
| 6258 | } |
| 6259 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6260 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6261 | if (body == NULL) goto failed; |
| 6262 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6263 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6264 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6265 | Py_INCREF(tmp2); |
| 6266 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6267 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6268 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6269 | if (len != PyList_GET_SIZE(tmp)) { |
| 6270 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 6271 | goto failed; |
| 6272 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6273 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6274 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6275 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6276 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6277 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6278 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6279 | return 1; |
| 6280 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6281 | if (tmp == NULL) { |
| 6282 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 6283 | return 1; |
| 6284 | } |
| 6285 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6286 | int res; |
| 6287 | Py_ssize_t len; |
| 6288 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6289 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6290 | 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] | 6291 | goto failed; |
| 6292 | } |
| 6293 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6294 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6295 | if (orelse == NULL) goto failed; |
| 6296 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6297 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6298 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6299 | Py_INCREF(tmp2); |
| 6300 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6301 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6302 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6303 | if (len != PyList_GET_SIZE(tmp)) { |
| 6304 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 6305 | goto failed; |
| 6306 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6307 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6308 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6309 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6310 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6311 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 6312 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6313 | if (*out == NULL) goto failed; |
| 6314 | return 0; |
| 6315 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6316 | tp = astmodulestate_global->If_type; |
| 6317 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6318 | if (isinstance == -1) { |
| 6319 | return 1; |
| 6320 | } |
| 6321 | if (isinstance) { |
| 6322 | expr_ty test; |
| 6323 | asdl_seq* body; |
| 6324 | asdl_seq* orelse; |
| 6325 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6326 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6327 | return 1; |
| 6328 | } |
| 6329 | if (tmp == NULL) { |
| 6330 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 6331 | return 1; |
| 6332 | } |
| 6333 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6334 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6335 | res = obj2ast_expr(tmp, &test, arena); |
| 6336 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6337 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6338 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6339 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6340 | return 1; |
| 6341 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6342 | if (tmp == NULL) { |
| 6343 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 6344 | return 1; |
| 6345 | } |
| 6346 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6347 | int res; |
| 6348 | Py_ssize_t len; |
| 6349 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6350 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6351 | 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] | 6352 | goto failed; |
| 6353 | } |
| 6354 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6355 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6356 | if (body == NULL) goto failed; |
| 6357 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6358 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6359 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6360 | Py_INCREF(tmp2); |
| 6361 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6362 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6363 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6364 | if (len != PyList_GET_SIZE(tmp)) { |
| 6365 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 6366 | goto failed; |
| 6367 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6368 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6369 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6370 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6371 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6372 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6373 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6374 | return 1; |
| 6375 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6376 | if (tmp == NULL) { |
| 6377 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 6378 | return 1; |
| 6379 | } |
| 6380 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6381 | int res; |
| 6382 | Py_ssize_t len; |
| 6383 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6384 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6385 | 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] | 6386 | goto failed; |
| 6387 | } |
| 6388 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6389 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6390 | if (orelse == NULL) goto failed; |
| 6391 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6392 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6393 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6394 | Py_INCREF(tmp2); |
| 6395 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6396 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6397 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6398 | if (len != PyList_GET_SIZE(tmp)) { |
| 6399 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 6400 | goto failed; |
| 6401 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6402 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6403 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6404 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6405 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6406 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 6407 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6408 | if (*out == NULL) goto failed; |
| 6409 | return 0; |
| 6410 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6411 | tp = astmodulestate_global->With_type; |
| 6412 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6413 | if (isinstance == -1) { |
| 6414 | return 1; |
| 6415 | } |
| 6416 | if (isinstance) { |
| 6417 | asdl_seq* items; |
| 6418 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6419 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6420 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6421 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6422 | return 1; |
| 6423 | } |
| 6424 | if (tmp == NULL) { |
| 6425 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 6426 | return 1; |
| 6427 | } |
| 6428 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6429 | int res; |
| 6430 | Py_ssize_t len; |
| 6431 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6432 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6433 | 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] | 6434 | goto failed; |
| 6435 | } |
| 6436 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6437 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6438 | if (items == NULL) goto failed; |
| 6439 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6440 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6441 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6442 | Py_INCREF(tmp2); |
| 6443 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6444 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6445 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6446 | if (len != PyList_GET_SIZE(tmp)) { |
| 6447 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 6448 | goto failed; |
| 6449 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6450 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6451 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6452 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6453 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6454 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6455 | return 1; |
| 6456 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6457 | if (tmp == NULL) { |
| 6458 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 6459 | return 1; |
| 6460 | } |
| 6461 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6462 | int res; |
| 6463 | Py_ssize_t len; |
| 6464 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6465 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6466 | 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] | 6467 | goto failed; |
| 6468 | } |
| 6469 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6470 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6471 | if (body == NULL) goto failed; |
| 6472 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6473 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6474 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6475 | Py_INCREF(tmp2); |
| 6476 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6477 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6478 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6479 | if (len != PyList_GET_SIZE(tmp)) { |
| 6480 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 6481 | goto failed; |
| 6482 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6483 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6484 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6485 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6486 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6487 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6488 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6489 | return 1; |
| 6490 | } |
| 6491 | if (tmp == NULL || tmp == Py_None) { |
| 6492 | Py_CLEAR(tmp); |
| 6493 | type_comment = NULL; |
| 6494 | } |
| 6495 | else { |
| 6496 | int res; |
| 6497 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6498 | if (res != 0) goto failed; |
| 6499 | Py_CLEAR(tmp); |
| 6500 | } |
| 6501 | *out = With(items, body, type_comment, lineno, col_offset, end_lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6502 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6503 | if (*out == NULL) goto failed; |
| 6504 | return 0; |
| 6505 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6506 | tp = astmodulestate_global->AsyncWith_type; |
| 6507 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6508 | if (isinstance == -1) { |
| 6509 | return 1; |
| 6510 | } |
| 6511 | if (isinstance) { |
| 6512 | asdl_seq* items; |
| 6513 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6514 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6515 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6516 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6517 | return 1; |
| 6518 | } |
| 6519 | if (tmp == NULL) { |
| 6520 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 6521 | return 1; |
| 6522 | } |
| 6523 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6524 | int res; |
| 6525 | Py_ssize_t len; |
| 6526 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6527 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6528 | 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] | 6529 | goto failed; |
| 6530 | } |
| 6531 | len = PyList_GET_SIZE(tmp); |
| 6532 | items = _Py_asdl_seq_new(len, arena); |
| 6533 | if (items == NULL) goto failed; |
| 6534 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6535 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6536 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6537 | Py_INCREF(tmp2); |
| 6538 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6539 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6540 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6541 | if (len != PyList_GET_SIZE(tmp)) { |
| 6542 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 6543 | goto failed; |
| 6544 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6545 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6546 | } |
| 6547 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6548 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6549 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6550 | return 1; |
| 6551 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6552 | if (tmp == NULL) { |
| 6553 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 6554 | return 1; |
| 6555 | } |
| 6556 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6557 | int res; |
| 6558 | Py_ssize_t len; |
| 6559 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6560 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6561 | 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] | 6562 | goto failed; |
| 6563 | } |
| 6564 | len = PyList_GET_SIZE(tmp); |
| 6565 | body = _Py_asdl_seq_new(len, arena); |
| 6566 | if (body == NULL) goto failed; |
| 6567 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6568 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6569 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6570 | Py_INCREF(tmp2); |
| 6571 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6572 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6573 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6574 | if (len != PyList_GET_SIZE(tmp)) { |
| 6575 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 6576 | goto failed; |
| 6577 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6578 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6579 | } |
| 6580 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6581 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6582 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6583 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6584 | return 1; |
| 6585 | } |
| 6586 | if (tmp == NULL || tmp == Py_None) { |
| 6587 | Py_CLEAR(tmp); |
| 6588 | type_comment = NULL; |
| 6589 | } |
| 6590 | else { |
| 6591 | int res; |
| 6592 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6593 | if (res != 0) goto failed; |
| 6594 | Py_CLEAR(tmp); |
| 6595 | } |
| 6596 | *out = AsyncWith(items, body, type_comment, lineno, col_offset, |
| 6597 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6598 | if (*out == NULL) goto failed; |
| 6599 | return 0; |
| 6600 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6601 | tp = astmodulestate_global->Raise_type; |
| 6602 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6603 | if (isinstance == -1) { |
| 6604 | return 1; |
| 6605 | } |
| 6606 | if (isinstance) { |
| 6607 | expr_ty exc; |
| 6608 | expr_ty cause; |
| 6609 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6610 | if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6611 | return 1; |
| 6612 | } |
| 6613 | if (tmp == NULL || tmp == Py_None) { |
| 6614 | Py_CLEAR(tmp); |
| 6615 | exc = NULL; |
| 6616 | } |
| 6617 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6618 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6619 | res = obj2ast_expr(tmp, &exc, arena); |
| 6620 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6621 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6622 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6623 | if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6624 | return 1; |
| 6625 | } |
| 6626 | if (tmp == NULL || tmp == Py_None) { |
| 6627 | Py_CLEAR(tmp); |
| 6628 | cause = NULL; |
| 6629 | } |
| 6630 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6631 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6632 | res = obj2ast_expr(tmp, &cause, arena); |
| 6633 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6634 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6635 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6636 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 6637 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6638 | if (*out == NULL) goto failed; |
| 6639 | return 0; |
| 6640 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6641 | tp = astmodulestate_global->Try_type; |
| 6642 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6643 | if (isinstance == -1) { |
| 6644 | return 1; |
| 6645 | } |
| 6646 | if (isinstance) { |
| 6647 | asdl_seq* body; |
| 6648 | asdl_seq* handlers; |
| 6649 | asdl_seq* orelse; |
| 6650 | asdl_seq* finalbody; |
| 6651 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6652 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6653 | return 1; |
| 6654 | } |
| 6655 | if (tmp == NULL) { |
| 6656 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 6657 | return 1; |
| 6658 | } |
| 6659 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6660 | int res; |
| 6661 | Py_ssize_t len; |
| 6662 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6663 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6664 | 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] | 6665 | goto failed; |
| 6666 | } |
| 6667 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6668 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6669 | if (body == NULL) goto failed; |
| 6670 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6671 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6672 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6673 | Py_INCREF(tmp2); |
| 6674 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6675 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6676 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6677 | if (len != PyList_GET_SIZE(tmp)) { |
| 6678 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 6679 | goto failed; |
| 6680 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6681 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6682 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6683 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6684 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6685 | if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) < |
| 6686 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6687 | return 1; |
| 6688 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6689 | if (tmp == NULL) { |
| 6690 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 6691 | return 1; |
| 6692 | } |
| 6693 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6694 | int res; |
| 6695 | Py_ssize_t len; |
| 6696 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6697 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6698 | 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] | 6699 | goto failed; |
| 6700 | } |
| 6701 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6702 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6703 | if (handlers == NULL) goto failed; |
| 6704 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6705 | excepthandler_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6706 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6707 | Py_INCREF(tmp2); |
| 6708 | res = obj2ast_excepthandler(tmp2, &val, arena); |
| 6709 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6710 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6711 | if (len != PyList_GET_SIZE(tmp)) { |
| 6712 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 6713 | goto failed; |
| 6714 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6715 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6716 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6717 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6718 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6719 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6720 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6721 | return 1; |
| 6722 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6723 | if (tmp == NULL) { |
| 6724 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 6725 | return 1; |
| 6726 | } |
| 6727 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6728 | int res; |
| 6729 | Py_ssize_t len; |
| 6730 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6731 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6732 | 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] | 6733 | goto failed; |
| 6734 | } |
| 6735 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6736 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6737 | if (orelse == NULL) goto failed; |
| 6738 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6739 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6740 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6741 | Py_INCREF(tmp2); |
| 6742 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6743 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6744 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6745 | if (len != PyList_GET_SIZE(tmp)) { |
| 6746 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 6747 | goto failed; |
| 6748 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6749 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6750 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6751 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6752 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6753 | if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) < |
| 6754 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6755 | return 1; |
| 6756 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6757 | if (tmp == NULL) { |
| 6758 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 6759 | return 1; |
| 6760 | } |
| 6761 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6762 | int res; |
| 6763 | Py_ssize_t len; |
| 6764 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6765 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6766 | 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] | 6767 | goto failed; |
| 6768 | } |
| 6769 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6770 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6771 | if (finalbody == NULL) goto failed; |
| 6772 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6773 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6774 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6775 | Py_INCREF(tmp2); |
| 6776 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6777 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6778 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6779 | if (len != PyList_GET_SIZE(tmp)) { |
| 6780 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 6781 | goto failed; |
| 6782 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6783 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6784 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6785 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6786 | } |
| 6787 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6788 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6789 | if (*out == NULL) goto failed; |
| 6790 | return 0; |
| 6791 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6792 | tp = astmodulestate_global->Assert_type; |
| 6793 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6794 | if (isinstance == -1) { |
| 6795 | return 1; |
| 6796 | } |
| 6797 | if (isinstance) { |
| 6798 | expr_ty test; |
| 6799 | expr_ty msg; |
| 6800 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6801 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6802 | return 1; |
| 6803 | } |
| 6804 | if (tmp == NULL) { |
| 6805 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 6806 | return 1; |
| 6807 | } |
| 6808 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6809 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6810 | res = obj2ast_expr(tmp, &test, arena); |
| 6811 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6812 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6813 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6814 | if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6815 | return 1; |
| 6816 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6817 | if (tmp == NULL || tmp == Py_None) { |
| 6818 | Py_CLEAR(tmp); |
| 6819 | msg = NULL; |
| 6820 | } |
| 6821 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6822 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6823 | res = obj2ast_expr(tmp, &msg, arena); |
| 6824 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6825 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6826 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6827 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 6828 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6829 | if (*out == NULL) goto failed; |
| 6830 | return 0; |
| 6831 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6832 | tp = astmodulestate_global->Import_type; |
| 6833 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6834 | if (isinstance == -1) { |
| 6835 | return 1; |
| 6836 | } |
| 6837 | if (isinstance) { |
| 6838 | asdl_seq* names; |
| 6839 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6840 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6841 | return 1; |
| 6842 | } |
| 6843 | if (tmp == NULL) { |
| 6844 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 6845 | return 1; |
| 6846 | } |
| 6847 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6848 | int res; |
| 6849 | Py_ssize_t len; |
| 6850 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6851 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6852 | 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] | 6853 | goto failed; |
| 6854 | } |
| 6855 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6856 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6857 | if (names == NULL) goto failed; |
| 6858 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6859 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6860 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6861 | Py_INCREF(tmp2); |
| 6862 | res = obj2ast_alias(tmp2, &val, arena); |
| 6863 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6864 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6865 | if (len != PyList_GET_SIZE(tmp)) { |
| 6866 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 6867 | goto failed; |
| 6868 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6869 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6870 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6871 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6872 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6873 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6874 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6875 | if (*out == NULL) goto failed; |
| 6876 | return 0; |
| 6877 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6878 | tp = astmodulestate_global->ImportFrom_type; |
| 6879 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6880 | if (isinstance == -1) { |
| 6881 | return 1; |
| 6882 | } |
| 6883 | if (isinstance) { |
| 6884 | identifier module; |
| 6885 | asdl_seq* names; |
| 6886 | int level; |
| 6887 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6888 | if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0) |
| 6889 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6890 | return 1; |
| 6891 | } |
| 6892 | if (tmp == NULL || tmp == Py_None) { |
| 6893 | Py_CLEAR(tmp); |
| 6894 | module = NULL; |
| 6895 | } |
| 6896 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6897 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6898 | res = obj2ast_identifier(tmp, &module, arena); |
| 6899 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6900 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6901 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6902 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6903 | return 1; |
| 6904 | } |
| 6905 | if (tmp == NULL) { |
| 6906 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 6907 | return 1; |
| 6908 | } |
| 6909 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6910 | int res; |
| 6911 | Py_ssize_t len; |
| 6912 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6913 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6914 | 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] | 6915 | goto failed; |
| 6916 | } |
| 6917 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6918 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6919 | if (names == NULL) goto failed; |
| 6920 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6921 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6922 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6923 | Py_INCREF(tmp2); |
| 6924 | res = obj2ast_alias(tmp2, &val, arena); |
| 6925 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6926 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6927 | if (len != PyList_GET_SIZE(tmp)) { |
| 6928 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 6929 | goto failed; |
| 6930 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6931 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6932 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6933 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6934 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6935 | if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6936 | return 1; |
| 6937 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6938 | if (tmp == NULL || tmp == Py_None) { |
| 6939 | Py_CLEAR(tmp); |
| 6940 | level = 0; |
| 6941 | } |
| 6942 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6943 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6944 | res = obj2ast_int(tmp, &level, arena); |
| 6945 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6946 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6947 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6948 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 6949 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6950 | if (*out == NULL) goto failed; |
| 6951 | return 0; |
| 6952 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6953 | tp = astmodulestate_global->Global_type; |
| 6954 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6955 | if (isinstance == -1) { |
| 6956 | return 1; |
| 6957 | } |
| 6958 | if (isinstance) { |
| 6959 | asdl_seq* names; |
| 6960 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6961 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6962 | return 1; |
| 6963 | } |
| 6964 | if (tmp == NULL) { |
| 6965 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 6966 | return 1; |
| 6967 | } |
| 6968 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6969 | int res; |
| 6970 | Py_ssize_t len; |
| 6971 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6972 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6973 | 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] | 6974 | goto failed; |
| 6975 | } |
| 6976 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6977 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6978 | if (names == NULL) goto failed; |
| 6979 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6980 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6981 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6982 | Py_INCREF(tmp2); |
| 6983 | res = obj2ast_identifier(tmp2, &val, arena); |
| 6984 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6985 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6986 | if (len != PyList_GET_SIZE(tmp)) { |
| 6987 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 6988 | goto failed; |
| 6989 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6990 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6991 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6992 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6993 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6994 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6995 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6996 | if (*out == NULL) goto failed; |
| 6997 | return 0; |
| 6998 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6999 | tp = astmodulestate_global->Nonlocal_type; |
| 7000 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7001 | if (isinstance == -1) { |
| 7002 | return 1; |
| 7003 | } |
| 7004 | if (isinstance) { |
| 7005 | asdl_seq* names; |
| 7006 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7007 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7008 | return 1; |
| 7009 | } |
| 7010 | if (tmp == NULL) { |
| 7011 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 7012 | return 1; |
| 7013 | } |
| 7014 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7015 | int res; |
| 7016 | Py_ssize_t len; |
| 7017 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7018 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7019 | 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] | 7020 | goto failed; |
| 7021 | } |
| 7022 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7023 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7024 | if (names == NULL) goto failed; |
| 7025 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7026 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7027 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7028 | Py_INCREF(tmp2); |
| 7029 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7030 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7031 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7032 | if (len != PyList_GET_SIZE(tmp)) { |
| 7033 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 7034 | goto failed; |
| 7035 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7036 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7037 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7038 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7039 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7040 | *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7041 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7042 | if (*out == NULL) goto failed; |
| 7043 | return 0; |
| 7044 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7045 | tp = astmodulestate_global->Expr_type; |
| 7046 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7047 | if (isinstance == -1) { |
| 7048 | return 1; |
| 7049 | } |
| 7050 | if (isinstance) { |
| 7051 | expr_ty value; |
| 7052 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7053 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7054 | return 1; |
| 7055 | } |
| 7056 | if (tmp == NULL) { |
| 7057 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 7058 | return 1; |
| 7059 | } |
| 7060 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7061 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7062 | res = obj2ast_expr(tmp, &value, arena); |
| 7063 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7064 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7065 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7066 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7067 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7068 | if (*out == NULL) goto failed; |
| 7069 | return 0; |
| 7070 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7071 | tp = astmodulestate_global->Pass_type; |
| 7072 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7073 | if (isinstance == -1) { |
| 7074 | return 1; |
| 7075 | } |
| 7076 | if (isinstance) { |
| 7077 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7078 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7079 | if (*out == NULL) goto failed; |
| 7080 | return 0; |
| 7081 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7082 | tp = astmodulestate_global->Break_type; |
| 7083 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7084 | if (isinstance == -1) { |
| 7085 | return 1; |
| 7086 | } |
| 7087 | if (isinstance) { |
| 7088 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7089 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7090 | if (*out == NULL) goto failed; |
| 7091 | return 0; |
| 7092 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7093 | tp = astmodulestate_global->Continue_type; |
| 7094 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7095 | if (isinstance == -1) { |
| 7096 | return 1; |
| 7097 | } |
| 7098 | if (isinstance) { |
| 7099 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7100 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7101 | if (*out == NULL) goto failed; |
| 7102 | return 0; |
| 7103 | } |
| 7104 | |
| 7105 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 7106 | failed: |
| 7107 | Py_XDECREF(tmp); |
| 7108 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7109 | } |
| 7110 | |
| 7111 | int |
| 7112 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 7113 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7114 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7115 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7116 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7117 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7118 | int lineno; |
| 7119 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7120 | int end_lineno; |
| 7121 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7122 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7123 | if (obj == Py_None) { |
| 7124 | *out = NULL; |
| 7125 | return 0; |
| 7126 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7127 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7128 | return 1; |
| 7129 | } |
| 7130 | if (tmp == NULL) { |
| 7131 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 7132 | return 1; |
| 7133 | } |
| 7134 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7135 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7136 | res = obj2ast_int(tmp, &lineno, arena); |
| 7137 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7138 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7139 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7140 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 7141 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7142 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7143 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7144 | if (tmp == NULL) { |
| 7145 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 7146 | return 1; |
| 7147 | } |
| 7148 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7149 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7150 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7151 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7152 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7153 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7154 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 7155 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7156 | return 1; |
| 7157 | } |
| 7158 | if (tmp == NULL || tmp == Py_None) { |
| 7159 | Py_CLEAR(tmp); |
| 7160 | end_lineno = 0; |
| 7161 | } |
| 7162 | else { |
| 7163 | int res; |
| 7164 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 7165 | if (res != 0) goto failed; |
| 7166 | Py_CLEAR(tmp); |
| 7167 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7168 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 7169 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7170 | return 1; |
| 7171 | } |
| 7172 | if (tmp == NULL || tmp == Py_None) { |
| 7173 | Py_CLEAR(tmp); |
| 7174 | end_col_offset = 0; |
| 7175 | } |
| 7176 | else { |
| 7177 | int res; |
| 7178 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 7179 | if (res != 0) goto failed; |
| 7180 | Py_CLEAR(tmp); |
| 7181 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7182 | tp = astmodulestate_global->BoolOp_type; |
| 7183 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7184 | if (isinstance == -1) { |
| 7185 | return 1; |
| 7186 | } |
| 7187 | if (isinstance) { |
| 7188 | boolop_ty op; |
| 7189 | asdl_seq* values; |
| 7190 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7191 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7192 | return 1; |
| 7193 | } |
| 7194 | if (tmp == NULL) { |
| 7195 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 7196 | return 1; |
| 7197 | } |
| 7198 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7199 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7200 | res = obj2ast_boolop(tmp, &op, arena); |
| 7201 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7202 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7203 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7204 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7205 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7206 | return 1; |
| 7207 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7208 | if (tmp == NULL) { |
| 7209 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 7210 | return 1; |
| 7211 | } |
| 7212 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7213 | int res; |
| 7214 | Py_ssize_t len; |
| 7215 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7216 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7217 | 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] | 7218 | goto failed; |
| 7219 | } |
| 7220 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7221 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7222 | if (values == NULL) goto failed; |
| 7223 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7224 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7225 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7226 | Py_INCREF(tmp2); |
| 7227 | res = obj2ast_expr(tmp2, &val, arena); |
| 7228 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7229 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7230 | if (len != PyList_GET_SIZE(tmp)) { |
| 7231 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 7232 | goto failed; |
| 7233 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7234 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7235 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7236 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7237 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7238 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 7239 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7240 | if (*out == NULL) goto failed; |
| 7241 | return 0; |
| 7242 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7243 | tp = astmodulestate_global->NamedExpr_type; |
| 7244 | isinstance = PyObject_IsInstance(obj, tp); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7245 | if (isinstance == -1) { |
| 7246 | return 1; |
| 7247 | } |
| 7248 | if (isinstance) { |
| 7249 | expr_ty target; |
| 7250 | expr_ty value; |
| 7251 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7252 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 7253 | { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7254 | return 1; |
| 7255 | } |
| 7256 | if (tmp == NULL) { |
| 7257 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); |
| 7258 | return 1; |
| 7259 | } |
| 7260 | else { |
| 7261 | int res; |
| 7262 | res = obj2ast_expr(tmp, &target, arena); |
| 7263 | if (res != 0) goto failed; |
| 7264 | Py_CLEAR(tmp); |
| 7265 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7266 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7267 | return 1; |
| 7268 | } |
| 7269 | if (tmp == NULL) { |
| 7270 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); |
| 7271 | return 1; |
| 7272 | } |
| 7273 | else { |
| 7274 | int res; |
| 7275 | res = obj2ast_expr(tmp, &value, arena); |
| 7276 | if (res != 0) goto failed; |
| 7277 | Py_CLEAR(tmp); |
| 7278 | } |
| 7279 | *out = NamedExpr(target, value, lineno, col_offset, end_lineno, |
| 7280 | end_col_offset, arena); |
| 7281 | if (*out == NULL) goto failed; |
| 7282 | return 0; |
| 7283 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7284 | tp = astmodulestate_global->BinOp_type; |
| 7285 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7286 | if (isinstance == -1) { |
| 7287 | return 1; |
| 7288 | } |
| 7289 | if (isinstance) { |
| 7290 | expr_ty left; |
| 7291 | operator_ty op; |
| 7292 | expr_ty right; |
| 7293 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7294 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7295 | return 1; |
| 7296 | } |
| 7297 | if (tmp == NULL) { |
| 7298 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 7299 | return 1; |
| 7300 | } |
| 7301 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7302 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7303 | res = obj2ast_expr(tmp, &left, arena); |
| 7304 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7305 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7306 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7307 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7308 | return 1; |
| 7309 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7310 | if (tmp == NULL) { |
| 7311 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 7312 | return 1; |
| 7313 | } |
| 7314 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7315 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7316 | res = obj2ast_operator(tmp, &op, arena); |
| 7317 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7318 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7319 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7320 | if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7321 | return 1; |
| 7322 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7323 | if (tmp == NULL) { |
| 7324 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 7325 | return 1; |
| 7326 | } |
| 7327 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7328 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7329 | res = obj2ast_expr(tmp, &right, arena); |
| 7330 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7331 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7332 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7333 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 7334 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7335 | if (*out == NULL) goto failed; |
| 7336 | return 0; |
| 7337 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7338 | tp = astmodulestate_global->UnaryOp_type; |
| 7339 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7340 | if (isinstance == -1) { |
| 7341 | return 1; |
| 7342 | } |
| 7343 | if (isinstance) { |
| 7344 | unaryop_ty op; |
| 7345 | expr_ty operand; |
| 7346 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7347 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7348 | return 1; |
| 7349 | } |
| 7350 | if (tmp == NULL) { |
| 7351 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 7352 | return 1; |
| 7353 | } |
| 7354 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7355 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7356 | res = obj2ast_unaryop(tmp, &op, arena); |
| 7357 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7358 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7359 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7360 | if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) < |
| 7361 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7362 | return 1; |
| 7363 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7364 | if (tmp == NULL) { |
| 7365 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 7366 | return 1; |
| 7367 | } |
| 7368 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7369 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7370 | res = obj2ast_expr(tmp, &operand, arena); |
| 7371 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7372 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7373 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7374 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 7375 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7376 | if (*out == NULL) goto failed; |
| 7377 | return 0; |
| 7378 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7379 | tp = astmodulestate_global->Lambda_type; |
| 7380 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7381 | if (isinstance == -1) { |
| 7382 | return 1; |
| 7383 | } |
| 7384 | if (isinstance) { |
| 7385 | arguments_ty args; |
| 7386 | expr_ty body; |
| 7387 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7388 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7389 | return 1; |
| 7390 | } |
| 7391 | if (tmp == NULL) { |
| 7392 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 7393 | return 1; |
| 7394 | } |
| 7395 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7396 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7397 | res = obj2ast_arguments(tmp, &args, arena); |
| 7398 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7399 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7400 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7401 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7402 | return 1; |
| 7403 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7404 | if (tmp == NULL) { |
| 7405 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 7406 | return 1; |
| 7407 | } |
| 7408 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7409 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7410 | res = obj2ast_expr(tmp, &body, arena); |
| 7411 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7412 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7413 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7414 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 7415 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7416 | if (*out == NULL) goto failed; |
| 7417 | return 0; |
| 7418 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7419 | tp = astmodulestate_global->IfExp_type; |
| 7420 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7421 | if (isinstance == -1) { |
| 7422 | return 1; |
| 7423 | } |
| 7424 | if (isinstance) { |
| 7425 | expr_ty test; |
| 7426 | expr_ty body; |
| 7427 | expr_ty orelse; |
| 7428 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7429 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7430 | return 1; |
| 7431 | } |
| 7432 | if (tmp == NULL) { |
| 7433 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 7434 | return 1; |
| 7435 | } |
| 7436 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7437 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7438 | res = obj2ast_expr(tmp, &test, arena); |
| 7439 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7440 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7441 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7442 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7443 | return 1; |
| 7444 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7445 | if (tmp == NULL) { |
| 7446 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 7447 | return 1; |
| 7448 | } |
| 7449 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7450 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7451 | res = obj2ast_expr(tmp, &body, arena); |
| 7452 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7453 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7454 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7455 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 7456 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7457 | return 1; |
| 7458 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7459 | if (tmp == NULL) { |
| 7460 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 7461 | return 1; |
| 7462 | } |
| 7463 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7464 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7465 | res = obj2ast_expr(tmp, &orelse, arena); |
| 7466 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7467 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7468 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7469 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 7470 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7471 | if (*out == NULL) goto failed; |
| 7472 | return 0; |
| 7473 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7474 | tp = astmodulestate_global->Dict_type; |
| 7475 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7476 | if (isinstance == -1) { |
| 7477 | return 1; |
| 7478 | } |
| 7479 | if (isinstance) { |
| 7480 | asdl_seq* keys; |
| 7481 | asdl_seq* values; |
| 7482 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7483 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7484 | return 1; |
| 7485 | } |
| 7486 | if (tmp == NULL) { |
| 7487 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 7488 | return 1; |
| 7489 | } |
| 7490 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7491 | int res; |
| 7492 | Py_ssize_t len; |
| 7493 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7494 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7495 | 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] | 7496 | goto failed; |
| 7497 | } |
| 7498 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7499 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7500 | if (keys == NULL) goto failed; |
| 7501 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7502 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7503 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7504 | Py_INCREF(tmp2); |
| 7505 | res = obj2ast_expr(tmp2, &val, arena); |
| 7506 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7507 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7508 | if (len != PyList_GET_SIZE(tmp)) { |
| 7509 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 7510 | goto failed; |
| 7511 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7512 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7513 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7514 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7515 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7516 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7517 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7518 | return 1; |
| 7519 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7520 | if (tmp == NULL) { |
| 7521 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 7522 | return 1; |
| 7523 | } |
| 7524 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7525 | int res; |
| 7526 | Py_ssize_t len; |
| 7527 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7528 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7529 | 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] | 7530 | goto failed; |
| 7531 | } |
| 7532 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7533 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7534 | if (values == NULL) goto failed; |
| 7535 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7536 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7537 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7538 | Py_INCREF(tmp2); |
| 7539 | res = obj2ast_expr(tmp2, &val, arena); |
| 7540 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7541 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7542 | if (len != PyList_GET_SIZE(tmp)) { |
| 7543 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 7544 | goto failed; |
| 7545 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7546 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7547 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7548 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7549 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7550 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 7551 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7552 | if (*out == NULL) goto failed; |
| 7553 | return 0; |
| 7554 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7555 | tp = astmodulestate_global->Set_type; |
| 7556 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7557 | if (isinstance == -1) { |
| 7558 | return 1; |
| 7559 | } |
| 7560 | if (isinstance) { |
| 7561 | asdl_seq* elts; |
| 7562 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7563 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7564 | return 1; |
| 7565 | } |
| 7566 | if (tmp == NULL) { |
| 7567 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 7568 | return 1; |
| 7569 | } |
| 7570 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7571 | int res; |
| 7572 | Py_ssize_t len; |
| 7573 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7574 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7575 | 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] | 7576 | goto failed; |
| 7577 | } |
| 7578 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7579 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7580 | if (elts == NULL) goto failed; |
| 7581 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7582 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7583 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7584 | Py_INCREF(tmp2); |
| 7585 | res = obj2ast_expr(tmp2, &val, arena); |
| 7586 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7587 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7588 | if (len != PyList_GET_SIZE(tmp)) { |
| 7589 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 7590 | goto failed; |
| 7591 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7592 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7593 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7594 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7595 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7596 | *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7597 | if (*out == NULL) goto failed; |
| 7598 | return 0; |
| 7599 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7600 | tp = astmodulestate_global->ListComp_type; |
| 7601 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7602 | if (isinstance == -1) { |
| 7603 | return 1; |
| 7604 | } |
| 7605 | if (isinstance) { |
| 7606 | expr_ty elt; |
| 7607 | asdl_seq* generators; |
| 7608 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7609 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7610 | return 1; |
| 7611 | } |
| 7612 | if (tmp == NULL) { |
| 7613 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 7614 | return 1; |
| 7615 | } |
| 7616 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7617 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7618 | res = obj2ast_expr(tmp, &elt, arena); |
| 7619 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7620 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7621 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7622 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7623 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7624 | return 1; |
| 7625 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7626 | if (tmp == NULL) { |
| 7627 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 7628 | return 1; |
| 7629 | } |
| 7630 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7631 | int res; |
| 7632 | Py_ssize_t len; |
| 7633 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7634 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7635 | 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] | 7636 | goto failed; |
| 7637 | } |
| 7638 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7639 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7640 | if (generators == NULL) goto failed; |
| 7641 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7642 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7643 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7644 | Py_INCREF(tmp2); |
| 7645 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7646 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7647 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7648 | if (len != PyList_GET_SIZE(tmp)) { |
| 7649 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 7650 | goto failed; |
| 7651 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7652 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7653 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7654 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7655 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7656 | *out = ListComp(elt, generators, lineno, col_offset, end_lineno, |
| 7657 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7658 | if (*out == NULL) goto failed; |
| 7659 | return 0; |
| 7660 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7661 | tp = astmodulestate_global->SetComp_type; |
| 7662 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7663 | if (isinstance == -1) { |
| 7664 | return 1; |
| 7665 | } |
| 7666 | if (isinstance) { |
| 7667 | expr_ty elt; |
| 7668 | asdl_seq* generators; |
| 7669 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7670 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7671 | return 1; |
| 7672 | } |
| 7673 | if (tmp == NULL) { |
| 7674 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 7675 | return 1; |
| 7676 | } |
| 7677 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7678 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7679 | res = obj2ast_expr(tmp, &elt, arena); |
| 7680 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7681 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7682 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7683 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7684 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7685 | return 1; |
| 7686 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7687 | if (tmp == NULL) { |
| 7688 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 7689 | return 1; |
| 7690 | } |
| 7691 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7692 | int res; |
| 7693 | Py_ssize_t len; |
| 7694 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7695 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7696 | 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] | 7697 | goto failed; |
| 7698 | } |
| 7699 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7700 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7701 | if (generators == NULL) goto failed; |
| 7702 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7703 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7704 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7705 | Py_INCREF(tmp2); |
| 7706 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7707 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7708 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7709 | if (len != PyList_GET_SIZE(tmp)) { |
| 7710 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 7711 | goto failed; |
| 7712 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7713 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7714 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7715 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7716 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7717 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 7718 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7719 | if (*out == NULL) goto failed; |
| 7720 | return 0; |
| 7721 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7722 | tp = astmodulestate_global->DictComp_type; |
| 7723 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7724 | if (isinstance == -1) { |
| 7725 | return 1; |
| 7726 | } |
| 7727 | if (isinstance) { |
| 7728 | expr_ty key; |
| 7729 | expr_ty value; |
| 7730 | asdl_seq* generators; |
| 7731 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7732 | if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7733 | return 1; |
| 7734 | } |
| 7735 | if (tmp == NULL) { |
| 7736 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 7737 | return 1; |
| 7738 | } |
| 7739 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7740 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7741 | res = obj2ast_expr(tmp, &key, arena); |
| 7742 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7743 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7744 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7745 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7746 | return 1; |
| 7747 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7748 | if (tmp == NULL) { |
| 7749 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 7750 | return 1; |
| 7751 | } |
| 7752 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7753 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7754 | res = obj2ast_expr(tmp, &value, arena); |
| 7755 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7756 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7757 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7758 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7759 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7760 | return 1; |
| 7761 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7762 | if (tmp == NULL) { |
| 7763 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 7764 | return 1; |
| 7765 | } |
| 7766 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7767 | int res; |
| 7768 | Py_ssize_t len; |
| 7769 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7770 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7771 | 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] | 7772 | goto failed; |
| 7773 | } |
| 7774 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7775 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7776 | if (generators == NULL) goto failed; |
| 7777 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7778 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7779 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7780 | Py_INCREF(tmp2); |
| 7781 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7782 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7783 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7784 | if (len != PyList_GET_SIZE(tmp)) { |
| 7785 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 7786 | goto failed; |
| 7787 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7788 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7789 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7790 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7791 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7792 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 7793 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7794 | if (*out == NULL) goto failed; |
| 7795 | return 0; |
| 7796 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7797 | tp = astmodulestate_global->GeneratorExp_type; |
| 7798 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7799 | if (isinstance == -1) { |
| 7800 | return 1; |
| 7801 | } |
| 7802 | if (isinstance) { |
| 7803 | expr_ty elt; |
| 7804 | asdl_seq* generators; |
| 7805 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7806 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7807 | return 1; |
| 7808 | } |
| 7809 | if (tmp == NULL) { |
| 7810 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 7811 | return 1; |
| 7812 | } |
| 7813 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7814 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7815 | res = obj2ast_expr(tmp, &elt, arena); |
| 7816 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7817 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7818 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7819 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7820 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7821 | return 1; |
| 7822 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7823 | if (tmp == NULL) { |
| 7824 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 7825 | return 1; |
| 7826 | } |
| 7827 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7828 | int res; |
| 7829 | Py_ssize_t len; |
| 7830 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7831 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7832 | 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] | 7833 | goto failed; |
| 7834 | } |
| 7835 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7836 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7837 | if (generators == NULL) goto failed; |
| 7838 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7839 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7840 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7841 | Py_INCREF(tmp2); |
| 7842 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7843 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7844 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7845 | if (len != PyList_GET_SIZE(tmp)) { |
| 7846 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 7847 | goto failed; |
| 7848 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7849 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7850 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7851 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7852 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7853 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 7854 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7855 | if (*out == NULL) goto failed; |
| 7856 | return 0; |
| 7857 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7858 | tp = astmodulestate_global->Await_type; |
| 7859 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7860 | if (isinstance == -1) { |
| 7861 | return 1; |
| 7862 | } |
| 7863 | if (isinstance) { |
| 7864 | expr_ty value; |
| 7865 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7866 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7867 | return 1; |
| 7868 | } |
| 7869 | if (tmp == NULL) { |
| 7870 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 7871 | return 1; |
| 7872 | } |
| 7873 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7874 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7875 | res = obj2ast_expr(tmp, &value, arena); |
| 7876 | if (res != 0) goto failed; |
| 7877 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7878 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7879 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7880 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7881 | if (*out == NULL) goto failed; |
| 7882 | return 0; |
| 7883 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7884 | tp = astmodulestate_global->Yield_type; |
| 7885 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7886 | if (isinstance == -1) { |
| 7887 | return 1; |
| 7888 | } |
| 7889 | if (isinstance) { |
| 7890 | expr_ty value; |
| 7891 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7892 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7893 | return 1; |
| 7894 | } |
| 7895 | if (tmp == NULL || tmp == Py_None) { |
| 7896 | Py_CLEAR(tmp); |
| 7897 | value = NULL; |
| 7898 | } |
| 7899 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7900 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7901 | res = obj2ast_expr(tmp, &value, arena); |
| 7902 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7903 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7904 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7905 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7906 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7907 | if (*out == NULL) goto failed; |
| 7908 | return 0; |
| 7909 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7910 | tp = astmodulestate_global->YieldFrom_type; |
| 7911 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7912 | if (isinstance == -1) { |
| 7913 | return 1; |
| 7914 | } |
| 7915 | if (isinstance) { |
| 7916 | expr_ty value; |
| 7917 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7918 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7919 | return 1; |
| 7920 | } |
| 7921 | if (tmp == NULL) { |
| 7922 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 7923 | return 1; |
| 7924 | } |
| 7925 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7926 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7927 | res = obj2ast_expr(tmp, &value, arena); |
| 7928 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7929 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7930 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7931 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7932 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7933 | if (*out == NULL) goto failed; |
| 7934 | return 0; |
| 7935 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7936 | tp = astmodulestate_global->Compare_type; |
| 7937 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7938 | if (isinstance == -1) { |
| 7939 | return 1; |
| 7940 | } |
| 7941 | if (isinstance) { |
| 7942 | expr_ty left; |
| 7943 | asdl_int_seq* ops; |
| 7944 | asdl_seq* comparators; |
| 7945 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7946 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7947 | return 1; |
| 7948 | } |
| 7949 | if (tmp == NULL) { |
| 7950 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 7951 | return 1; |
| 7952 | } |
| 7953 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7954 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7955 | res = obj2ast_expr(tmp, &left, arena); |
| 7956 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7957 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7958 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7959 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7960 | return 1; |
| 7961 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7962 | if (tmp == NULL) { |
| 7963 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 7964 | return 1; |
| 7965 | } |
| 7966 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7967 | int res; |
| 7968 | Py_ssize_t len; |
| 7969 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7970 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7971 | 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] | 7972 | goto failed; |
| 7973 | } |
| 7974 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7975 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7976 | if (ops == NULL) goto failed; |
| 7977 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7978 | cmpop_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7979 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7980 | Py_INCREF(tmp2); |
| 7981 | res = obj2ast_cmpop(tmp2, &val, arena); |
| 7982 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7983 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7984 | if (len != PyList_GET_SIZE(tmp)) { |
| 7985 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 7986 | goto failed; |
| 7987 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7988 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7989 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7990 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7991 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7992 | if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp) |
| 7993 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7994 | return 1; |
| 7995 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7996 | if (tmp == NULL) { |
| 7997 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 7998 | return 1; |
| 7999 | } |
| 8000 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8001 | int res; |
| 8002 | Py_ssize_t len; |
| 8003 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8004 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8005 | 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] | 8006 | goto failed; |
| 8007 | } |
| 8008 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8009 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8010 | if (comparators == NULL) goto failed; |
| 8011 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8012 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8013 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8014 | Py_INCREF(tmp2); |
| 8015 | res = obj2ast_expr(tmp2, &val, arena); |
| 8016 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8017 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8018 | if (len != PyList_GET_SIZE(tmp)) { |
| 8019 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 8020 | goto failed; |
| 8021 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8022 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8023 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8024 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8025 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8026 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 8027 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8028 | if (*out == NULL) goto failed; |
| 8029 | return 0; |
| 8030 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8031 | tp = astmodulestate_global->Call_type; |
| 8032 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8033 | if (isinstance == -1) { |
| 8034 | return 1; |
| 8035 | } |
| 8036 | if (isinstance) { |
| 8037 | expr_ty func; |
| 8038 | asdl_seq* args; |
| 8039 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8040 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8041 | if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8042 | return 1; |
| 8043 | } |
| 8044 | if (tmp == NULL) { |
| 8045 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 8046 | return 1; |
| 8047 | } |
| 8048 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8049 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8050 | res = obj2ast_expr(tmp, &func, arena); |
| 8051 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8052 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8053 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8054 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8055 | return 1; |
| 8056 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8057 | if (tmp == NULL) { |
| 8058 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 8059 | return 1; |
| 8060 | } |
| 8061 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8062 | int res; |
| 8063 | Py_ssize_t len; |
| 8064 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8065 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8066 | 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] | 8067 | goto failed; |
| 8068 | } |
| 8069 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8070 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8071 | if (args == NULL) goto failed; |
| 8072 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8073 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8074 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8075 | Py_INCREF(tmp2); |
| 8076 | res = obj2ast_expr(tmp2, &val, arena); |
| 8077 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8078 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8079 | if (len != PyList_GET_SIZE(tmp)) { |
| 8080 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 8081 | goto failed; |
| 8082 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8083 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8084 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8085 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8086 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8087 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 8088 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8089 | return 1; |
| 8090 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8091 | if (tmp == NULL) { |
| 8092 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 8093 | return 1; |
| 8094 | } |
| 8095 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8096 | int res; |
| 8097 | Py_ssize_t len; |
| 8098 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8099 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8100 | 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] | 8101 | goto failed; |
| 8102 | } |
| 8103 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8104 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8105 | if (keywords == NULL) goto failed; |
| 8106 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8107 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8108 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8109 | Py_INCREF(tmp2); |
| 8110 | res = obj2ast_keyword(tmp2, &val, arena); |
| 8111 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8112 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8113 | if (len != PyList_GET_SIZE(tmp)) { |
| 8114 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 8115 | goto failed; |
| 8116 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8117 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8118 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8119 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8120 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8121 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 8122 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8123 | if (*out == NULL) goto failed; |
| 8124 | return 0; |
| 8125 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8126 | tp = astmodulestate_global->FormattedValue_type; |
| 8127 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8128 | if (isinstance == -1) { |
| 8129 | return 1; |
| 8130 | } |
| 8131 | if (isinstance) { |
| 8132 | expr_ty value; |
| 8133 | int conversion; |
| 8134 | expr_ty format_spec; |
| 8135 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8136 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8137 | return 1; |
| 8138 | } |
| 8139 | if (tmp == NULL) { |
| 8140 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 8141 | return 1; |
| 8142 | } |
| 8143 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8144 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8145 | res = obj2ast_expr(tmp, &value, arena); |
| 8146 | if (res != 0) goto failed; |
| 8147 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8148 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8149 | if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp) |
| 8150 | < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8151 | return 1; |
| 8152 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8153 | if (tmp == NULL || tmp == Py_None) { |
| 8154 | Py_CLEAR(tmp); |
| 8155 | conversion = 0; |
| 8156 | } |
| 8157 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8158 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8159 | res = obj2ast_int(tmp, &conversion, arena); |
| 8160 | if (res != 0) goto failed; |
| 8161 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8162 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8163 | if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp) |
| 8164 | < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8165 | return 1; |
| 8166 | } |
| 8167 | if (tmp == NULL || tmp == Py_None) { |
| 8168 | Py_CLEAR(tmp); |
| 8169 | format_spec = NULL; |
| 8170 | } |
| 8171 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8172 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8173 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 8174 | if (res != 0) goto failed; |
| 8175 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8176 | } |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 8177 | *out = FormattedValue(value, conversion, format_spec, lineno, |
| 8178 | col_offset, end_lineno, end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8179 | if (*out == NULL) goto failed; |
| 8180 | return 0; |
| 8181 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8182 | tp = astmodulestate_global->JoinedStr_type; |
| 8183 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8184 | if (isinstance == -1) { |
| 8185 | return 1; |
| 8186 | } |
| 8187 | if (isinstance) { |
| 8188 | asdl_seq* values; |
| 8189 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8190 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 8191 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8192 | return 1; |
| 8193 | } |
| 8194 | if (tmp == NULL) { |
| 8195 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 8196 | return 1; |
| 8197 | } |
| 8198 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8199 | int res; |
| 8200 | Py_ssize_t len; |
| 8201 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8202 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8203 | 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] | 8204 | goto failed; |
| 8205 | } |
| 8206 | len = PyList_GET_SIZE(tmp); |
| 8207 | values = _Py_asdl_seq_new(len, arena); |
| 8208 | if (values == NULL) goto failed; |
| 8209 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8210 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8211 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8212 | Py_INCREF(tmp2); |
| 8213 | res = obj2ast_expr(tmp2, &val, arena); |
| 8214 | Py_DECREF(tmp2); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8215 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 8216 | if (len != PyList_GET_SIZE(tmp)) { |
| 8217 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 8218 | goto failed; |
| 8219 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8220 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8221 | } |
| 8222 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8223 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8224 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 8225 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8226 | if (*out == NULL) goto failed; |
| 8227 | return 0; |
| 8228 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8229 | tp = astmodulestate_global->Constant_type; |
| 8230 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8231 | if (isinstance == -1) { |
| 8232 | return 1; |
| 8233 | } |
| 8234 | if (isinstance) { |
| 8235 | constant value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8236 | string kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8237 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8238 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8239 | return 1; |
| 8240 | } |
| 8241 | if (tmp == NULL) { |
| 8242 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 8243 | return 1; |
| 8244 | } |
| 8245 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8246 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8247 | res = obj2ast_constant(tmp, &value, arena); |
| 8248 | if (res != 0) goto failed; |
| 8249 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8250 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8251 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) { |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8252 | return 1; |
| 8253 | } |
| 8254 | if (tmp == NULL || tmp == Py_None) { |
| 8255 | Py_CLEAR(tmp); |
| 8256 | kind = NULL; |
| 8257 | } |
| 8258 | else { |
| 8259 | int res; |
| 8260 | res = obj2ast_string(tmp, &kind, arena); |
| 8261 | if (res != 0) goto failed; |
| 8262 | Py_CLEAR(tmp); |
| 8263 | } |
| 8264 | *out = Constant(value, kind, lineno, col_offset, end_lineno, |
| 8265 | end_col_offset, arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8266 | if (*out == NULL) goto failed; |
| 8267 | return 0; |
| 8268 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8269 | tp = astmodulestate_global->Attribute_type; |
| 8270 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8271 | if (isinstance == -1) { |
| 8272 | return 1; |
| 8273 | } |
| 8274 | if (isinstance) { |
| 8275 | expr_ty value; |
| 8276 | identifier attr; |
| 8277 | expr_context_ty ctx; |
| 8278 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8279 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8280 | return 1; |
| 8281 | } |
| 8282 | if (tmp == NULL) { |
| 8283 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 8284 | return 1; |
| 8285 | } |
| 8286 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8287 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8288 | res = obj2ast_expr(tmp, &value, arena); |
| 8289 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8290 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8291 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8292 | if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8293 | return 1; |
| 8294 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8295 | if (tmp == NULL) { |
| 8296 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 8297 | return 1; |
| 8298 | } |
| 8299 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8300 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8301 | res = obj2ast_identifier(tmp, &attr, arena); |
| 8302 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8303 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8304 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8305 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8306 | return 1; |
| 8307 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8308 | if (tmp == NULL) { |
| 8309 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 8310 | return 1; |
| 8311 | } |
| 8312 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8313 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8314 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8315 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8316 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8317 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8318 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 8319 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8320 | if (*out == NULL) goto failed; |
| 8321 | return 0; |
| 8322 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8323 | tp = astmodulestate_global->Subscript_type; |
| 8324 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8325 | if (isinstance == -1) { |
| 8326 | return 1; |
| 8327 | } |
| 8328 | if (isinstance) { |
| 8329 | expr_ty value; |
| 8330 | slice_ty slice; |
| 8331 | expr_context_ty ctx; |
| 8332 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8333 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8334 | return 1; |
| 8335 | } |
| 8336 | if (tmp == NULL) { |
| 8337 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 8338 | return 1; |
| 8339 | } |
| 8340 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8341 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8342 | res = obj2ast_expr(tmp, &value, arena); |
| 8343 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8344 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8345 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8346 | if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8347 | return 1; |
| 8348 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8349 | if (tmp == NULL) { |
| 8350 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 8351 | return 1; |
| 8352 | } |
| 8353 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8354 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8355 | res = obj2ast_slice(tmp, &slice, arena); |
| 8356 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8357 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8358 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8359 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8360 | return 1; |
| 8361 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8362 | if (tmp == NULL) { |
| 8363 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 8364 | return 1; |
| 8365 | } |
| 8366 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8367 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8368 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8369 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8370 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8371 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8372 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 8373 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8374 | if (*out == NULL) goto failed; |
| 8375 | return 0; |
| 8376 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8377 | tp = astmodulestate_global->Starred_type; |
| 8378 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8379 | if (isinstance == -1) { |
| 8380 | return 1; |
| 8381 | } |
| 8382 | if (isinstance) { |
| 8383 | expr_ty value; |
| 8384 | expr_context_ty ctx; |
| 8385 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8386 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8387 | return 1; |
| 8388 | } |
| 8389 | if (tmp == NULL) { |
| 8390 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 8391 | return 1; |
| 8392 | } |
| 8393 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8394 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8395 | res = obj2ast_expr(tmp, &value, arena); |
| 8396 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8397 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8398 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8399 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8400 | return 1; |
| 8401 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8402 | if (tmp == NULL) { |
| 8403 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 8404 | return 1; |
| 8405 | } |
| 8406 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8407 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8408 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8409 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8410 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8411 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8412 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 8413 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8414 | if (*out == NULL) goto failed; |
| 8415 | return 0; |
| 8416 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8417 | tp = astmodulestate_global->Name_type; |
| 8418 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8419 | if (isinstance == -1) { |
| 8420 | return 1; |
| 8421 | } |
| 8422 | if (isinstance) { |
| 8423 | identifier id; |
| 8424 | expr_context_ty ctx; |
| 8425 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8426 | if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8427 | return 1; |
| 8428 | } |
| 8429 | if (tmp == NULL) { |
| 8430 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 8431 | return 1; |
| 8432 | } |
| 8433 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8434 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8435 | res = obj2ast_identifier(tmp, &id, arena); |
| 8436 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8437 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8438 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8439 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8440 | return 1; |
| 8441 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8442 | if (tmp == NULL) { |
| 8443 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 8444 | return 1; |
| 8445 | } |
| 8446 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8447 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8448 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8449 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8450 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8451 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8452 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8453 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8454 | if (*out == NULL) goto failed; |
| 8455 | return 0; |
| 8456 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8457 | tp = astmodulestate_global->List_type; |
| 8458 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8459 | if (isinstance == -1) { |
| 8460 | return 1; |
| 8461 | } |
| 8462 | if (isinstance) { |
| 8463 | asdl_seq* elts; |
| 8464 | expr_context_ty ctx; |
| 8465 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8466 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8467 | return 1; |
| 8468 | } |
| 8469 | if (tmp == NULL) { |
| 8470 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 8471 | return 1; |
| 8472 | } |
| 8473 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8474 | int res; |
| 8475 | Py_ssize_t len; |
| 8476 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8477 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8478 | 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] | 8479 | goto failed; |
| 8480 | } |
| 8481 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8482 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8483 | if (elts == NULL) goto failed; |
| 8484 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8485 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8486 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8487 | Py_INCREF(tmp2); |
| 8488 | res = obj2ast_expr(tmp2, &val, arena); |
| 8489 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8490 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8491 | if (len != PyList_GET_SIZE(tmp)) { |
| 8492 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 8493 | goto failed; |
| 8494 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8495 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8496 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8497 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8498 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8499 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8500 | return 1; |
| 8501 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8502 | if (tmp == NULL) { |
| 8503 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 8504 | return 1; |
| 8505 | } |
| 8506 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8507 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8508 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8509 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8510 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8511 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8512 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8513 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8514 | if (*out == NULL) goto failed; |
| 8515 | return 0; |
| 8516 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8517 | tp = astmodulestate_global->Tuple_type; |
| 8518 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8519 | if (isinstance == -1) { |
| 8520 | return 1; |
| 8521 | } |
| 8522 | if (isinstance) { |
| 8523 | asdl_seq* elts; |
| 8524 | expr_context_ty ctx; |
| 8525 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8526 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8527 | return 1; |
| 8528 | } |
| 8529 | if (tmp == NULL) { |
| 8530 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 8531 | return 1; |
| 8532 | } |
| 8533 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8534 | int res; |
| 8535 | Py_ssize_t len; |
| 8536 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8537 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8538 | 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] | 8539 | goto failed; |
| 8540 | } |
| 8541 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8542 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8543 | if (elts == NULL) goto failed; |
| 8544 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8545 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8546 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8547 | Py_INCREF(tmp2); |
| 8548 | res = obj2ast_expr(tmp2, &val, arena); |
| 8549 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8550 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8551 | if (len != PyList_GET_SIZE(tmp)) { |
| 8552 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 8553 | goto failed; |
| 8554 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8555 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8556 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8557 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8558 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8559 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8560 | return 1; |
| 8561 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8562 | if (tmp == NULL) { |
| 8563 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 8564 | return 1; |
| 8565 | } |
| 8566 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8567 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8568 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8569 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8570 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8571 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8572 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8573 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8574 | if (*out == NULL) goto failed; |
| 8575 | return 0; |
| 8576 | } |
| 8577 | |
| 8578 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 8579 | failed: |
| 8580 | Py_XDECREF(tmp); |
| 8581 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8582 | } |
| 8583 | |
| 8584 | int |
| 8585 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 8586 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8587 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8588 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8589 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8590 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8591 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8592 | } |
| 8593 | if (isinstance) { |
| 8594 | *out = Load; |
| 8595 | return 0; |
| 8596 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8597 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8598 | if (isinstance == -1) { |
| 8599 | return 1; |
| 8600 | } |
| 8601 | if (isinstance) { |
| 8602 | *out = Store; |
| 8603 | return 0; |
| 8604 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8605 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8606 | if (isinstance == -1) { |
| 8607 | return 1; |
| 8608 | } |
| 8609 | if (isinstance) { |
| 8610 | *out = Del; |
| 8611 | return 0; |
| 8612 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8613 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugLoad_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8614 | if (isinstance == -1) { |
| 8615 | return 1; |
| 8616 | } |
| 8617 | if (isinstance) { |
| 8618 | *out = AugLoad; |
| 8619 | return 0; |
| 8620 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8621 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugStore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8622 | if (isinstance == -1) { |
| 8623 | return 1; |
| 8624 | } |
| 8625 | if (isinstance) { |
| 8626 | *out = AugStore; |
| 8627 | return 0; |
| 8628 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8629 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Param_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8630 | if (isinstance == -1) { |
| 8631 | return 1; |
| 8632 | } |
| 8633 | if (isinstance) { |
| 8634 | *out = Param; |
| 8635 | return 0; |
| 8636 | } |
| 8637 | |
| 8638 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 8639 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8640 | } |
| 8641 | |
| 8642 | int |
| 8643 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 8644 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8645 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8646 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8647 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8648 | PyObject *tp; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8649 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8650 | if (obj == Py_None) { |
| 8651 | *out = NULL; |
| 8652 | return 0; |
| 8653 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8654 | tp = astmodulestate_global->Slice_type; |
| 8655 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8656 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8657 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8658 | } |
| 8659 | if (isinstance) { |
| 8660 | expr_ty lower; |
| 8661 | expr_ty upper; |
| 8662 | expr_ty step; |
| 8663 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8664 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8665 | return 1; |
| 8666 | } |
| 8667 | if (tmp == NULL || tmp == Py_None) { |
| 8668 | Py_CLEAR(tmp); |
| 8669 | lower = NULL; |
| 8670 | } |
| 8671 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8672 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8673 | res = obj2ast_expr(tmp, &lower, arena); |
| 8674 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8675 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8676 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8677 | if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8678 | return 1; |
| 8679 | } |
| 8680 | if (tmp == NULL || tmp == Py_None) { |
| 8681 | Py_CLEAR(tmp); |
| 8682 | upper = NULL; |
| 8683 | } |
| 8684 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8685 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8686 | res = obj2ast_expr(tmp, &upper, arena); |
| 8687 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8688 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8689 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8690 | if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8691 | return 1; |
| 8692 | } |
| 8693 | if (tmp == NULL || tmp == Py_None) { |
| 8694 | Py_CLEAR(tmp); |
| 8695 | step = NULL; |
| 8696 | } |
| 8697 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8698 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8699 | res = obj2ast_expr(tmp, &step, arena); |
| 8700 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8701 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8702 | } |
| 8703 | *out = Slice(lower, upper, step, arena); |
| 8704 | if (*out == NULL) goto failed; |
| 8705 | return 0; |
| 8706 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8707 | tp = astmodulestate_global->ExtSlice_type; |
| 8708 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8709 | if (isinstance == -1) { |
| 8710 | return 1; |
| 8711 | } |
| 8712 | if (isinstance) { |
| 8713 | asdl_seq* dims; |
| 8714 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8715 | if (_PyObject_LookupAttr(obj, astmodulestate_global->dims, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8716 | return 1; |
| 8717 | } |
| 8718 | if (tmp == NULL) { |
| 8719 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 8720 | return 1; |
| 8721 | } |
| 8722 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8723 | int res; |
| 8724 | Py_ssize_t len; |
| 8725 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8726 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8727 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8728 | goto failed; |
| 8729 | } |
| 8730 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8731 | dims = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8732 | if (dims == NULL) goto failed; |
| 8733 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8734 | slice_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8735 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8736 | Py_INCREF(tmp2); |
| 8737 | res = obj2ast_slice(tmp2, &val, arena); |
| 8738 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8739 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8740 | if (len != PyList_GET_SIZE(tmp)) { |
| 8741 | PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration"); |
| 8742 | goto failed; |
| 8743 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8744 | asdl_seq_SET(dims, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8745 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8746 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8747 | } |
| 8748 | *out = ExtSlice(dims, arena); |
| 8749 | if (*out == NULL) goto failed; |
| 8750 | return 0; |
| 8751 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8752 | tp = astmodulestate_global->Index_type; |
| 8753 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8754 | if (isinstance == -1) { |
| 8755 | return 1; |
| 8756 | } |
| 8757 | if (isinstance) { |
| 8758 | expr_ty value; |
| 8759 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8760 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8761 | return 1; |
| 8762 | } |
| 8763 | if (tmp == NULL) { |
| 8764 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 8765 | return 1; |
| 8766 | } |
| 8767 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8768 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8769 | res = obj2ast_expr(tmp, &value, arena); |
| 8770 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8771 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8772 | } |
| 8773 | *out = Index(value, arena); |
| 8774 | if (*out == NULL) goto failed; |
| 8775 | return 0; |
| 8776 | } |
| 8777 | |
| 8778 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 8779 | failed: |
| 8780 | Py_XDECREF(tmp); |
| 8781 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8782 | } |
| 8783 | |
| 8784 | int |
| 8785 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 8786 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8787 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8788 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8789 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8790 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8791 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8792 | } |
| 8793 | if (isinstance) { |
| 8794 | *out = And; |
| 8795 | return 0; |
| 8796 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8797 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8798 | if (isinstance == -1) { |
| 8799 | return 1; |
| 8800 | } |
| 8801 | if (isinstance) { |
| 8802 | *out = Or; |
| 8803 | return 0; |
| 8804 | } |
| 8805 | |
| 8806 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 8807 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8808 | } |
| 8809 | |
| 8810 | int |
| 8811 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 8812 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8813 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8814 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8815 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8816 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8817 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8818 | } |
| 8819 | if (isinstance) { |
| 8820 | *out = Add; |
| 8821 | return 0; |
| 8822 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8823 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8824 | if (isinstance == -1) { |
| 8825 | return 1; |
| 8826 | } |
| 8827 | if (isinstance) { |
| 8828 | *out = Sub; |
| 8829 | return 0; |
| 8830 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8831 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8832 | if (isinstance == -1) { |
| 8833 | return 1; |
| 8834 | } |
| 8835 | if (isinstance) { |
| 8836 | *out = Mult; |
| 8837 | return 0; |
| 8838 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8839 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type); |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8840 | if (isinstance == -1) { |
| 8841 | return 1; |
| 8842 | } |
| 8843 | if (isinstance) { |
| 8844 | *out = MatMult; |
| 8845 | return 0; |
| 8846 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8847 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8848 | if (isinstance == -1) { |
| 8849 | return 1; |
| 8850 | } |
| 8851 | if (isinstance) { |
| 8852 | *out = Div; |
| 8853 | return 0; |
| 8854 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8855 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8856 | if (isinstance == -1) { |
| 8857 | return 1; |
| 8858 | } |
| 8859 | if (isinstance) { |
| 8860 | *out = Mod; |
| 8861 | return 0; |
| 8862 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8863 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_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 = Pow; |
| 8869 | return 0; |
| 8870 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8871 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_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 = LShift; |
| 8877 | return 0; |
| 8878 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8879 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8880 | if (isinstance == -1) { |
| 8881 | return 1; |
| 8882 | } |
| 8883 | if (isinstance) { |
| 8884 | *out = RShift; |
| 8885 | return 0; |
| 8886 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8887 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_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 = BitOr; |
| 8893 | return 0; |
| 8894 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8895 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_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 = BitXor; |
| 8901 | return 0; |
| 8902 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8903 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_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 = BitAnd; |
| 8909 | return 0; |
| 8910 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8911 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_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 = FloorDiv; |
| 8917 | return 0; |
| 8918 | } |
| 8919 | |
| 8920 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 8921 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8922 | } |
| 8923 | |
| 8924 | int |
| 8925 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 8926 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8927 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8928 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8929 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8930 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8931 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8932 | } |
| 8933 | if (isinstance) { |
| 8934 | *out = Invert; |
| 8935 | return 0; |
| 8936 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8937 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8938 | if (isinstance == -1) { |
| 8939 | return 1; |
| 8940 | } |
| 8941 | if (isinstance) { |
| 8942 | *out = Not; |
| 8943 | return 0; |
| 8944 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8945 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8946 | if (isinstance == -1) { |
| 8947 | return 1; |
| 8948 | } |
| 8949 | if (isinstance) { |
| 8950 | *out = UAdd; |
| 8951 | return 0; |
| 8952 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8953 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8954 | if (isinstance == -1) { |
| 8955 | return 1; |
| 8956 | } |
| 8957 | if (isinstance) { |
| 8958 | *out = USub; |
| 8959 | return 0; |
| 8960 | } |
| 8961 | |
| 8962 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 8963 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8964 | } |
| 8965 | |
| 8966 | int |
| 8967 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 8968 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8969 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8970 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8971 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8972 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8973 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8974 | } |
| 8975 | if (isinstance) { |
| 8976 | *out = Eq; |
| 8977 | return 0; |
| 8978 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8979 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8980 | if (isinstance == -1) { |
| 8981 | return 1; |
| 8982 | } |
| 8983 | if (isinstance) { |
| 8984 | *out = NotEq; |
| 8985 | return 0; |
| 8986 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8987 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8988 | if (isinstance == -1) { |
| 8989 | return 1; |
| 8990 | } |
| 8991 | if (isinstance) { |
| 8992 | *out = Lt; |
| 8993 | return 0; |
| 8994 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8995 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8996 | if (isinstance == -1) { |
| 8997 | return 1; |
| 8998 | } |
| 8999 | if (isinstance) { |
| 9000 | *out = LtE; |
| 9001 | return 0; |
| 9002 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9003 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9004 | if (isinstance == -1) { |
| 9005 | return 1; |
| 9006 | } |
| 9007 | if (isinstance) { |
| 9008 | *out = Gt; |
| 9009 | return 0; |
| 9010 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9011 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9012 | if (isinstance == -1) { |
| 9013 | return 1; |
| 9014 | } |
| 9015 | if (isinstance) { |
| 9016 | *out = GtE; |
| 9017 | return 0; |
| 9018 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9019 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_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 = Is; |
| 9025 | return 0; |
| 9026 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9027 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_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 = IsNot; |
| 9033 | return 0; |
| 9034 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9035 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_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 = In; |
| 9041 | return 0; |
| 9042 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9043 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_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 = NotIn; |
| 9049 | return 0; |
| 9050 | } |
| 9051 | |
| 9052 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 9053 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9054 | } |
| 9055 | |
| 9056 | int |
| 9057 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 9058 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9059 | PyObject* tmp = NULL; |
| 9060 | expr_ty target; |
| 9061 | expr_ty iter; |
| 9062 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9063 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9064 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9065 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9066 | return 1; |
| 9067 | } |
| 9068 | if (tmp == NULL) { |
| 9069 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 9070 | return 1; |
| 9071 | } |
| 9072 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9073 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9074 | res = obj2ast_expr(tmp, &target, arena); |
| 9075 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9076 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9077 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9078 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9079 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9080 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9081 | if (tmp == NULL) { |
| 9082 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 9083 | return 1; |
| 9084 | } |
| 9085 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9086 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9087 | res = obj2ast_expr(tmp, &iter, arena); |
| 9088 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9089 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9090 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9091 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9092 | return 1; |
| 9093 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9094 | if (tmp == NULL) { |
| 9095 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 9096 | return 1; |
| 9097 | } |
| 9098 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9099 | int res; |
| 9100 | Py_ssize_t len; |
| 9101 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9102 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9103 | 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] | 9104 | goto failed; |
| 9105 | } |
| 9106 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9107 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9108 | if (ifs == NULL) goto failed; |
| 9109 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9110 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9111 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9112 | Py_INCREF(tmp2); |
| 9113 | res = obj2ast_expr(tmp2, &val, arena); |
| 9114 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9115 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9116 | if (len != PyList_GET_SIZE(tmp)) { |
| 9117 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 9118 | goto failed; |
| 9119 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9120 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9121 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9122 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9123 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9124 | if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9125 | return 1; |
| 9126 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9127 | if (tmp == NULL) { |
| 9128 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 9129 | return 1; |
| 9130 | } |
| 9131 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9132 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9133 | res = obj2ast_int(tmp, &is_async, arena); |
| 9134 | if (res != 0) goto failed; |
| 9135 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9136 | } |
| 9137 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9138 | return 0; |
| 9139 | failed: |
| 9140 | Py_XDECREF(tmp); |
| 9141 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9142 | } |
| 9143 | |
| 9144 | int |
| 9145 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 9146 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9147 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 9148 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9149 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9150 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9151 | int lineno; |
| 9152 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9153 | int end_lineno; |
| 9154 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9155 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9156 | if (obj == Py_None) { |
| 9157 | *out = NULL; |
| 9158 | return 0; |
| 9159 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9160 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9161 | return 1; |
| 9162 | } |
| 9163 | if (tmp == NULL) { |
| 9164 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 9165 | return 1; |
| 9166 | } |
| 9167 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9168 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9169 | res = obj2ast_int(tmp, &lineno, arena); |
| 9170 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9171 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9172 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9173 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9174 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9175 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9176 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9177 | if (tmp == NULL) { |
| 9178 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 9179 | return 1; |
| 9180 | } |
| 9181 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9182 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9183 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9184 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9185 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9186 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9187 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9188 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9189 | return 1; |
| 9190 | } |
| 9191 | if (tmp == NULL || tmp == Py_None) { |
| 9192 | Py_CLEAR(tmp); |
| 9193 | end_lineno = 0; |
| 9194 | } |
| 9195 | else { |
| 9196 | int res; |
| 9197 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9198 | if (res != 0) goto failed; |
| 9199 | Py_CLEAR(tmp); |
| 9200 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9201 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9202 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9203 | return 1; |
| 9204 | } |
| 9205 | if (tmp == NULL || tmp == Py_None) { |
| 9206 | Py_CLEAR(tmp); |
| 9207 | end_col_offset = 0; |
| 9208 | } |
| 9209 | else { |
| 9210 | int res; |
| 9211 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9212 | if (res != 0) goto failed; |
| 9213 | Py_CLEAR(tmp); |
| 9214 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9215 | tp = astmodulestate_global->ExceptHandler_type; |
| 9216 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9217 | if (isinstance == -1) { |
| 9218 | return 1; |
| 9219 | } |
| 9220 | if (isinstance) { |
| 9221 | expr_ty type; |
| 9222 | identifier name; |
| 9223 | asdl_seq* body; |
| 9224 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9225 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9226 | return 1; |
| 9227 | } |
| 9228 | if (tmp == NULL || tmp == Py_None) { |
| 9229 | Py_CLEAR(tmp); |
| 9230 | type = NULL; |
| 9231 | } |
| 9232 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9233 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9234 | res = obj2ast_expr(tmp, &type, arena); |
| 9235 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9236 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9237 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9238 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9239 | return 1; |
| 9240 | } |
| 9241 | if (tmp == NULL || tmp == Py_None) { |
| 9242 | Py_CLEAR(tmp); |
| 9243 | name = NULL; |
| 9244 | } |
| 9245 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9246 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9247 | res = obj2ast_identifier(tmp, &name, arena); |
| 9248 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9249 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9250 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9251 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9252 | return 1; |
| 9253 | } |
| 9254 | if (tmp == NULL) { |
| 9255 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 9256 | return 1; |
| 9257 | } |
| 9258 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9259 | int res; |
| 9260 | Py_ssize_t len; |
| 9261 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9262 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9263 | 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] | 9264 | goto failed; |
| 9265 | } |
| 9266 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9267 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9268 | if (body == NULL) goto failed; |
| 9269 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9270 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9271 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9272 | Py_INCREF(tmp2); |
| 9273 | res = obj2ast_stmt(tmp2, &val, arena); |
| 9274 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9275 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9276 | if (len != PyList_GET_SIZE(tmp)) { |
| 9277 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 9278 | goto failed; |
| 9279 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9280 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9281 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9282 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9283 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9284 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 9285 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9286 | if (*out == NULL) goto failed; |
| 9287 | return 0; |
| 9288 | } |
| 9289 | |
| 9290 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 9291 | failed: |
| 9292 | Py_XDECREF(tmp); |
| 9293 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9294 | } |
| 9295 | |
| 9296 | int |
| 9297 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 9298 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9299 | PyObject* tmp = NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9300 | asdl_seq* posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9301 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9302 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9303 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9304 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9305 | arg_ty kwarg; |
| 9306 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9307 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9308 | if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) < |
| 9309 | 0) { |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9310 | return 1; |
| 9311 | } |
| 9312 | if (tmp == NULL) { |
| 9313 | PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments"); |
| 9314 | return 1; |
| 9315 | } |
| 9316 | else { |
| 9317 | int res; |
| 9318 | Py_ssize_t len; |
| 9319 | Py_ssize_t i; |
| 9320 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9321 | 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] | 9322 | goto failed; |
| 9323 | } |
| 9324 | len = PyList_GET_SIZE(tmp); |
| 9325 | posonlyargs = _Py_asdl_seq_new(len, arena); |
| 9326 | if (posonlyargs == NULL) goto failed; |
| 9327 | for (i = 0; i < len; i++) { |
| 9328 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9329 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9330 | Py_INCREF(tmp2); |
| 9331 | res = obj2ast_arg(tmp2, &val, arena); |
| 9332 | Py_DECREF(tmp2); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9333 | if (res != 0) goto failed; |
| 9334 | if (len != PyList_GET_SIZE(tmp)) { |
| 9335 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration"); |
| 9336 | goto failed; |
| 9337 | } |
| 9338 | asdl_seq_SET(posonlyargs, i, val); |
| 9339 | } |
| 9340 | Py_CLEAR(tmp); |
| 9341 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9342 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9343 | return 1; |
| 9344 | } |
| 9345 | if (tmp == NULL) { |
| 9346 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 9347 | return 1; |
| 9348 | } |
| 9349 | else { |
| 9350 | int res; |
| 9351 | Py_ssize_t len; |
| 9352 | Py_ssize_t i; |
| 9353 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9354 | 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] | 9355 | goto failed; |
| 9356 | } |
| 9357 | len = PyList_GET_SIZE(tmp); |
| 9358 | args = _Py_asdl_seq_new(len, arena); |
| 9359 | if (args == NULL) goto failed; |
| 9360 | for (i = 0; i < len; i++) { |
| 9361 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9362 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9363 | Py_INCREF(tmp2); |
| 9364 | res = obj2ast_arg(tmp2, &val, arena); |
| 9365 | Py_DECREF(tmp2); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9366 | if (res != 0) goto failed; |
| 9367 | if (len != PyList_GET_SIZE(tmp)) { |
| 9368 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 9369 | goto failed; |
| 9370 | } |
| 9371 | asdl_seq_SET(args, i, val); |
| 9372 | } |
| 9373 | Py_CLEAR(tmp); |
| 9374 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9375 | if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9376 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9377 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9378 | if (tmp == NULL || tmp == Py_None) { |
| 9379 | Py_CLEAR(tmp); |
| 9380 | vararg = NULL; |
| 9381 | } |
| 9382 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9383 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9384 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9385 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9386 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9387 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9388 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0) |
| 9389 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9390 | return 1; |
| 9391 | } |
| 9392 | if (tmp == NULL) { |
| 9393 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 9394 | return 1; |
| 9395 | } |
| 9396 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9397 | int res; |
| 9398 | Py_ssize_t len; |
| 9399 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9400 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9401 | 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] | 9402 | goto failed; |
| 9403 | } |
| 9404 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9405 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9406 | if (kwonlyargs == NULL) goto failed; |
| 9407 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9408 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9409 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9410 | Py_INCREF(tmp2); |
| 9411 | res = obj2ast_arg(tmp2, &val, arena); |
| 9412 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9413 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9414 | if (len != PyList_GET_SIZE(tmp)) { |
| 9415 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 9416 | goto failed; |
| 9417 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9418 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9419 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9420 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9421 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9422 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) < |
| 9423 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9424 | return 1; |
| 9425 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9426 | if (tmp == NULL) { |
| 9427 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 9428 | return 1; |
| 9429 | } |
| 9430 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9431 | int res; |
| 9432 | Py_ssize_t len; |
| 9433 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9434 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9435 | 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] | 9436 | goto failed; |
| 9437 | } |
| 9438 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9439 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9440 | if (kw_defaults == NULL) goto failed; |
| 9441 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9442 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9443 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9444 | Py_INCREF(tmp2); |
| 9445 | res = obj2ast_expr(tmp2, &val, arena); |
| 9446 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9447 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9448 | if (len != PyList_GET_SIZE(tmp)) { |
| 9449 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 9450 | goto failed; |
| 9451 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9452 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9453 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9454 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9455 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9456 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9457 | return 1; |
| 9458 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9459 | if (tmp == NULL || tmp == Py_None) { |
| 9460 | Py_CLEAR(tmp); |
| 9461 | kwarg = NULL; |
| 9462 | } |
| 9463 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9464 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9465 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 9466 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9467 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9468 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9469 | if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9470 | return 1; |
| 9471 | } |
| 9472 | if (tmp == NULL) { |
| 9473 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 9474 | return 1; |
| 9475 | } |
| 9476 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9477 | int res; |
| 9478 | Py_ssize_t len; |
| 9479 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9480 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9481 | 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] | 9482 | goto failed; |
| 9483 | } |
| 9484 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9485 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9486 | if (defaults == NULL) goto failed; |
| 9487 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9488 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9489 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9490 | Py_INCREF(tmp2); |
| 9491 | res = obj2ast_expr(tmp2, &val, arena); |
| 9492 | Py_DECREF(tmp2); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9493 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9494 | if (len != PyList_GET_SIZE(tmp)) { |
| 9495 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 9496 | goto failed; |
| 9497 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9498 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9499 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9500 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9501 | } |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9502 | *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9503 | defaults, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9504 | return 0; |
| 9505 | failed: |
| 9506 | Py_XDECREF(tmp); |
| 9507 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9508 | } |
| 9509 | |
| 9510 | int |
| 9511 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 9512 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9513 | PyObject* tmp = NULL; |
| 9514 | identifier arg; |
| 9515 | expr_ty annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9516 | string type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9517 | int lineno; |
| 9518 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9519 | int end_lineno; |
| 9520 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9521 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9522 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9523 | return 1; |
| 9524 | } |
| 9525 | if (tmp == NULL) { |
| 9526 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 9527 | return 1; |
| 9528 | } |
| 9529 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9530 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9531 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9532 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9533 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9534 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9535 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0) |
| 9536 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9537 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9538 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9539 | if (tmp == NULL || tmp == Py_None) { |
| 9540 | Py_CLEAR(tmp); |
| 9541 | annotation = NULL; |
| 9542 | } |
| 9543 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9544 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9545 | res = obj2ast_expr(tmp, &annotation, arena); |
| 9546 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9547 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9548 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9549 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) < |
| 9550 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9551 | return 1; |
| 9552 | } |
| 9553 | if (tmp == NULL || tmp == Py_None) { |
| 9554 | Py_CLEAR(tmp); |
| 9555 | type_comment = NULL; |
| 9556 | } |
| 9557 | else { |
| 9558 | int res; |
| 9559 | res = obj2ast_string(tmp, &type_comment, arena); |
| 9560 | if (res != 0) goto failed; |
| 9561 | Py_CLEAR(tmp); |
| 9562 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9563 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9564 | return 1; |
| 9565 | } |
| 9566 | if (tmp == NULL) { |
| 9567 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 9568 | return 1; |
| 9569 | } |
| 9570 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9571 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9572 | res = obj2ast_int(tmp, &lineno, arena); |
| 9573 | if (res != 0) goto failed; |
| 9574 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9575 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9576 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9577 | { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9578 | return 1; |
| 9579 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9580 | if (tmp == NULL) { |
| 9581 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 9582 | return 1; |
| 9583 | } |
| 9584 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9585 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9586 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9587 | if (res != 0) goto failed; |
| 9588 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9589 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9590 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9591 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9592 | return 1; |
| 9593 | } |
| 9594 | if (tmp == NULL || tmp == Py_None) { |
| 9595 | Py_CLEAR(tmp); |
| 9596 | end_lineno = 0; |
| 9597 | } |
| 9598 | else { |
| 9599 | int res; |
| 9600 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9601 | if (res != 0) goto failed; |
| 9602 | Py_CLEAR(tmp); |
| 9603 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9604 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9605 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9606 | return 1; |
| 9607 | } |
| 9608 | if (tmp == NULL || tmp == Py_None) { |
| 9609 | Py_CLEAR(tmp); |
| 9610 | end_col_offset = 0; |
| 9611 | } |
| 9612 | else { |
| 9613 | int res; |
| 9614 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9615 | if (res != 0) goto failed; |
| 9616 | Py_CLEAR(tmp); |
| 9617 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9618 | *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno, |
| 9619 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9620 | return 0; |
| 9621 | failed: |
| 9622 | Py_XDECREF(tmp); |
| 9623 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9624 | } |
| 9625 | |
| 9626 | int |
| 9627 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 9628 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9629 | PyObject* tmp = NULL; |
| 9630 | identifier arg; |
| 9631 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9632 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9633 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9634 | return 1; |
| 9635 | } |
| 9636 | if (tmp == NULL || tmp == Py_None) { |
| 9637 | Py_CLEAR(tmp); |
| 9638 | arg = NULL; |
| 9639 | } |
| 9640 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9641 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9642 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9643 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9644 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9645 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9646 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9647 | return 1; |
| 9648 | } |
| 9649 | if (tmp == NULL) { |
| 9650 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 9651 | return 1; |
| 9652 | } |
| 9653 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9654 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9655 | res = obj2ast_expr(tmp, &value, arena); |
| 9656 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9657 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9658 | } |
| 9659 | *out = keyword(arg, value, arena); |
| 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_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 9668 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9669 | PyObject* tmp = NULL; |
| 9670 | identifier name; |
| 9671 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9672 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9673 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9674 | return 1; |
| 9675 | } |
| 9676 | if (tmp == NULL) { |
| 9677 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 9678 | return 1; |
| 9679 | } |
| 9680 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9681 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9682 | res = obj2ast_identifier(tmp, &name, arena); |
| 9683 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9684 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9685 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9686 | if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9687 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9688 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9689 | if (tmp == NULL || tmp == Py_None) { |
| 9690 | Py_CLEAR(tmp); |
| 9691 | asname = NULL; |
| 9692 | } |
| 9693 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9694 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9695 | res = obj2ast_identifier(tmp, &asname, arena); |
| 9696 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9697 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9698 | } |
| 9699 | *out = alias(name, asname, arena); |
| 9700 | return 0; |
| 9701 | failed: |
| 9702 | Py_XDECREF(tmp); |
| 9703 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9704 | } |
| 9705 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9706 | int |
| 9707 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 9708 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9709 | PyObject* tmp = NULL; |
| 9710 | expr_ty context_expr; |
| 9711 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9712 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9713 | if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) < |
| 9714 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9715 | return 1; |
| 9716 | } |
| 9717 | if (tmp == NULL) { |
| 9718 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 9719 | return 1; |
| 9720 | } |
| 9721 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9722 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9723 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 9724 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9725 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9726 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9727 | if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) < |
| 9728 | 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9729 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9730 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9731 | if (tmp == NULL || tmp == Py_None) { |
| 9732 | Py_CLEAR(tmp); |
| 9733 | optional_vars = NULL; |
| 9734 | } |
| 9735 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9736 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9737 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 9738 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9739 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9740 | } |
| 9741 | *out = withitem(context_expr, optional_vars, arena); |
| 9742 | return 0; |
| 9743 | failed: |
| 9744 | Py_XDECREF(tmp); |
| 9745 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9746 | } |
| 9747 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9748 | int |
| 9749 | obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) |
| 9750 | { |
| 9751 | int isinstance; |
| 9752 | |
| 9753 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9754 | PyObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9755 | |
| 9756 | if (obj == Py_None) { |
| 9757 | *out = NULL; |
| 9758 | return 0; |
| 9759 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9760 | tp = astmodulestate_global->TypeIgnore_type; |
| 9761 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9762 | if (isinstance == -1) { |
| 9763 | return 1; |
| 9764 | } |
| 9765 | if (isinstance) { |
| 9766 | int lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9767 | string tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9768 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9769 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) |
| 9770 | { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9771 | return 1; |
| 9772 | } |
| 9773 | if (tmp == NULL) { |
| 9774 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore"); |
| 9775 | return 1; |
| 9776 | } |
| 9777 | else { |
| 9778 | int res; |
| 9779 | res = obj2ast_int(tmp, &lineno, arena); |
| 9780 | if (res != 0) goto failed; |
| 9781 | Py_CLEAR(tmp); |
| 9782 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9783 | if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) { |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9784 | return 1; |
| 9785 | } |
| 9786 | if (tmp == NULL) { |
| 9787 | PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore"); |
| 9788 | return 1; |
| 9789 | } |
| 9790 | else { |
| 9791 | int res; |
| 9792 | res = obj2ast_string(tmp, &tag, arena); |
| 9793 | if (res != 0) goto failed; |
| 9794 | Py_CLEAR(tmp); |
| 9795 | } |
| 9796 | *out = TypeIgnore(lineno, tag, arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9797 | if (*out == NULL) goto failed; |
| 9798 | return 0; |
| 9799 | } |
| 9800 | |
| 9801 | PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj); |
| 9802 | failed: |
| 9803 | Py_XDECREF(tmp); |
| 9804 | return 1; |
| 9805 | } |
| 9806 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9807 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9808 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 9809 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9810 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9811 | PyObject *m; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9812 | if (!init_types()) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9813 | m = PyState_FindModule(&_astmodule); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9814 | if (!m) return NULL; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9815 | if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) { |
| 9816 | goto error; |
| 9817 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9818 | Py_INCREF(astmodulestate(m)->AST_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9819 | if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) { |
| 9820 | goto error; |
| 9821 | } |
| 9822 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) { |
| 9823 | goto error; |
| 9824 | } |
| 9825 | if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) { |
| 9826 | goto error; |
| 9827 | } |
| 9828 | if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) { |
| 9829 | goto error; |
| 9830 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9831 | Py_INCREF(astmodulestate(m)->mod_type); |
| 9832 | if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9833 | 0) { |
| 9834 | goto error; |
| 9835 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9836 | Py_INCREF(astmodulestate(m)->Module_type); |
| 9837 | if (PyModule_AddObject(m, "Interactive", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9838 | astmodulestate_global->Interactive_type) < 0) { |
| 9839 | goto error; |
| 9840 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9841 | Py_INCREF(astmodulestate(m)->Interactive_type); |
| 9842 | if (PyModule_AddObject(m, "Expression", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9843 | astmodulestate_global->Expression_type) < 0) { |
| 9844 | goto error; |
| 9845 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9846 | Py_INCREF(astmodulestate(m)->Expression_type); |
| 9847 | if (PyModule_AddObject(m, "FunctionType", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9848 | astmodulestate_global->FunctionType_type) < 0) { |
| 9849 | goto error; |
| 9850 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9851 | Py_INCREF(astmodulestate(m)->FunctionType_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9852 | if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) { |
| 9853 | goto error; |
| 9854 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9855 | Py_INCREF(astmodulestate(m)->stmt_type); |
| 9856 | if (PyModule_AddObject(m, "FunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9857 | astmodulestate_global->FunctionDef_type) < 0) { |
| 9858 | goto error; |
| 9859 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9860 | Py_INCREF(astmodulestate(m)->FunctionDef_type); |
| 9861 | if (PyModule_AddObject(m, "AsyncFunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9862 | astmodulestate_global->AsyncFunctionDef_type) < 0) { |
| 9863 | goto error; |
| 9864 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9865 | Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type); |
| 9866 | if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9867 | < 0) { |
| 9868 | goto error; |
| 9869 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9870 | Py_INCREF(astmodulestate(m)->ClassDef_type); |
| 9871 | if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9872 | 0) { |
| 9873 | goto error; |
| 9874 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9875 | Py_INCREF(astmodulestate(m)->Return_type); |
| 9876 | if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9877 | 0) { |
| 9878 | goto error; |
| 9879 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9880 | Py_INCREF(astmodulestate(m)->Delete_type); |
| 9881 | if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9882 | 0) { |
| 9883 | goto error; |
| 9884 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9885 | Py_INCREF(astmodulestate(m)->Assign_type); |
| 9886 | if (PyModule_AddObject(m, "AugAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9887 | astmodulestate_global->AugAssign_type) < 0) { |
| 9888 | goto error; |
| 9889 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9890 | Py_INCREF(astmodulestate(m)->AugAssign_type); |
| 9891 | if (PyModule_AddObject(m, "AnnAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9892 | astmodulestate_global->AnnAssign_type) < 0) { |
| 9893 | goto error; |
| 9894 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9895 | Py_INCREF(astmodulestate(m)->AnnAssign_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9896 | if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) { |
| 9897 | goto error; |
| 9898 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9899 | Py_INCREF(astmodulestate(m)->For_type); |
| 9900 | if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9901 | < 0) { |
| 9902 | goto error; |
| 9903 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9904 | Py_INCREF(astmodulestate(m)->AsyncFor_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9905 | if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) { |
| 9906 | goto error; |
| 9907 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9908 | Py_INCREF(astmodulestate(m)->While_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9909 | if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) { |
| 9910 | goto error; |
| 9911 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9912 | Py_INCREF(astmodulestate(m)->If_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9913 | if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) { |
| 9914 | goto error; |
| 9915 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9916 | Py_INCREF(astmodulestate(m)->With_type); |
| 9917 | if (PyModule_AddObject(m, "AsyncWith", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9918 | astmodulestate_global->AsyncWith_type) < 0) { |
| 9919 | goto error; |
| 9920 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9921 | Py_INCREF(astmodulestate(m)->AsyncWith_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9922 | if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) { |
| 9923 | goto error; |
| 9924 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9925 | Py_INCREF(astmodulestate(m)->Raise_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9926 | if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) { |
| 9927 | goto error; |
| 9928 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9929 | Py_INCREF(astmodulestate(m)->Try_type); |
| 9930 | if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9931 | 0) { |
| 9932 | goto error; |
| 9933 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9934 | Py_INCREF(astmodulestate(m)->Assert_type); |
| 9935 | if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9936 | 0) { |
| 9937 | goto error; |
| 9938 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9939 | Py_INCREF(astmodulestate(m)->Import_type); |
| 9940 | if (PyModule_AddObject(m, "ImportFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9941 | astmodulestate_global->ImportFrom_type) < 0) { |
| 9942 | goto error; |
| 9943 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9944 | Py_INCREF(astmodulestate(m)->ImportFrom_type); |
| 9945 | if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9946 | 0) { |
| 9947 | goto error; |
| 9948 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9949 | Py_INCREF(astmodulestate(m)->Global_type); |
| 9950 | if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9951 | < 0) { |
| 9952 | goto error; |
| 9953 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9954 | Py_INCREF(astmodulestate(m)->Nonlocal_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9955 | if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) { |
| 9956 | goto error; |
| 9957 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9958 | Py_INCREF(astmodulestate(m)->Expr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9959 | if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) { |
| 9960 | goto error; |
| 9961 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9962 | Py_INCREF(astmodulestate(m)->Pass_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9963 | if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) { |
| 9964 | goto error; |
| 9965 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9966 | Py_INCREF(astmodulestate(m)->Break_type); |
| 9967 | if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9968 | < 0) { |
| 9969 | goto error; |
| 9970 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9971 | Py_INCREF(astmodulestate(m)->Continue_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9972 | if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) { |
| 9973 | goto error; |
| 9974 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9975 | Py_INCREF(astmodulestate(m)->expr_type); |
| 9976 | if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_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)->BoolOp_type); |
| 9981 | if (PyModule_AddObject(m, "NamedExpr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9982 | astmodulestate_global->NamedExpr_type) < 0) { |
| 9983 | goto error; |
| 9984 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9985 | Py_INCREF(astmodulestate(m)->NamedExpr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9986 | if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) { |
| 9987 | goto error; |
| 9988 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9989 | Py_INCREF(astmodulestate(m)->BinOp_type); |
| 9990 | if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9991 | 0) { |
| 9992 | goto error; |
| 9993 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9994 | Py_INCREF(astmodulestate(m)->UnaryOp_type); |
| 9995 | if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9996 | 0) { |
| 9997 | goto error; |
| 9998 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9999 | Py_INCREF(astmodulestate(m)->Lambda_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10000 | if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) { |
| 10001 | goto error; |
| 10002 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10003 | Py_INCREF(astmodulestate(m)->IfExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10004 | if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) { |
| 10005 | goto error; |
| 10006 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10007 | Py_INCREF(astmodulestate(m)->Dict_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10008 | if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) { |
| 10009 | goto error; |
| 10010 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10011 | Py_INCREF(astmodulestate(m)->Set_type); |
| 10012 | if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10013 | < 0) { |
| 10014 | goto error; |
| 10015 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10016 | Py_INCREF(astmodulestate(m)->ListComp_type); |
| 10017 | if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10018 | 0) { |
| 10019 | goto error; |
| 10020 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10021 | Py_INCREF(astmodulestate(m)->SetComp_type); |
| 10022 | if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10023 | < 0) { |
| 10024 | goto error; |
| 10025 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10026 | Py_INCREF(astmodulestate(m)->DictComp_type); |
| 10027 | if (PyModule_AddObject(m, "GeneratorExp", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10028 | astmodulestate_global->GeneratorExp_type) < 0) { |
| 10029 | goto error; |
| 10030 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10031 | Py_INCREF(astmodulestate(m)->GeneratorExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10032 | if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) { |
| 10033 | goto error; |
| 10034 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10035 | Py_INCREF(astmodulestate(m)->Await_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10036 | if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) { |
| 10037 | goto error; |
| 10038 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10039 | Py_INCREF(astmodulestate(m)->Yield_type); |
| 10040 | if (PyModule_AddObject(m, "YieldFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10041 | astmodulestate_global->YieldFrom_type) < 0) { |
| 10042 | goto error; |
| 10043 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10044 | Py_INCREF(astmodulestate(m)->YieldFrom_type); |
| 10045 | if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_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)->Compare_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10050 | if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) { |
| 10051 | goto error; |
| 10052 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10053 | Py_INCREF(astmodulestate(m)->Call_type); |
| 10054 | if (PyModule_AddObject(m, "FormattedValue", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10055 | astmodulestate_global->FormattedValue_type) < 0) { |
| 10056 | goto error; |
| 10057 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10058 | Py_INCREF(astmodulestate(m)->FormattedValue_type); |
| 10059 | if (PyModule_AddObject(m, "JoinedStr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10060 | astmodulestate_global->JoinedStr_type) < 0) { |
| 10061 | goto error; |
| 10062 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10063 | Py_INCREF(astmodulestate(m)->JoinedStr_type); |
| 10064 | if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10065 | < 0) { |
| 10066 | goto error; |
| 10067 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10068 | Py_INCREF(astmodulestate(m)->Constant_type); |
| 10069 | if (PyModule_AddObject(m, "Attribute", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10070 | astmodulestate_global->Attribute_type) < 0) { |
| 10071 | goto error; |
| 10072 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10073 | Py_INCREF(astmodulestate(m)->Attribute_type); |
| 10074 | if (PyModule_AddObject(m, "Subscript", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10075 | astmodulestate_global->Subscript_type) < 0) { |
| 10076 | goto error; |
| 10077 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10078 | Py_INCREF(astmodulestate(m)->Subscript_type); |
| 10079 | if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10080 | 0) { |
| 10081 | goto error; |
| 10082 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10083 | Py_INCREF(astmodulestate(m)->Starred_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10084 | if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) { |
| 10085 | goto error; |
| 10086 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10087 | Py_INCREF(astmodulestate(m)->Name_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10088 | if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) { |
| 10089 | goto error; |
| 10090 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10091 | Py_INCREF(astmodulestate(m)->List_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10092 | if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) { |
| 10093 | goto error; |
| 10094 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10095 | Py_INCREF(astmodulestate(m)->Tuple_type); |
| 10096 | if (PyModule_AddObject(m, "expr_context", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10097 | astmodulestate_global->expr_context_type) < 0) { |
| 10098 | goto error; |
| 10099 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10100 | Py_INCREF(astmodulestate(m)->expr_context_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10101 | if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) { |
| 10102 | goto error; |
| 10103 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10104 | Py_INCREF(astmodulestate(m)->Load_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10105 | if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) { |
| 10106 | goto error; |
| 10107 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10108 | Py_INCREF(astmodulestate(m)->Store_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10109 | if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) { |
| 10110 | goto error; |
| 10111 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10112 | Py_INCREF(astmodulestate(m)->Del_type); |
| 10113 | if (PyModule_AddObject(m, "AugLoad", astmodulestate_global->AugLoad_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10114 | 0) { |
| 10115 | goto error; |
| 10116 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10117 | Py_INCREF(astmodulestate(m)->AugLoad_type); |
| 10118 | if (PyModule_AddObject(m, "AugStore", astmodulestate_global->AugStore_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10119 | < 0) { |
| 10120 | goto error; |
| 10121 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10122 | Py_INCREF(astmodulestate(m)->AugStore_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10123 | if (PyModule_AddObject(m, "Param", astmodulestate_global->Param_type) < 0) { |
| 10124 | goto error; |
| 10125 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10126 | Py_INCREF(astmodulestate(m)->Param_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10127 | if (PyModule_AddObject(m, "slice", astmodulestate_global->slice_type) < 0) { |
| 10128 | goto error; |
| 10129 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10130 | Py_INCREF(astmodulestate(m)->slice_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10131 | if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) { |
| 10132 | goto error; |
| 10133 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10134 | Py_INCREF(astmodulestate(m)->Slice_type); |
| 10135 | if (PyModule_AddObject(m, "ExtSlice", astmodulestate_global->ExtSlice_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10136 | < 0) { |
| 10137 | goto error; |
| 10138 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10139 | Py_INCREF(astmodulestate(m)->ExtSlice_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10140 | if (PyModule_AddObject(m, "Index", astmodulestate_global->Index_type) < 0) { |
| 10141 | goto error; |
| 10142 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10143 | Py_INCREF(astmodulestate(m)->Index_type); |
| 10144 | if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10145 | 0) { |
| 10146 | goto error; |
| 10147 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10148 | Py_INCREF(astmodulestate(m)->boolop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10149 | if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) { |
| 10150 | goto error; |
| 10151 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10152 | Py_INCREF(astmodulestate(m)->And_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10153 | if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) { |
| 10154 | goto error; |
| 10155 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10156 | Py_INCREF(astmodulestate(m)->Or_type); |
| 10157 | if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10158 | < 0) { |
| 10159 | goto error; |
| 10160 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10161 | Py_INCREF(astmodulestate(m)->operator_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10162 | if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) { |
| 10163 | goto error; |
| 10164 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10165 | Py_INCREF(astmodulestate(m)->Add_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10166 | if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) { |
| 10167 | goto error; |
| 10168 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10169 | Py_INCREF(astmodulestate(m)->Sub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10170 | if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) { |
| 10171 | goto error; |
| 10172 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10173 | Py_INCREF(astmodulestate(m)->Mult_type); |
| 10174 | if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10175 | 0) { |
| 10176 | goto error; |
| 10177 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10178 | Py_INCREF(astmodulestate(m)->MatMult_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10179 | if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) { |
| 10180 | goto error; |
| 10181 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10182 | Py_INCREF(astmodulestate(m)->Div_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10183 | if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) { |
| 10184 | goto error; |
| 10185 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10186 | Py_INCREF(astmodulestate(m)->Mod_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10187 | if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) { |
| 10188 | goto error; |
| 10189 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10190 | Py_INCREF(astmodulestate(m)->Pow_type); |
| 10191 | if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10192 | 0) { |
| 10193 | goto error; |
| 10194 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10195 | Py_INCREF(astmodulestate(m)->LShift_type); |
| 10196 | if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10197 | 0) { |
| 10198 | goto error; |
| 10199 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10200 | Py_INCREF(astmodulestate(m)->RShift_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10201 | if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) { |
| 10202 | goto error; |
| 10203 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10204 | Py_INCREF(astmodulestate(m)->BitOr_type); |
| 10205 | if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10206 | 0) { |
| 10207 | goto error; |
| 10208 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10209 | Py_INCREF(astmodulestate(m)->BitXor_type); |
| 10210 | if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10211 | 0) { |
| 10212 | goto error; |
| 10213 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10214 | Py_INCREF(astmodulestate(m)->BitAnd_type); |
| 10215 | if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10216 | < 0) { |
| 10217 | goto error; |
| 10218 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10219 | Py_INCREF(astmodulestate(m)->FloorDiv_type); |
| 10220 | if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10221 | 0) { |
| 10222 | goto error; |
| 10223 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10224 | Py_INCREF(astmodulestate(m)->unaryop_type); |
| 10225 | if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10226 | 0) { |
| 10227 | goto error; |
| 10228 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10229 | Py_INCREF(astmodulestate(m)->Invert_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10230 | if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) { |
| 10231 | goto error; |
| 10232 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10233 | Py_INCREF(astmodulestate(m)->Not_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10234 | if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) { |
| 10235 | goto error; |
| 10236 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10237 | Py_INCREF(astmodulestate(m)->UAdd_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10238 | if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) { |
| 10239 | goto error; |
| 10240 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10241 | Py_INCREF(astmodulestate(m)->USub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10242 | if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) { |
| 10243 | goto error; |
| 10244 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10245 | Py_INCREF(astmodulestate(m)->cmpop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10246 | if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) { |
| 10247 | goto error; |
| 10248 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10249 | Py_INCREF(astmodulestate(m)->Eq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10250 | if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) { |
| 10251 | goto error; |
| 10252 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10253 | Py_INCREF(astmodulestate(m)->NotEq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10254 | if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) { |
| 10255 | goto error; |
| 10256 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10257 | Py_INCREF(astmodulestate(m)->Lt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10258 | if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) { |
| 10259 | goto error; |
| 10260 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10261 | Py_INCREF(astmodulestate(m)->LtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10262 | if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) { |
| 10263 | goto error; |
| 10264 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10265 | Py_INCREF(astmodulestate(m)->Gt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10266 | if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) { |
| 10267 | goto error; |
| 10268 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10269 | Py_INCREF(astmodulestate(m)->GtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10270 | if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) { |
| 10271 | goto error; |
| 10272 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10273 | Py_INCREF(astmodulestate(m)->Is_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10274 | if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) { |
| 10275 | goto error; |
| 10276 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10277 | Py_INCREF(astmodulestate(m)->IsNot_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10278 | if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) { |
| 10279 | goto error; |
| 10280 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10281 | Py_INCREF(astmodulestate(m)->In_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10282 | if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) { |
| 10283 | goto error; |
| 10284 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10285 | Py_INCREF(astmodulestate(m)->NotIn_type); |
| 10286 | if (PyModule_AddObject(m, "comprehension", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10287 | astmodulestate_global->comprehension_type) < 0) { |
| 10288 | goto error; |
| 10289 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10290 | Py_INCREF(astmodulestate(m)->comprehension_type); |
| 10291 | if (PyModule_AddObject(m, "excepthandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10292 | astmodulestate_global->excepthandler_type) < 0) { |
| 10293 | goto error; |
| 10294 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10295 | Py_INCREF(astmodulestate(m)->excepthandler_type); |
| 10296 | if (PyModule_AddObject(m, "ExceptHandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10297 | astmodulestate_global->ExceptHandler_type) < 0) { |
| 10298 | goto error; |
| 10299 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10300 | Py_INCREF(astmodulestate(m)->ExceptHandler_type); |
| 10301 | if (PyModule_AddObject(m, "arguments", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10302 | astmodulestate_global->arguments_type) < 0) { |
| 10303 | goto error; |
| 10304 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10305 | Py_INCREF(astmodulestate(m)->arguments_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10306 | if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) { |
| 10307 | goto error; |
| 10308 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10309 | Py_INCREF(astmodulestate(m)->arg_type); |
| 10310 | if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10311 | 0) { |
| 10312 | goto error; |
| 10313 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10314 | Py_INCREF(astmodulestate(m)->keyword_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10315 | if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) { |
| 10316 | goto error; |
| 10317 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10318 | Py_INCREF(astmodulestate(m)->alias_type); |
| 10319 | if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10320 | < 0) { |
| 10321 | goto error; |
| 10322 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10323 | Py_INCREF(astmodulestate(m)->withitem_type); |
| 10324 | if (PyModule_AddObject(m, "type_ignore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10325 | astmodulestate_global->type_ignore_type) < 0) { |
| 10326 | goto error; |
| 10327 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10328 | Py_INCREF(astmodulestate(m)->type_ignore_type); |
| 10329 | if (PyModule_AddObject(m, "TypeIgnore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10330 | astmodulestate_global->TypeIgnore_type) < 0) { |
| 10331 | goto error; |
| 10332 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10333 | Py_INCREF(astmodulestate(m)->TypeIgnore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 10334 | return m; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10335 | error: |
| 10336 | Py_DECREF(m); |
| 10337 | return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 10338 | } |
| 10339 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10340 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10341 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10342 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10343 | if (!init_types()) |
| 10344 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10345 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10346 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10347 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10348 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 10349 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10350 | { |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 10351 | PyObject *req_type[3]; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 10352 | const char * const req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10353 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10354 | |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 10355 | if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { |
| 10356 | return NULL; |
| 10357 | } |
| 10358 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10359 | req_type[0] = astmodulestate_global->Module_type; |
| 10360 | req_type[1] = astmodulestate_global->Expression_type; |
| 10361 | req_type[2] = astmodulestate_global->Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10362 | |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 10363 | assert(0 <= mode && mode <= 2); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10364 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10365 | if (!init_types()) |
| 10366 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10367 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10368 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 10369 | if (isinstance == -1) |
| 10370 | return NULL; |
| 10371 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10372 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10373 | req_name[mode], _PyType_Name(Py_TYPE(ast))); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10374 | return NULL; |
| 10375 | } |
Dong-hee Na | a05fcd3 | 2019-10-10 16:41:26 +0900 | [diff] [blame] | 10376 | |
| 10377 | mod_ty res = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10378 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 10379 | return NULL; |
| 10380 | else |
| 10381 | return res; |
| 10382 | } |
| 10383 | |
| 10384 | int PyAST_Check(PyObject* obj) |
| 10385 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10386 | if (!init_types()) |
| 10387 | return -1; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10388 | return PyObject_IsInstance(obj, astmodulestate_global->AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10389 | } |
| 10390 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10391 | |