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; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 24 | PyObject *Await_type; |
| 25 | PyObject *BinOp_type; |
| 26 | PyObject *BitAnd_singleton; |
| 27 | PyObject *BitAnd_type; |
| 28 | PyObject *BitOr_singleton; |
| 29 | PyObject *BitOr_type; |
| 30 | PyObject *BitXor_singleton; |
| 31 | PyObject *BitXor_type; |
| 32 | PyObject *BoolOp_type; |
| 33 | PyObject *Break_type; |
| 34 | PyObject *Call_type; |
| 35 | PyObject *ClassDef_type; |
| 36 | PyObject *Compare_type; |
| 37 | PyObject *Constant_type; |
| 38 | PyObject *Continue_type; |
| 39 | PyObject *Del_singleton; |
| 40 | PyObject *Del_type; |
| 41 | PyObject *Delete_type; |
| 42 | PyObject *DictComp_type; |
| 43 | PyObject *Dict_type; |
| 44 | PyObject *Div_singleton; |
| 45 | PyObject *Div_type; |
| 46 | PyObject *Eq_singleton; |
| 47 | PyObject *Eq_type; |
| 48 | PyObject *ExceptHandler_type; |
| 49 | PyObject *Expr_type; |
| 50 | PyObject *Expression_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 51 | PyObject *FloorDiv_singleton; |
| 52 | PyObject *FloorDiv_type; |
| 53 | PyObject *For_type; |
| 54 | PyObject *FormattedValue_type; |
| 55 | PyObject *FunctionDef_type; |
| 56 | PyObject *FunctionType_type; |
| 57 | PyObject *GeneratorExp_type; |
| 58 | PyObject *Global_type; |
| 59 | PyObject *GtE_singleton; |
| 60 | PyObject *GtE_type; |
| 61 | PyObject *Gt_singleton; |
| 62 | PyObject *Gt_type; |
| 63 | PyObject *IfExp_type; |
| 64 | PyObject *If_type; |
| 65 | PyObject *ImportFrom_type; |
| 66 | PyObject *Import_type; |
| 67 | PyObject *In_singleton; |
| 68 | PyObject *In_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 69 | PyObject *Interactive_type; |
| 70 | PyObject *Invert_singleton; |
| 71 | PyObject *Invert_type; |
| 72 | PyObject *IsNot_singleton; |
| 73 | PyObject *IsNot_type; |
| 74 | PyObject *Is_singleton; |
| 75 | PyObject *Is_type; |
| 76 | PyObject *JoinedStr_type; |
| 77 | PyObject *LShift_singleton; |
| 78 | PyObject *LShift_type; |
| 79 | PyObject *Lambda_type; |
| 80 | PyObject *ListComp_type; |
| 81 | PyObject *List_type; |
| 82 | PyObject *Load_singleton; |
| 83 | PyObject *Load_type; |
| 84 | PyObject *LtE_singleton; |
| 85 | PyObject *LtE_type; |
| 86 | PyObject *Lt_singleton; |
| 87 | PyObject *Lt_type; |
| 88 | PyObject *MatMult_singleton; |
| 89 | PyObject *MatMult_type; |
| 90 | PyObject *Mod_singleton; |
| 91 | PyObject *Mod_type; |
| 92 | PyObject *Module_type; |
| 93 | PyObject *Mult_singleton; |
| 94 | PyObject *Mult_type; |
| 95 | PyObject *Name_type; |
| 96 | PyObject *NamedExpr_type; |
| 97 | PyObject *Nonlocal_type; |
| 98 | PyObject *NotEq_singleton; |
| 99 | PyObject *NotEq_type; |
| 100 | PyObject *NotIn_singleton; |
| 101 | PyObject *NotIn_type; |
| 102 | PyObject *Not_singleton; |
| 103 | PyObject *Not_type; |
| 104 | PyObject *Or_singleton; |
| 105 | PyObject *Or_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 106 | PyObject *Pass_type; |
| 107 | PyObject *Pow_singleton; |
| 108 | PyObject *Pow_type; |
| 109 | PyObject *RShift_singleton; |
| 110 | PyObject *RShift_type; |
| 111 | PyObject *Raise_type; |
| 112 | PyObject *Return_type; |
| 113 | PyObject *SetComp_type; |
| 114 | PyObject *Set_type; |
| 115 | PyObject *Slice_type; |
| 116 | PyObject *Starred_type; |
| 117 | PyObject *Store_singleton; |
| 118 | PyObject *Store_type; |
| 119 | PyObject *Sub_singleton; |
| 120 | PyObject *Sub_type; |
| 121 | PyObject *Subscript_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 122 | PyObject *Try_type; |
| 123 | PyObject *Tuple_type; |
| 124 | PyObject *TypeIgnore_type; |
| 125 | PyObject *UAdd_singleton; |
| 126 | PyObject *UAdd_type; |
| 127 | PyObject *USub_singleton; |
| 128 | PyObject *USub_type; |
| 129 | PyObject *UnaryOp_type; |
| 130 | PyObject *While_type; |
| 131 | PyObject *With_type; |
| 132 | PyObject *YieldFrom_type; |
| 133 | PyObject *Yield_type; |
| 134 | PyObject *__dict__; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 135 | PyObject *__doc__; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 136 | PyObject *__module__; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 137 | PyObject *_attributes; |
| 138 | PyObject *_fields; |
| 139 | PyObject *alias_type; |
| 140 | PyObject *annotation; |
| 141 | PyObject *arg; |
| 142 | PyObject *arg_type; |
| 143 | PyObject *args; |
| 144 | PyObject *argtypes; |
| 145 | PyObject *arguments_type; |
| 146 | PyObject *asname; |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 147 | PyObject *ast; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 148 | PyObject *attr; |
| 149 | PyObject *bases; |
| 150 | PyObject *body; |
| 151 | PyObject *boolop_type; |
| 152 | PyObject *cause; |
| 153 | PyObject *cmpop_type; |
| 154 | PyObject *col_offset; |
| 155 | PyObject *comparators; |
| 156 | PyObject *comprehension_type; |
| 157 | PyObject *context_expr; |
| 158 | PyObject *conversion; |
| 159 | PyObject *ctx; |
| 160 | PyObject *decorator_list; |
| 161 | PyObject *defaults; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 162 | PyObject *elt; |
| 163 | PyObject *elts; |
| 164 | PyObject *end_col_offset; |
| 165 | PyObject *end_lineno; |
| 166 | PyObject *exc; |
| 167 | PyObject *excepthandler_type; |
| 168 | PyObject *expr_context_type; |
| 169 | PyObject *expr_type; |
| 170 | PyObject *finalbody; |
| 171 | PyObject *format_spec; |
| 172 | PyObject *func; |
| 173 | PyObject *generators; |
| 174 | PyObject *handlers; |
| 175 | PyObject *id; |
| 176 | PyObject *ifs; |
| 177 | PyObject *is_async; |
| 178 | PyObject *items; |
| 179 | PyObject *iter; |
| 180 | PyObject *key; |
| 181 | PyObject *keys; |
| 182 | PyObject *keyword_type; |
| 183 | PyObject *keywords; |
| 184 | PyObject *kind; |
| 185 | PyObject *kw_defaults; |
| 186 | PyObject *kwarg; |
| 187 | PyObject *kwonlyargs; |
| 188 | PyObject *left; |
| 189 | PyObject *level; |
| 190 | PyObject *lineno; |
| 191 | PyObject *lower; |
| 192 | PyObject *mod_type; |
| 193 | PyObject *module; |
| 194 | PyObject *msg; |
| 195 | PyObject *name; |
| 196 | PyObject *names; |
| 197 | PyObject *op; |
| 198 | PyObject *operand; |
| 199 | PyObject *operator_type; |
| 200 | PyObject *ops; |
| 201 | PyObject *optional_vars; |
| 202 | PyObject *orelse; |
| 203 | PyObject *posonlyargs; |
| 204 | PyObject *returns; |
| 205 | PyObject *right; |
| 206 | PyObject *simple; |
| 207 | PyObject *slice; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 208 | PyObject *step; |
| 209 | PyObject *stmt_type; |
| 210 | PyObject *tag; |
| 211 | PyObject *target; |
| 212 | PyObject *targets; |
| 213 | PyObject *test; |
| 214 | PyObject *type; |
| 215 | PyObject *type_comment; |
| 216 | PyObject *type_ignore_type; |
| 217 | PyObject *type_ignores; |
| 218 | PyObject *unaryop_type; |
| 219 | PyObject *upper; |
| 220 | PyObject *value; |
| 221 | PyObject *values; |
| 222 | PyObject *vararg; |
| 223 | PyObject *withitem_type; |
| 224 | } astmodulestate; |
| 225 | |
| 226 | |
| 227 | #define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o)) |
| 228 | |
| 229 | static int astmodule_clear(PyObject *module) |
| 230 | { |
| 231 | Py_CLEAR(astmodulestate(module)->AST_type); |
| 232 | Py_CLEAR(astmodulestate(module)->Add_singleton); |
| 233 | Py_CLEAR(astmodulestate(module)->Add_type); |
| 234 | Py_CLEAR(astmodulestate(module)->And_singleton); |
| 235 | Py_CLEAR(astmodulestate(module)->And_type); |
| 236 | Py_CLEAR(astmodulestate(module)->AnnAssign_type); |
| 237 | Py_CLEAR(astmodulestate(module)->Assert_type); |
| 238 | Py_CLEAR(astmodulestate(module)->Assign_type); |
| 239 | Py_CLEAR(astmodulestate(module)->AsyncFor_type); |
| 240 | Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type); |
| 241 | Py_CLEAR(astmodulestate(module)->AsyncWith_type); |
| 242 | Py_CLEAR(astmodulestate(module)->Attribute_type); |
| 243 | Py_CLEAR(astmodulestate(module)->AugAssign_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 244 | Py_CLEAR(astmodulestate(module)->Await_type); |
| 245 | Py_CLEAR(astmodulestate(module)->BinOp_type); |
| 246 | Py_CLEAR(astmodulestate(module)->BitAnd_singleton); |
| 247 | Py_CLEAR(astmodulestate(module)->BitAnd_type); |
| 248 | Py_CLEAR(astmodulestate(module)->BitOr_singleton); |
| 249 | Py_CLEAR(astmodulestate(module)->BitOr_type); |
| 250 | Py_CLEAR(astmodulestate(module)->BitXor_singleton); |
| 251 | Py_CLEAR(astmodulestate(module)->BitXor_type); |
| 252 | Py_CLEAR(astmodulestate(module)->BoolOp_type); |
| 253 | Py_CLEAR(astmodulestate(module)->Break_type); |
| 254 | Py_CLEAR(astmodulestate(module)->Call_type); |
| 255 | Py_CLEAR(astmodulestate(module)->ClassDef_type); |
| 256 | Py_CLEAR(astmodulestate(module)->Compare_type); |
| 257 | Py_CLEAR(astmodulestate(module)->Constant_type); |
| 258 | Py_CLEAR(astmodulestate(module)->Continue_type); |
| 259 | Py_CLEAR(astmodulestate(module)->Del_singleton); |
| 260 | Py_CLEAR(astmodulestate(module)->Del_type); |
| 261 | Py_CLEAR(astmodulestate(module)->Delete_type); |
| 262 | Py_CLEAR(astmodulestate(module)->DictComp_type); |
| 263 | Py_CLEAR(astmodulestate(module)->Dict_type); |
| 264 | Py_CLEAR(astmodulestate(module)->Div_singleton); |
| 265 | Py_CLEAR(astmodulestate(module)->Div_type); |
| 266 | Py_CLEAR(astmodulestate(module)->Eq_singleton); |
| 267 | Py_CLEAR(astmodulestate(module)->Eq_type); |
| 268 | Py_CLEAR(astmodulestate(module)->ExceptHandler_type); |
| 269 | Py_CLEAR(astmodulestate(module)->Expr_type); |
| 270 | Py_CLEAR(astmodulestate(module)->Expression_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 271 | Py_CLEAR(astmodulestate(module)->FloorDiv_singleton); |
| 272 | Py_CLEAR(astmodulestate(module)->FloorDiv_type); |
| 273 | Py_CLEAR(astmodulestate(module)->For_type); |
| 274 | Py_CLEAR(astmodulestate(module)->FormattedValue_type); |
| 275 | Py_CLEAR(astmodulestate(module)->FunctionDef_type); |
| 276 | Py_CLEAR(astmodulestate(module)->FunctionType_type); |
| 277 | Py_CLEAR(astmodulestate(module)->GeneratorExp_type); |
| 278 | Py_CLEAR(astmodulestate(module)->Global_type); |
| 279 | Py_CLEAR(astmodulestate(module)->GtE_singleton); |
| 280 | Py_CLEAR(astmodulestate(module)->GtE_type); |
| 281 | Py_CLEAR(astmodulestate(module)->Gt_singleton); |
| 282 | Py_CLEAR(astmodulestate(module)->Gt_type); |
| 283 | Py_CLEAR(astmodulestate(module)->IfExp_type); |
| 284 | Py_CLEAR(astmodulestate(module)->If_type); |
| 285 | Py_CLEAR(astmodulestate(module)->ImportFrom_type); |
| 286 | Py_CLEAR(astmodulestate(module)->Import_type); |
| 287 | Py_CLEAR(astmodulestate(module)->In_singleton); |
| 288 | Py_CLEAR(astmodulestate(module)->In_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 289 | Py_CLEAR(astmodulestate(module)->Interactive_type); |
| 290 | Py_CLEAR(astmodulestate(module)->Invert_singleton); |
| 291 | Py_CLEAR(astmodulestate(module)->Invert_type); |
| 292 | Py_CLEAR(astmodulestate(module)->IsNot_singleton); |
| 293 | Py_CLEAR(astmodulestate(module)->IsNot_type); |
| 294 | Py_CLEAR(astmodulestate(module)->Is_singleton); |
| 295 | Py_CLEAR(astmodulestate(module)->Is_type); |
| 296 | Py_CLEAR(astmodulestate(module)->JoinedStr_type); |
| 297 | Py_CLEAR(astmodulestate(module)->LShift_singleton); |
| 298 | Py_CLEAR(astmodulestate(module)->LShift_type); |
| 299 | Py_CLEAR(astmodulestate(module)->Lambda_type); |
| 300 | Py_CLEAR(astmodulestate(module)->ListComp_type); |
| 301 | Py_CLEAR(astmodulestate(module)->List_type); |
| 302 | Py_CLEAR(astmodulestate(module)->Load_singleton); |
| 303 | Py_CLEAR(astmodulestate(module)->Load_type); |
| 304 | Py_CLEAR(astmodulestate(module)->LtE_singleton); |
| 305 | Py_CLEAR(astmodulestate(module)->LtE_type); |
| 306 | Py_CLEAR(astmodulestate(module)->Lt_singleton); |
| 307 | Py_CLEAR(astmodulestate(module)->Lt_type); |
| 308 | Py_CLEAR(astmodulestate(module)->MatMult_singleton); |
| 309 | Py_CLEAR(astmodulestate(module)->MatMult_type); |
| 310 | Py_CLEAR(astmodulestate(module)->Mod_singleton); |
| 311 | Py_CLEAR(astmodulestate(module)->Mod_type); |
| 312 | Py_CLEAR(astmodulestate(module)->Module_type); |
| 313 | Py_CLEAR(astmodulestate(module)->Mult_singleton); |
| 314 | Py_CLEAR(astmodulestate(module)->Mult_type); |
| 315 | Py_CLEAR(astmodulestate(module)->Name_type); |
| 316 | Py_CLEAR(astmodulestate(module)->NamedExpr_type); |
| 317 | Py_CLEAR(astmodulestate(module)->Nonlocal_type); |
| 318 | Py_CLEAR(astmodulestate(module)->NotEq_singleton); |
| 319 | Py_CLEAR(astmodulestate(module)->NotEq_type); |
| 320 | Py_CLEAR(astmodulestate(module)->NotIn_singleton); |
| 321 | Py_CLEAR(astmodulestate(module)->NotIn_type); |
| 322 | Py_CLEAR(astmodulestate(module)->Not_singleton); |
| 323 | Py_CLEAR(astmodulestate(module)->Not_type); |
| 324 | Py_CLEAR(astmodulestate(module)->Or_singleton); |
| 325 | Py_CLEAR(astmodulestate(module)->Or_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 326 | Py_CLEAR(astmodulestate(module)->Pass_type); |
| 327 | Py_CLEAR(astmodulestate(module)->Pow_singleton); |
| 328 | Py_CLEAR(astmodulestate(module)->Pow_type); |
| 329 | Py_CLEAR(astmodulestate(module)->RShift_singleton); |
| 330 | Py_CLEAR(astmodulestate(module)->RShift_type); |
| 331 | Py_CLEAR(astmodulestate(module)->Raise_type); |
| 332 | Py_CLEAR(astmodulestate(module)->Return_type); |
| 333 | Py_CLEAR(astmodulestate(module)->SetComp_type); |
| 334 | Py_CLEAR(astmodulestate(module)->Set_type); |
| 335 | Py_CLEAR(astmodulestate(module)->Slice_type); |
| 336 | Py_CLEAR(astmodulestate(module)->Starred_type); |
| 337 | Py_CLEAR(astmodulestate(module)->Store_singleton); |
| 338 | Py_CLEAR(astmodulestate(module)->Store_type); |
| 339 | Py_CLEAR(astmodulestate(module)->Sub_singleton); |
| 340 | Py_CLEAR(astmodulestate(module)->Sub_type); |
| 341 | Py_CLEAR(astmodulestate(module)->Subscript_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 342 | Py_CLEAR(astmodulestate(module)->Try_type); |
| 343 | Py_CLEAR(astmodulestate(module)->Tuple_type); |
| 344 | Py_CLEAR(astmodulestate(module)->TypeIgnore_type); |
| 345 | Py_CLEAR(astmodulestate(module)->UAdd_singleton); |
| 346 | Py_CLEAR(astmodulestate(module)->UAdd_type); |
| 347 | Py_CLEAR(astmodulestate(module)->USub_singleton); |
| 348 | Py_CLEAR(astmodulestate(module)->USub_type); |
| 349 | Py_CLEAR(astmodulestate(module)->UnaryOp_type); |
| 350 | Py_CLEAR(astmodulestate(module)->While_type); |
| 351 | Py_CLEAR(astmodulestate(module)->With_type); |
| 352 | Py_CLEAR(astmodulestate(module)->YieldFrom_type); |
| 353 | Py_CLEAR(astmodulestate(module)->Yield_type); |
| 354 | Py_CLEAR(astmodulestate(module)->__dict__); |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 355 | Py_CLEAR(astmodulestate(module)->__doc__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 356 | Py_CLEAR(astmodulestate(module)->__module__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 357 | Py_CLEAR(astmodulestate(module)->_attributes); |
| 358 | Py_CLEAR(astmodulestate(module)->_fields); |
| 359 | Py_CLEAR(astmodulestate(module)->alias_type); |
| 360 | Py_CLEAR(astmodulestate(module)->annotation); |
| 361 | Py_CLEAR(astmodulestate(module)->arg); |
| 362 | Py_CLEAR(astmodulestate(module)->arg_type); |
| 363 | Py_CLEAR(astmodulestate(module)->args); |
| 364 | Py_CLEAR(astmodulestate(module)->argtypes); |
| 365 | Py_CLEAR(astmodulestate(module)->arguments_type); |
| 366 | Py_CLEAR(astmodulestate(module)->asname); |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 367 | Py_CLEAR(astmodulestate(module)->ast); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 368 | Py_CLEAR(astmodulestate(module)->attr); |
| 369 | Py_CLEAR(astmodulestate(module)->bases); |
| 370 | Py_CLEAR(astmodulestate(module)->body); |
| 371 | Py_CLEAR(astmodulestate(module)->boolop_type); |
| 372 | Py_CLEAR(astmodulestate(module)->cause); |
| 373 | Py_CLEAR(astmodulestate(module)->cmpop_type); |
| 374 | Py_CLEAR(astmodulestate(module)->col_offset); |
| 375 | Py_CLEAR(astmodulestate(module)->comparators); |
| 376 | Py_CLEAR(astmodulestate(module)->comprehension_type); |
| 377 | Py_CLEAR(astmodulestate(module)->context_expr); |
| 378 | Py_CLEAR(astmodulestate(module)->conversion); |
| 379 | Py_CLEAR(astmodulestate(module)->ctx); |
| 380 | Py_CLEAR(astmodulestate(module)->decorator_list); |
| 381 | Py_CLEAR(astmodulestate(module)->defaults); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 382 | Py_CLEAR(astmodulestate(module)->elt); |
| 383 | Py_CLEAR(astmodulestate(module)->elts); |
| 384 | Py_CLEAR(astmodulestate(module)->end_col_offset); |
| 385 | Py_CLEAR(astmodulestate(module)->end_lineno); |
| 386 | Py_CLEAR(astmodulestate(module)->exc); |
| 387 | Py_CLEAR(astmodulestate(module)->excepthandler_type); |
| 388 | Py_CLEAR(astmodulestate(module)->expr_context_type); |
| 389 | Py_CLEAR(astmodulestate(module)->expr_type); |
| 390 | Py_CLEAR(astmodulestate(module)->finalbody); |
| 391 | Py_CLEAR(astmodulestate(module)->format_spec); |
| 392 | Py_CLEAR(astmodulestate(module)->func); |
| 393 | Py_CLEAR(astmodulestate(module)->generators); |
| 394 | Py_CLEAR(astmodulestate(module)->handlers); |
| 395 | Py_CLEAR(astmodulestate(module)->id); |
| 396 | Py_CLEAR(astmodulestate(module)->ifs); |
| 397 | Py_CLEAR(astmodulestate(module)->is_async); |
| 398 | Py_CLEAR(astmodulestate(module)->items); |
| 399 | Py_CLEAR(astmodulestate(module)->iter); |
| 400 | Py_CLEAR(astmodulestate(module)->key); |
| 401 | Py_CLEAR(astmodulestate(module)->keys); |
| 402 | Py_CLEAR(astmodulestate(module)->keyword_type); |
| 403 | Py_CLEAR(astmodulestate(module)->keywords); |
| 404 | Py_CLEAR(astmodulestate(module)->kind); |
| 405 | Py_CLEAR(astmodulestate(module)->kw_defaults); |
| 406 | Py_CLEAR(astmodulestate(module)->kwarg); |
| 407 | Py_CLEAR(astmodulestate(module)->kwonlyargs); |
| 408 | Py_CLEAR(astmodulestate(module)->left); |
| 409 | Py_CLEAR(astmodulestate(module)->level); |
| 410 | Py_CLEAR(astmodulestate(module)->lineno); |
| 411 | Py_CLEAR(astmodulestate(module)->lower); |
| 412 | Py_CLEAR(astmodulestate(module)->mod_type); |
| 413 | Py_CLEAR(astmodulestate(module)->module); |
| 414 | Py_CLEAR(astmodulestate(module)->msg); |
| 415 | Py_CLEAR(astmodulestate(module)->name); |
| 416 | Py_CLEAR(astmodulestate(module)->names); |
| 417 | Py_CLEAR(astmodulestate(module)->op); |
| 418 | Py_CLEAR(astmodulestate(module)->operand); |
| 419 | Py_CLEAR(astmodulestate(module)->operator_type); |
| 420 | Py_CLEAR(astmodulestate(module)->ops); |
| 421 | Py_CLEAR(astmodulestate(module)->optional_vars); |
| 422 | Py_CLEAR(astmodulestate(module)->orelse); |
| 423 | Py_CLEAR(astmodulestate(module)->posonlyargs); |
| 424 | Py_CLEAR(astmodulestate(module)->returns); |
| 425 | Py_CLEAR(astmodulestate(module)->right); |
| 426 | Py_CLEAR(astmodulestate(module)->simple); |
| 427 | Py_CLEAR(astmodulestate(module)->slice); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 428 | Py_CLEAR(astmodulestate(module)->step); |
| 429 | Py_CLEAR(astmodulestate(module)->stmt_type); |
| 430 | Py_CLEAR(astmodulestate(module)->tag); |
| 431 | Py_CLEAR(astmodulestate(module)->target); |
| 432 | Py_CLEAR(astmodulestate(module)->targets); |
| 433 | Py_CLEAR(astmodulestate(module)->test); |
| 434 | Py_CLEAR(astmodulestate(module)->type); |
| 435 | Py_CLEAR(astmodulestate(module)->type_comment); |
| 436 | Py_CLEAR(astmodulestate(module)->type_ignore_type); |
| 437 | Py_CLEAR(astmodulestate(module)->type_ignores); |
| 438 | Py_CLEAR(astmodulestate(module)->unaryop_type); |
| 439 | Py_CLEAR(astmodulestate(module)->upper); |
| 440 | Py_CLEAR(astmodulestate(module)->value); |
| 441 | Py_CLEAR(astmodulestate(module)->values); |
| 442 | Py_CLEAR(astmodulestate(module)->vararg); |
| 443 | Py_CLEAR(astmodulestate(module)->withitem_type); |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static int astmodule_traverse(PyObject *module, visitproc visit, void* arg) |
| 449 | { |
| 450 | Py_VISIT(astmodulestate(module)->AST_type); |
| 451 | Py_VISIT(astmodulestate(module)->Add_singleton); |
| 452 | Py_VISIT(astmodulestate(module)->Add_type); |
| 453 | Py_VISIT(astmodulestate(module)->And_singleton); |
| 454 | Py_VISIT(astmodulestate(module)->And_type); |
| 455 | Py_VISIT(astmodulestate(module)->AnnAssign_type); |
| 456 | Py_VISIT(astmodulestate(module)->Assert_type); |
| 457 | Py_VISIT(astmodulestate(module)->Assign_type); |
| 458 | Py_VISIT(astmodulestate(module)->AsyncFor_type); |
| 459 | Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type); |
| 460 | Py_VISIT(astmodulestate(module)->AsyncWith_type); |
| 461 | Py_VISIT(astmodulestate(module)->Attribute_type); |
| 462 | Py_VISIT(astmodulestate(module)->AugAssign_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 463 | Py_VISIT(astmodulestate(module)->Await_type); |
| 464 | Py_VISIT(astmodulestate(module)->BinOp_type); |
| 465 | Py_VISIT(astmodulestate(module)->BitAnd_singleton); |
| 466 | Py_VISIT(astmodulestate(module)->BitAnd_type); |
| 467 | Py_VISIT(astmodulestate(module)->BitOr_singleton); |
| 468 | Py_VISIT(astmodulestate(module)->BitOr_type); |
| 469 | Py_VISIT(astmodulestate(module)->BitXor_singleton); |
| 470 | Py_VISIT(astmodulestate(module)->BitXor_type); |
| 471 | Py_VISIT(astmodulestate(module)->BoolOp_type); |
| 472 | Py_VISIT(astmodulestate(module)->Break_type); |
| 473 | Py_VISIT(astmodulestate(module)->Call_type); |
| 474 | Py_VISIT(astmodulestate(module)->ClassDef_type); |
| 475 | Py_VISIT(astmodulestate(module)->Compare_type); |
| 476 | Py_VISIT(astmodulestate(module)->Constant_type); |
| 477 | Py_VISIT(astmodulestate(module)->Continue_type); |
| 478 | Py_VISIT(astmodulestate(module)->Del_singleton); |
| 479 | Py_VISIT(astmodulestate(module)->Del_type); |
| 480 | Py_VISIT(astmodulestate(module)->Delete_type); |
| 481 | Py_VISIT(astmodulestate(module)->DictComp_type); |
| 482 | Py_VISIT(astmodulestate(module)->Dict_type); |
| 483 | Py_VISIT(astmodulestate(module)->Div_singleton); |
| 484 | Py_VISIT(astmodulestate(module)->Div_type); |
| 485 | Py_VISIT(astmodulestate(module)->Eq_singleton); |
| 486 | Py_VISIT(astmodulestate(module)->Eq_type); |
| 487 | Py_VISIT(astmodulestate(module)->ExceptHandler_type); |
| 488 | Py_VISIT(astmodulestate(module)->Expr_type); |
| 489 | Py_VISIT(astmodulestate(module)->Expression_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 490 | Py_VISIT(astmodulestate(module)->FloorDiv_singleton); |
| 491 | Py_VISIT(astmodulestate(module)->FloorDiv_type); |
| 492 | Py_VISIT(astmodulestate(module)->For_type); |
| 493 | Py_VISIT(astmodulestate(module)->FormattedValue_type); |
| 494 | Py_VISIT(astmodulestate(module)->FunctionDef_type); |
| 495 | Py_VISIT(astmodulestate(module)->FunctionType_type); |
| 496 | Py_VISIT(astmodulestate(module)->GeneratorExp_type); |
| 497 | Py_VISIT(astmodulestate(module)->Global_type); |
| 498 | Py_VISIT(astmodulestate(module)->GtE_singleton); |
| 499 | Py_VISIT(astmodulestate(module)->GtE_type); |
| 500 | Py_VISIT(astmodulestate(module)->Gt_singleton); |
| 501 | Py_VISIT(astmodulestate(module)->Gt_type); |
| 502 | Py_VISIT(astmodulestate(module)->IfExp_type); |
| 503 | Py_VISIT(astmodulestate(module)->If_type); |
| 504 | Py_VISIT(astmodulestate(module)->ImportFrom_type); |
| 505 | Py_VISIT(astmodulestate(module)->Import_type); |
| 506 | Py_VISIT(astmodulestate(module)->In_singleton); |
| 507 | Py_VISIT(astmodulestate(module)->In_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 508 | Py_VISIT(astmodulestate(module)->Interactive_type); |
| 509 | Py_VISIT(astmodulestate(module)->Invert_singleton); |
| 510 | Py_VISIT(astmodulestate(module)->Invert_type); |
| 511 | Py_VISIT(astmodulestate(module)->IsNot_singleton); |
| 512 | Py_VISIT(astmodulestate(module)->IsNot_type); |
| 513 | Py_VISIT(astmodulestate(module)->Is_singleton); |
| 514 | Py_VISIT(astmodulestate(module)->Is_type); |
| 515 | Py_VISIT(astmodulestate(module)->JoinedStr_type); |
| 516 | Py_VISIT(astmodulestate(module)->LShift_singleton); |
| 517 | Py_VISIT(astmodulestate(module)->LShift_type); |
| 518 | Py_VISIT(astmodulestate(module)->Lambda_type); |
| 519 | Py_VISIT(astmodulestate(module)->ListComp_type); |
| 520 | Py_VISIT(astmodulestate(module)->List_type); |
| 521 | Py_VISIT(astmodulestate(module)->Load_singleton); |
| 522 | Py_VISIT(astmodulestate(module)->Load_type); |
| 523 | Py_VISIT(astmodulestate(module)->LtE_singleton); |
| 524 | Py_VISIT(astmodulestate(module)->LtE_type); |
| 525 | Py_VISIT(astmodulestate(module)->Lt_singleton); |
| 526 | Py_VISIT(astmodulestate(module)->Lt_type); |
| 527 | Py_VISIT(astmodulestate(module)->MatMult_singleton); |
| 528 | Py_VISIT(astmodulestate(module)->MatMult_type); |
| 529 | Py_VISIT(astmodulestate(module)->Mod_singleton); |
| 530 | Py_VISIT(astmodulestate(module)->Mod_type); |
| 531 | Py_VISIT(astmodulestate(module)->Module_type); |
| 532 | Py_VISIT(astmodulestate(module)->Mult_singleton); |
| 533 | Py_VISIT(astmodulestate(module)->Mult_type); |
| 534 | Py_VISIT(astmodulestate(module)->Name_type); |
| 535 | Py_VISIT(astmodulestate(module)->NamedExpr_type); |
| 536 | Py_VISIT(astmodulestate(module)->Nonlocal_type); |
| 537 | Py_VISIT(astmodulestate(module)->NotEq_singleton); |
| 538 | Py_VISIT(astmodulestate(module)->NotEq_type); |
| 539 | Py_VISIT(astmodulestate(module)->NotIn_singleton); |
| 540 | Py_VISIT(astmodulestate(module)->NotIn_type); |
| 541 | Py_VISIT(astmodulestate(module)->Not_singleton); |
| 542 | Py_VISIT(astmodulestate(module)->Not_type); |
| 543 | Py_VISIT(astmodulestate(module)->Or_singleton); |
| 544 | Py_VISIT(astmodulestate(module)->Or_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 545 | Py_VISIT(astmodulestate(module)->Pass_type); |
| 546 | Py_VISIT(astmodulestate(module)->Pow_singleton); |
| 547 | Py_VISIT(astmodulestate(module)->Pow_type); |
| 548 | Py_VISIT(astmodulestate(module)->RShift_singleton); |
| 549 | Py_VISIT(astmodulestate(module)->RShift_type); |
| 550 | Py_VISIT(astmodulestate(module)->Raise_type); |
| 551 | Py_VISIT(astmodulestate(module)->Return_type); |
| 552 | Py_VISIT(astmodulestate(module)->SetComp_type); |
| 553 | Py_VISIT(astmodulestate(module)->Set_type); |
| 554 | Py_VISIT(astmodulestate(module)->Slice_type); |
| 555 | Py_VISIT(astmodulestate(module)->Starred_type); |
| 556 | Py_VISIT(astmodulestate(module)->Store_singleton); |
| 557 | Py_VISIT(astmodulestate(module)->Store_type); |
| 558 | Py_VISIT(astmodulestate(module)->Sub_singleton); |
| 559 | Py_VISIT(astmodulestate(module)->Sub_type); |
| 560 | Py_VISIT(astmodulestate(module)->Subscript_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 561 | Py_VISIT(astmodulestate(module)->Try_type); |
| 562 | Py_VISIT(astmodulestate(module)->Tuple_type); |
| 563 | Py_VISIT(astmodulestate(module)->TypeIgnore_type); |
| 564 | Py_VISIT(astmodulestate(module)->UAdd_singleton); |
| 565 | Py_VISIT(astmodulestate(module)->UAdd_type); |
| 566 | Py_VISIT(astmodulestate(module)->USub_singleton); |
| 567 | Py_VISIT(astmodulestate(module)->USub_type); |
| 568 | Py_VISIT(astmodulestate(module)->UnaryOp_type); |
| 569 | Py_VISIT(astmodulestate(module)->While_type); |
| 570 | Py_VISIT(astmodulestate(module)->With_type); |
| 571 | Py_VISIT(astmodulestate(module)->YieldFrom_type); |
| 572 | Py_VISIT(astmodulestate(module)->Yield_type); |
| 573 | Py_VISIT(astmodulestate(module)->__dict__); |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 574 | Py_VISIT(astmodulestate(module)->__doc__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 575 | Py_VISIT(astmodulestate(module)->__module__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 576 | Py_VISIT(astmodulestate(module)->_attributes); |
| 577 | Py_VISIT(astmodulestate(module)->_fields); |
| 578 | Py_VISIT(astmodulestate(module)->alias_type); |
| 579 | Py_VISIT(astmodulestate(module)->annotation); |
| 580 | Py_VISIT(astmodulestate(module)->arg); |
| 581 | Py_VISIT(astmodulestate(module)->arg_type); |
| 582 | Py_VISIT(astmodulestate(module)->args); |
| 583 | Py_VISIT(astmodulestate(module)->argtypes); |
| 584 | Py_VISIT(astmodulestate(module)->arguments_type); |
| 585 | Py_VISIT(astmodulestate(module)->asname); |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 586 | Py_VISIT(astmodulestate(module)->ast); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 587 | Py_VISIT(astmodulestate(module)->attr); |
| 588 | Py_VISIT(astmodulestate(module)->bases); |
| 589 | Py_VISIT(astmodulestate(module)->body); |
| 590 | Py_VISIT(astmodulestate(module)->boolop_type); |
| 591 | Py_VISIT(astmodulestate(module)->cause); |
| 592 | Py_VISIT(astmodulestate(module)->cmpop_type); |
| 593 | Py_VISIT(astmodulestate(module)->col_offset); |
| 594 | Py_VISIT(astmodulestate(module)->comparators); |
| 595 | Py_VISIT(astmodulestate(module)->comprehension_type); |
| 596 | Py_VISIT(astmodulestate(module)->context_expr); |
| 597 | Py_VISIT(astmodulestate(module)->conversion); |
| 598 | Py_VISIT(astmodulestate(module)->ctx); |
| 599 | Py_VISIT(astmodulestate(module)->decorator_list); |
| 600 | Py_VISIT(astmodulestate(module)->defaults); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 601 | Py_VISIT(astmodulestate(module)->elt); |
| 602 | Py_VISIT(astmodulestate(module)->elts); |
| 603 | Py_VISIT(astmodulestate(module)->end_col_offset); |
| 604 | Py_VISIT(astmodulestate(module)->end_lineno); |
| 605 | Py_VISIT(astmodulestate(module)->exc); |
| 606 | Py_VISIT(astmodulestate(module)->excepthandler_type); |
| 607 | Py_VISIT(astmodulestate(module)->expr_context_type); |
| 608 | Py_VISIT(astmodulestate(module)->expr_type); |
| 609 | Py_VISIT(astmodulestate(module)->finalbody); |
| 610 | Py_VISIT(astmodulestate(module)->format_spec); |
| 611 | Py_VISIT(astmodulestate(module)->func); |
| 612 | Py_VISIT(astmodulestate(module)->generators); |
| 613 | Py_VISIT(astmodulestate(module)->handlers); |
| 614 | Py_VISIT(astmodulestate(module)->id); |
| 615 | Py_VISIT(astmodulestate(module)->ifs); |
| 616 | Py_VISIT(astmodulestate(module)->is_async); |
| 617 | Py_VISIT(astmodulestate(module)->items); |
| 618 | Py_VISIT(astmodulestate(module)->iter); |
| 619 | Py_VISIT(astmodulestate(module)->key); |
| 620 | Py_VISIT(astmodulestate(module)->keys); |
| 621 | Py_VISIT(astmodulestate(module)->keyword_type); |
| 622 | Py_VISIT(astmodulestate(module)->keywords); |
| 623 | Py_VISIT(astmodulestate(module)->kind); |
| 624 | Py_VISIT(astmodulestate(module)->kw_defaults); |
| 625 | Py_VISIT(astmodulestate(module)->kwarg); |
| 626 | Py_VISIT(astmodulestate(module)->kwonlyargs); |
| 627 | Py_VISIT(astmodulestate(module)->left); |
| 628 | Py_VISIT(astmodulestate(module)->level); |
| 629 | Py_VISIT(astmodulestate(module)->lineno); |
| 630 | Py_VISIT(astmodulestate(module)->lower); |
| 631 | Py_VISIT(astmodulestate(module)->mod_type); |
| 632 | Py_VISIT(astmodulestate(module)->module); |
| 633 | Py_VISIT(astmodulestate(module)->msg); |
| 634 | Py_VISIT(astmodulestate(module)->name); |
| 635 | Py_VISIT(astmodulestate(module)->names); |
| 636 | Py_VISIT(astmodulestate(module)->op); |
| 637 | Py_VISIT(astmodulestate(module)->operand); |
| 638 | Py_VISIT(astmodulestate(module)->operator_type); |
| 639 | Py_VISIT(astmodulestate(module)->ops); |
| 640 | Py_VISIT(astmodulestate(module)->optional_vars); |
| 641 | Py_VISIT(astmodulestate(module)->orelse); |
| 642 | Py_VISIT(astmodulestate(module)->posonlyargs); |
| 643 | Py_VISIT(astmodulestate(module)->returns); |
| 644 | Py_VISIT(astmodulestate(module)->right); |
| 645 | Py_VISIT(astmodulestate(module)->simple); |
| 646 | Py_VISIT(astmodulestate(module)->slice); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 647 | Py_VISIT(astmodulestate(module)->step); |
| 648 | Py_VISIT(astmodulestate(module)->stmt_type); |
| 649 | Py_VISIT(astmodulestate(module)->tag); |
| 650 | Py_VISIT(astmodulestate(module)->target); |
| 651 | Py_VISIT(astmodulestate(module)->targets); |
| 652 | Py_VISIT(astmodulestate(module)->test); |
| 653 | Py_VISIT(astmodulestate(module)->type); |
| 654 | Py_VISIT(astmodulestate(module)->type_comment); |
| 655 | Py_VISIT(astmodulestate(module)->type_ignore_type); |
| 656 | Py_VISIT(astmodulestate(module)->type_ignores); |
| 657 | Py_VISIT(astmodulestate(module)->unaryop_type); |
| 658 | Py_VISIT(astmodulestate(module)->upper); |
| 659 | Py_VISIT(astmodulestate(module)->value); |
| 660 | Py_VISIT(astmodulestate(module)->values); |
| 661 | Py_VISIT(astmodulestate(module)->vararg); |
| 662 | Py_VISIT(astmodulestate(module)->withitem_type); |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static void astmodule_free(void* module) { |
| 668 | astmodule_clear((PyObject*)module); |
| 669 | } |
| 670 | |
| 671 | static struct PyModuleDef _astmodule = { |
| 672 | PyModuleDef_HEAD_INIT, |
| 673 | "_ast", |
| 674 | NULL, |
| 675 | sizeof(astmodulestate), |
| 676 | NULL, |
| 677 | NULL, |
| 678 | astmodule_traverse, |
| 679 | astmodule_clear, |
| 680 | astmodule_free, |
| 681 | }; |
| 682 | |
| 683 | #define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule))) |
| 684 | |
| 685 | static int init_identifiers(void) |
| 686 | { |
| 687 | astmodulestate *state = astmodulestate_global; |
| 688 | if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 689 | if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 690 | if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 691 | if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0; |
| 692 | if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0; |
| 693 | if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0; |
| 694 | if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0; |
| 695 | if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0; |
| 696 | if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0; |
| 697 | if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0; |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 698 | if ((state->ast = PyUnicode_InternFromString("ast")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 699 | if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0; |
| 700 | if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0; |
| 701 | if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0; |
| 702 | if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0; |
| 703 | if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0; |
| 704 | if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0; |
| 705 | if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0; |
| 706 | if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0; |
| 707 | if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0; |
| 708 | if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0; |
| 709 | if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 710 | if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0; |
| 711 | if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0; |
| 712 | if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0; |
| 713 | if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0; |
| 714 | if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0; |
| 715 | if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0; |
| 716 | if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0; |
| 717 | if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0; |
| 718 | if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0; |
| 719 | if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0; |
| 720 | if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0; |
| 721 | if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0; |
| 722 | if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0; |
| 723 | if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0; |
| 724 | if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0; |
| 725 | if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0; |
| 726 | if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0; |
| 727 | if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0; |
| 728 | if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0; |
| 729 | if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0; |
| 730 | if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0; |
| 731 | if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0; |
| 732 | if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0; |
| 733 | if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0; |
| 734 | if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0; |
| 735 | if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0; |
| 736 | if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0; |
| 737 | if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0; |
| 738 | if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0; |
| 739 | if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0; |
| 740 | if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0; |
| 741 | if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0; |
| 742 | if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0; |
| 743 | if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0; |
| 744 | if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0; |
| 745 | if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0; |
| 746 | if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0; |
| 747 | if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0; |
| 748 | if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0; |
| 749 | if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0; |
| 750 | if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0; |
| 751 | if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0; |
| 752 | if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0; |
| 753 | if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0; |
| 754 | if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0; |
| 755 | if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0; |
| 756 | if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0; |
| 757 | if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0; |
| 758 | if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0; |
| 759 | if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0; |
| 760 | if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0; |
| 761 | if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0; |
| 762 | return 1; |
| 763 | }; |
| 764 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 765 | static PyObject* ast2obj_mod(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 766 | static const char * const Module_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 767 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 768 | "type_ignores", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 769 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 770 | static const char * const Interactive_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 771 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 772 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 773 | static const char * const Expression_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 774 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 775 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 776 | static const char * const FunctionType_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 777 | "argtypes", |
| 778 | "returns", |
| 779 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 780 | static const char * const stmt_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 781 | "lineno", |
| 782 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 783 | "end_lineno", |
| 784 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 785 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 786 | static PyObject* ast2obj_stmt(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 787 | static const char * const FunctionDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 788 | "name", |
| 789 | "args", |
| 790 | "body", |
| 791 | "decorator_list", |
| 792 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 793 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 794 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 795 | static const char * const AsyncFunctionDef_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 796 | "name", |
| 797 | "args", |
| 798 | "body", |
| 799 | "decorator_list", |
| 800 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 801 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 802 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 803 | static const char * const ClassDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 804 | "name", |
| 805 | "bases", |
| 806 | "keywords", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 807 | "body", |
| 808 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 809 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 810 | static const char * const Return_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 811 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 812 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 813 | static const char * const Delete_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 814 | "targets", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 815 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 816 | static const char * const Assign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 817 | "targets", |
| 818 | "value", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 819 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 820 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 821 | static const char * const AugAssign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 822 | "target", |
| 823 | "op", |
| 824 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 825 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 826 | static const char * const AnnAssign_fields[]={ |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 827 | "target", |
| 828 | "annotation", |
| 829 | "value", |
| 830 | "simple", |
| 831 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 832 | static const char * const For_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 833 | "target", |
| 834 | "iter", |
| 835 | "body", |
| 836 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 837 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 838 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 839 | static const char * const AsyncFor_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 840 | "target", |
| 841 | "iter", |
| 842 | "body", |
| 843 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 844 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 845 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 846 | static const char * const While_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 847 | "test", |
| 848 | "body", |
| 849 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 850 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 851 | static const char * const If_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 852 | "test", |
| 853 | "body", |
| 854 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 855 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 856 | static const char * const With_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 857 | "items", |
| 858 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 859 | "type_comment", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 860 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 861 | static const char * const AsyncWith_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 862 | "items", |
| 863 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 864 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 865 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 866 | static const char * const Raise_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 867 | "exc", |
| 868 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 869 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 870 | static const char * const Try_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 871 | "body", |
| 872 | "handlers", |
| 873 | "orelse", |
| 874 | "finalbody", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 875 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 876 | static const char * const Assert_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 877 | "test", |
| 878 | "msg", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 879 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 880 | static const char * const Import_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 881 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 882 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 883 | static const char * const ImportFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 884 | "module", |
| 885 | "names", |
| 886 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 887 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 888 | static const char * const Global_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 889 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 890 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 891 | static const char * const Nonlocal_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 892 | "names", |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 893 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 894 | static const char * const Expr_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 895 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 896 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 897 | static const char * const expr_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 898 | "lineno", |
| 899 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 900 | "end_lineno", |
| 901 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 902 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 903 | static PyObject* ast2obj_expr(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 904 | static const char * const BoolOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 905 | "op", |
| 906 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 907 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 908 | static const char * const NamedExpr_fields[]={ |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 909 | "target", |
| 910 | "value", |
| 911 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 912 | static const char * const BinOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 913 | "left", |
| 914 | "op", |
| 915 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 916 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 917 | static const char * const UnaryOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 918 | "op", |
| 919 | "operand", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 920 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 921 | static const char * const Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 922 | "args", |
| 923 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 924 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 925 | static const char * const IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 926 | "test", |
| 927 | "body", |
| 928 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 929 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 930 | static const char * const Dict_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 931 | "keys", |
| 932 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 933 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 934 | static const char * const Set_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 935 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 936 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 937 | static const char * const ListComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 938 | "elt", |
| 939 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 940 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 941 | static const char * const SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 942 | "elt", |
| 943 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 944 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 945 | static const char * const DictComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 946 | "key", |
| 947 | "value", |
| 948 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 949 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 950 | static const char * const GeneratorExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 951 | "elt", |
| 952 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 953 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 954 | static const char * const Await_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 955 | "value", |
| 956 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 957 | static const char * const Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 958 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 959 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 960 | static const char * const YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 961 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 962 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 963 | static const char * const Compare_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 964 | "left", |
| 965 | "ops", |
| 966 | "comparators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 967 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 968 | static const char * const Call_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 969 | "func", |
| 970 | "args", |
| 971 | "keywords", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 972 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 973 | static const char * const FormattedValue_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 974 | "value", |
| 975 | "conversion", |
| 976 | "format_spec", |
| 977 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 978 | static const char * const JoinedStr_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 979 | "values", |
| 980 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 981 | static const char * const Constant_fields[]={ |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 982 | "value", |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 983 | "kind", |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 984 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 985 | static const char * const Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 986 | "value", |
| 987 | "attr", |
| 988 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 989 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 990 | static const char * const Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 991 | "value", |
| 992 | "slice", |
| 993 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 994 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 995 | static const char * const Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 996 | "value", |
| 997 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 998 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 999 | static const char * const Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1000 | "id", |
| 1001 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1002 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1003 | static const char * const List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1004 | "elts", |
| 1005 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1006 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1007 | static const char * const Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1008 | "elts", |
| 1009 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1010 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1011 | static const char * const Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1012 | "lower", |
| 1013 | "upper", |
| 1014 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1015 | }; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 1016 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1017 | static PyObject* ast2obj_boolop(boolop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1018 | static PyObject* ast2obj_operator(operator_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1019 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1020 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1021 | static PyObject* ast2obj_comprehension(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1022 | static const char * const comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1023 | "target", |
| 1024 | "iter", |
| 1025 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 1026 | "is_async", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1027 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1028 | static const char * const excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1029 | "lineno", |
| 1030 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1031 | "end_lineno", |
| 1032 | "end_col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1033 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1034 | static PyObject* ast2obj_excepthandler(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1035 | static const char * const ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1036 | "type", |
| 1037 | "name", |
| 1038 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1039 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1040 | static PyObject* ast2obj_arguments(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1041 | static const char * const arguments_fields[]={ |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 1042 | "posonlyargs", |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 1043 | "args", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1044 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1045 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1046 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1047 | "kwarg", |
| 1048 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1049 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1050 | static PyObject* ast2obj_arg(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1051 | static const char * const arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1052 | "lineno", |
| 1053 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1054 | "end_lineno", |
| 1055 | "end_col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1056 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1057 | static const char * const arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1058 | "arg", |
| 1059 | "annotation", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1060 | "type_comment", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1061 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1062 | static PyObject* ast2obj_keyword(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1063 | static const char * const keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1064 | "arg", |
| 1065 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1066 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1067 | static PyObject* ast2obj_alias(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1068 | static const char * const alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1069 | "name", |
| 1070 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1071 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1072 | static PyObject* ast2obj_withitem(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1073 | static const char * const withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1074 | "context_expr", |
| 1075 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1076 | }; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1077 | static PyObject* ast2obj_type_ignore(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1078 | static const char * const TypeIgnore_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1079 | "lineno", |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 1080 | "tag", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1081 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1082 | |
| 1083 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1084 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1085 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 1086 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1087 | PyObject *dict; |
| 1088 | } AST_object; |
| 1089 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1090 | static void |
| 1091 | ast_dealloc(AST_object *self) |
| 1092 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1093 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1094 | PyTypeObject *tp = Py_TYPE(self); |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1095 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1096 | Py_CLEAR(self->dict); |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1097 | freefunc free_func = PyType_GetSlot(tp, Py_tp_free); |
| 1098 | assert(free_func != NULL); |
| 1099 | free_func(self); |
| 1100 | Py_DECREF(tp); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1101 | } |
| 1102 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1103 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1104 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 1105 | { |
| 1106 | Py_VISIT(self->dict); |
| 1107 | return 0; |
| 1108 | } |
| 1109 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1110 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1111 | ast_clear(AST_object *self) |
| 1112 | { |
| 1113 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1114 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1118 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 1119 | { |
| 1120 | Py_ssize_t i, numfields = 0; |
| 1121 | int res = -1; |
| 1122 | PyObject *key, *value, *fields; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1123 | if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1124 | goto cleanup; |
| 1125 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1126 | if (fields) { |
| 1127 | numfields = PySequence_Size(fields); |
| 1128 | if (numfields == -1) |
| 1129 | goto cleanup; |
| 1130 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1131 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1132 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1133 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 1134 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 1135 | "%zd positional argument%s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1136 | _PyType_Name(Py_TYPE(self)), |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1137 | numfields, numfields == 1 ? "" : "s"); |
| 1138 | res = -1; |
| 1139 | goto cleanup; |
| 1140 | } |
| 1141 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 1142 | /* cannot be reached when fields is NULL */ |
| 1143 | PyObject *name = PySequence_GetItem(fields, i); |
| 1144 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1145 | res = -1; |
| 1146 | goto cleanup; |
| 1147 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1148 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 1149 | Py_DECREF(name); |
| 1150 | if (res < 0) |
| 1151 | goto cleanup; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1152 | } |
| 1153 | if (kw) { |
| 1154 | i = 0; /* needed by PyDict_Next */ |
| 1155 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 1156 | res = PyObject_SetAttr(self, key, value); |
| 1157 | if (res < 0) |
| 1158 | goto cleanup; |
| 1159 | } |
| 1160 | } |
| 1161 | cleanup: |
| 1162 | Py_XDECREF(fields); |
| 1163 | return res; |
| 1164 | } |
| 1165 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1166 | /* Pickling support */ |
| 1167 | static PyObject * |
| 1168 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 1169 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1170 | PyObject *dict; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1171 | if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1172 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1173 | } |
| 1174 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1175 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1176 | } |
| 1177 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 1178 | } |
| 1179 | |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1180 | static PyMemberDef ast_type_members[] = { |
| 1181 | {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY}, |
| 1182 | {NULL} /* Sentinel */ |
| 1183 | }; |
| 1184 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1185 | static PyMethodDef ast_type_methods[] = { |
| 1186 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 1187 | {NULL} |
| 1188 | }; |
| 1189 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1190 | static PyGetSetDef ast_type_getsets[] = { |
| 1191 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 1192 | {NULL} |
| 1193 | }; |
| 1194 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1195 | static PyType_Slot AST_type_slots[] = { |
| 1196 | {Py_tp_dealloc, ast_dealloc}, |
| 1197 | {Py_tp_getattro, PyObject_GenericGetAttr}, |
| 1198 | {Py_tp_setattro, PyObject_GenericSetAttr}, |
| 1199 | {Py_tp_traverse, ast_traverse}, |
| 1200 | {Py_tp_clear, ast_clear}, |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1201 | {Py_tp_members, ast_type_members}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1202 | {Py_tp_methods, ast_type_methods}, |
| 1203 | {Py_tp_getset, ast_type_getsets}, |
| 1204 | {Py_tp_init, ast_type_init}, |
| 1205 | {Py_tp_alloc, PyType_GenericAlloc}, |
| 1206 | {Py_tp_new, PyType_GenericNew}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1207 | {Py_tp_free, PyObject_GC_Del}, |
| 1208 | {0, 0}, |
| 1209 | }; |
| 1210 | |
| 1211 | static PyType_Spec AST_type_spec = { |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 1212 | "ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1213 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1214 | 0, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1215 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
| 1216 | AST_type_slots |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1217 | }; |
| 1218 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1219 | static PyObject * |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1220 | make_type(const char *type, PyObject* base, const char* const* fields, int num_fields, const char *doc) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1221 | { |
| 1222 | PyObject *fnames, *result; |
| 1223 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1224 | fnames = PyTuple_New(num_fields); |
| 1225 | if (!fnames) return NULL; |
| 1226 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1227 | PyObject *field = PyUnicode_InternFromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1228 | if (!field) { |
| 1229 | Py_DECREF(fnames); |
| 1230 | return NULL; |
| 1231 | } |
| 1232 | PyTuple_SET_ITEM(fnames, i, field); |
| 1233 | } |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1234 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOs}", |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1235 | type, base, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1236 | astmodulestate_global->_fields, fnames, |
| 1237 | astmodulestate_global->__module__, |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 1238 | astmodulestate_global->ast, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1239 | astmodulestate_global->__doc__, doc); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1240 | Py_DECREF(fnames); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1241 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1244 | static int |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1245 | 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] | 1246 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1247 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1248 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 1249 | if (!l) |
| 1250 | return 0; |
| 1251 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1252 | s = PyUnicode_InternFromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1253 | if (!s) { |
| 1254 | Py_DECREF(l); |
| 1255 | return 0; |
| 1256 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1257 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1258 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1259 | result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1260 | Py_DECREF(l); |
| 1261 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1264 | /* Conversion AST -> Python */ |
| 1265 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1266 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 1267 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 1268 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1269 | PyObject *result = PyList_New(n); |
| 1270 | PyObject *value; |
| 1271 | if (!result) |
| 1272 | return NULL; |
| 1273 | for (i = 0; i < n; i++) { |
| 1274 | value = func(asdl_seq_GET(seq, i)); |
| 1275 | if (!value) { |
| 1276 | Py_DECREF(result); |
| 1277 | return NULL; |
| 1278 | } |
| 1279 | PyList_SET_ITEM(result, i, value); |
| 1280 | } |
| 1281 | return result; |
| 1282 | } |
| 1283 | |
| 1284 | static PyObject* ast2obj_object(void *o) |
| 1285 | { |
| 1286 | if (!o) |
| 1287 | o = Py_None; |
| 1288 | Py_INCREF((PyObject*)o); |
| 1289 | return (PyObject*)o; |
| 1290 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 1291 | #define ast2obj_singleton ast2obj_object |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1292 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1293 | #define ast2obj_identifier ast2obj_object |
| 1294 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 1295 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1296 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1297 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1298 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 1299 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1302 | /* Conversion Python -> AST */ |
| 1303 | |
| 1304 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 1305 | { |
| 1306 | if (obj == Py_None) |
| 1307 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 1308 | if (obj) { |
| 1309 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1310 | *out = NULL; |
| 1311 | return -1; |
| 1312 | } |
| 1313 | Py_INCREF(obj); |
| 1314 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1315 | *out = obj; |
| 1316 | return 0; |
| 1317 | } |
| 1318 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1319 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 1320 | { |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1321 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1322 | *out = NULL; |
| 1323 | return -1; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1324 | } |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1325 | Py_INCREF(obj); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1326 | *out = obj; |
| 1327 | return 0; |
| 1328 | } |
| 1329 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1330 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1331 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1332 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 1333 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1334 | return 1; |
| 1335 | } |
| 1336 | return obj2ast_object(obj, out, arena); |
| 1337 | } |
| 1338 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1339 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 1340 | { |
| 1341 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
| 1342 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 1343 | return 1; |
| 1344 | } |
| 1345 | return obj2ast_object(obj, out, arena); |
| 1346 | } |
| 1347 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1348 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 1349 | { |
| 1350 | int i; |
| 1351 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 1352 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1353 | return 1; |
| 1354 | } |
| 1355 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 1356 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1357 | if (i == -1 && PyErr_Occurred()) |
| 1358 | return 1; |
| 1359 | *out = i; |
| 1360 | return 0; |
| 1361 | } |
| 1362 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 1363 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1364 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1365 | PyObject *empty_tuple; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1366 | empty_tuple = PyTuple_New(0); |
| 1367 | if (!empty_tuple || |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1368 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 || |
| 1369 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) { |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1370 | Py_XDECREF(empty_tuple); |
| 1371 | return -1; |
| 1372 | } |
| 1373 | Py_DECREF(empty_tuple); |
| 1374 | return 0; |
| 1375 | } |
| 1376 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1377 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1378 | static int init_types(void) |
| 1379 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1380 | PyObject *m; |
| 1381 | if (PyState_FindModule(&_astmodule) == NULL) { |
| 1382 | m = PyModule_Create(&_astmodule); |
| 1383 | if (!m) return 0; |
| 1384 | PyState_AddModule(m, &_astmodule); |
| 1385 | } |
| 1386 | astmodulestate *state = astmodulestate_global; |
| 1387 | if (state->initialized) return 1; |
| 1388 | if (init_identifiers() < 0) return 0; |
| 1389 | state->AST_type = PyType_FromSpec(&AST_type_spec); |
| 1390 | if (!state->AST_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1391 | if (add_ast_fields() < 0) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1392 | state->mod_type = make_type("mod", state->AST_type, NULL, 0, |
| 1393 | "mod = Module(stmt* body, type_ignore* type_ignores)\n" |
| 1394 | " | Interactive(stmt* body)\n" |
| 1395 | " | Expression(expr body)\n" |
| 1396 | " | FunctionType(expr* argtypes, expr returns)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1397 | if (!state->mod_type) return 0; |
| 1398 | if (!add_attributes(state->mod_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1399 | state->Module_type = make_type("Module", state->mod_type, Module_fields, 2, |
| 1400 | "Module(stmt* body, type_ignore* type_ignores)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1401 | if (!state->Module_type) return 0; |
| 1402 | state->Interactive_type = make_type("Interactive", state->mod_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1403 | Interactive_fields, 1, |
| 1404 | "Interactive(stmt* body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1405 | if (!state->Interactive_type) return 0; |
| 1406 | state->Expression_type = make_type("Expression", state->mod_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1407 | Expression_fields, 1, |
| 1408 | "Expression(expr body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1409 | if (!state->Expression_type) return 0; |
| 1410 | state->FunctionType_type = make_type("FunctionType", state->mod_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1411 | FunctionType_fields, 2, |
| 1412 | "FunctionType(expr* argtypes, expr returns)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1413 | if (!state->FunctionType_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1414 | state->stmt_type = make_type("stmt", state->AST_type, NULL, 0, |
| 1415 | "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" |
| 1416 | " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" |
| 1417 | " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n" |
| 1418 | " | Return(expr? value)\n" |
| 1419 | " | Delete(expr* targets)\n" |
| 1420 | " | Assign(expr* targets, expr value, string? type_comment)\n" |
| 1421 | " | AugAssign(expr target, operator op, expr value)\n" |
| 1422 | " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n" |
| 1423 | " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n" |
| 1424 | " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n" |
| 1425 | " | While(expr test, stmt* body, stmt* orelse)\n" |
| 1426 | " | If(expr test, stmt* body, stmt* orelse)\n" |
| 1427 | " | With(withitem* items, stmt* body, string? type_comment)\n" |
| 1428 | " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n" |
| 1429 | " | Raise(expr? exc, expr? cause)\n" |
| 1430 | " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n" |
| 1431 | " | Assert(expr test, expr? msg)\n" |
| 1432 | " | Import(alias* names)\n" |
| 1433 | " | ImportFrom(identifier? module, alias* names, int? level)\n" |
| 1434 | " | Global(identifier* names)\n" |
| 1435 | " | Nonlocal(identifier* names)\n" |
| 1436 | " | Expr(expr value)\n" |
| 1437 | " | Pass\n" |
| 1438 | " | Break\n" |
| 1439 | " | Continue"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1440 | if (!state->stmt_type) return 0; |
| 1441 | if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1442 | if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1) |
| 1443 | return 0; |
| 1444 | if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) == |
| 1445 | -1) |
| 1446 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1447 | state->FunctionDef_type = make_type("FunctionDef", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1448 | FunctionDef_fields, 6, |
| 1449 | "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1450 | if (!state->FunctionDef_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1451 | if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) == |
| 1452 | -1) |
| 1453 | return 0; |
| 1454 | if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None) |
| 1455 | == -1) |
| 1456 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1457 | state->AsyncFunctionDef_type = make_type("AsyncFunctionDef", |
| 1458 | state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1459 | AsyncFunctionDef_fields, 6, |
| 1460 | "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1461 | if (!state->AsyncFunctionDef_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1462 | if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None) |
| 1463 | == -1) |
| 1464 | return 0; |
| 1465 | if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment, |
| 1466 | Py_None) == -1) |
| 1467 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1468 | state->ClassDef_type = make_type("ClassDef", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1469 | ClassDef_fields, 5, |
| 1470 | "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1471 | if (!state->ClassDef_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1472 | state->Return_type = make_type("Return", state->stmt_type, Return_fields, 1, |
| 1473 | "Return(expr? value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1474 | if (!state->Return_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1475 | if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1) |
| 1476 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1477 | state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, 1, |
| 1478 | "Delete(expr* targets)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1479 | if (!state->Delete_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1480 | state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, 3, |
| 1481 | "Assign(expr* targets, expr value, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1482 | if (!state->Assign_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1483 | if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) == |
| 1484 | -1) |
| 1485 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1486 | state->AugAssign_type = make_type("AugAssign", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1487 | AugAssign_fields, 3, |
| 1488 | "AugAssign(expr target, operator op, expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1489 | if (!state->AugAssign_type) return 0; |
| 1490 | state->AnnAssign_type = make_type("AnnAssign", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1491 | AnnAssign_fields, 4, |
| 1492 | "AnnAssign(expr target, expr annotation, expr? value, int simple)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1493 | if (!state->AnnAssign_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1494 | if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1) |
| 1495 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1496 | state->For_type = make_type("For", state->stmt_type, For_fields, 5, |
| 1497 | "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1498 | if (!state->For_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1499 | if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1) |
| 1500 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1501 | state->AsyncFor_type = make_type("AsyncFor", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1502 | AsyncFor_fields, 5, |
| 1503 | "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1504 | if (!state->AsyncFor_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1505 | if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) == |
| 1506 | -1) |
| 1507 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1508 | state->While_type = make_type("While", state->stmt_type, While_fields, 3, |
| 1509 | "While(expr test, stmt* body, stmt* orelse)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1510 | if (!state->While_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1511 | state->If_type = make_type("If", state->stmt_type, If_fields, 3, |
| 1512 | "If(expr test, stmt* body, stmt* orelse)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1513 | if (!state->If_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1514 | state->With_type = make_type("With", state->stmt_type, With_fields, 3, |
| 1515 | "With(withitem* items, stmt* body, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1516 | if (!state->With_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1517 | if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1) |
| 1518 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1519 | state->AsyncWith_type = make_type("AsyncWith", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1520 | AsyncWith_fields, 3, |
| 1521 | "AsyncWith(withitem* items, stmt* body, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1522 | if (!state->AsyncWith_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1523 | if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None) |
| 1524 | == -1) |
| 1525 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1526 | state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2, |
| 1527 | "Raise(expr? exc, expr? cause)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1528 | if (!state->Raise_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1529 | if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1) |
| 1530 | return 0; |
| 1531 | if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1) |
| 1532 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1533 | state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4, |
| 1534 | "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1535 | if (!state->Try_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1536 | state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, 2, |
| 1537 | "Assert(expr test, expr? msg)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1538 | if (!state->Assert_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1539 | if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1) |
| 1540 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1541 | state->Import_type = make_type("Import", state->stmt_type, Import_fields, 1, |
| 1542 | "Import(alias* names)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1543 | if (!state->Import_type) return 0; |
| 1544 | state->ImportFrom_type = make_type("ImportFrom", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1545 | ImportFrom_fields, 3, |
| 1546 | "ImportFrom(identifier? module, alias* names, int? level)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1547 | if (!state->ImportFrom_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1548 | if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1) |
| 1549 | return 0; |
| 1550 | if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1) |
| 1551 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1552 | state->Global_type = make_type("Global", state->stmt_type, Global_fields, 1, |
| 1553 | "Global(identifier* names)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1554 | if (!state->Global_type) return 0; |
| 1555 | state->Nonlocal_type = make_type("Nonlocal", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1556 | Nonlocal_fields, 1, |
| 1557 | "Nonlocal(identifier* names)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1558 | if (!state->Nonlocal_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1559 | state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1, |
| 1560 | "Expr(expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1561 | if (!state->Expr_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1562 | state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0, |
| 1563 | "Pass"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1564 | if (!state->Pass_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1565 | state->Break_type = make_type("Break", state->stmt_type, NULL, 0, |
| 1566 | "Break"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1567 | if (!state->Break_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1568 | state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0, |
| 1569 | "Continue"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1570 | if (!state->Continue_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1571 | state->expr_type = make_type("expr", state->AST_type, NULL, 0, |
| 1572 | "expr = BoolOp(boolop op, expr* values)\n" |
| 1573 | " | NamedExpr(expr target, expr value)\n" |
| 1574 | " | BinOp(expr left, operator op, expr right)\n" |
| 1575 | " | UnaryOp(unaryop op, expr operand)\n" |
| 1576 | " | Lambda(arguments args, expr body)\n" |
| 1577 | " | IfExp(expr test, expr body, expr orelse)\n" |
| 1578 | " | Dict(expr* keys, expr* values)\n" |
| 1579 | " | Set(expr* elts)\n" |
| 1580 | " | ListComp(expr elt, comprehension* generators)\n" |
| 1581 | " | SetComp(expr elt, comprehension* generators)\n" |
| 1582 | " | DictComp(expr key, expr value, comprehension* generators)\n" |
| 1583 | " | GeneratorExp(expr elt, comprehension* generators)\n" |
| 1584 | " | Await(expr value)\n" |
| 1585 | " | Yield(expr? value)\n" |
| 1586 | " | YieldFrom(expr value)\n" |
| 1587 | " | Compare(expr left, cmpop* ops, expr* comparators)\n" |
| 1588 | " | Call(expr func, expr* args, keyword* keywords)\n" |
| 1589 | " | FormattedValue(expr value, int? conversion, expr? format_spec)\n" |
| 1590 | " | JoinedStr(expr* values)\n" |
| 1591 | " | Constant(constant value, string? kind)\n" |
| 1592 | " | Attribute(expr value, identifier attr, expr_context ctx)\n" |
| 1593 | " | Subscript(expr value, expr slice, expr_context ctx)\n" |
| 1594 | " | Starred(expr value, expr_context ctx)\n" |
| 1595 | " | Name(identifier id, expr_context ctx)\n" |
| 1596 | " | List(expr* elts, expr_context ctx)\n" |
| 1597 | " | Tuple(expr* elts, expr_context ctx)\n" |
| 1598 | " | Slice(expr? lower, expr? upper, expr? step)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1599 | if (!state->expr_type) return 0; |
| 1600 | if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1601 | if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1) |
| 1602 | return 0; |
| 1603 | if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) == |
| 1604 | -1) |
| 1605 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1606 | state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, 2, |
| 1607 | "BoolOp(boolop op, expr* values)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1608 | if (!state->BoolOp_type) return 0; |
| 1609 | state->NamedExpr_type = make_type("NamedExpr", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1610 | NamedExpr_fields, 2, |
| 1611 | "NamedExpr(expr target, expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1612 | if (!state->NamedExpr_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1613 | state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3, |
| 1614 | "BinOp(expr left, operator op, expr right)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1615 | if (!state->BinOp_type) return 0; |
| 1616 | state->UnaryOp_type = make_type("UnaryOp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1617 | UnaryOp_fields, 2, |
| 1618 | "UnaryOp(unaryop op, expr operand)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1619 | if (!state->UnaryOp_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1620 | state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, 2, |
| 1621 | "Lambda(arguments args, expr body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1622 | if (!state->Lambda_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1623 | state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3, |
| 1624 | "IfExp(expr test, expr body, expr orelse)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1625 | if (!state->IfExp_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1626 | state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2, |
| 1627 | "Dict(expr* keys, expr* values)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1628 | if (!state->Dict_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1629 | state->Set_type = make_type("Set", state->expr_type, Set_fields, 1, |
| 1630 | "Set(expr* elts)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1631 | if (!state->Set_type) return 0; |
| 1632 | state->ListComp_type = make_type("ListComp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1633 | ListComp_fields, 2, |
| 1634 | "ListComp(expr elt, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1635 | if (!state->ListComp_type) return 0; |
| 1636 | state->SetComp_type = make_type("SetComp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1637 | SetComp_fields, 2, |
| 1638 | "SetComp(expr elt, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1639 | if (!state->SetComp_type) return 0; |
| 1640 | state->DictComp_type = make_type("DictComp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1641 | DictComp_fields, 3, |
| 1642 | "DictComp(expr key, expr value, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1643 | if (!state->DictComp_type) return 0; |
| 1644 | state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1645 | GeneratorExp_fields, 2, |
| 1646 | "GeneratorExp(expr elt, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1647 | if (!state->GeneratorExp_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1648 | state->Await_type = make_type("Await", state->expr_type, Await_fields, 1, |
| 1649 | "Await(expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1650 | if (!state->Await_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1651 | state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1, |
| 1652 | "Yield(expr? value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1653 | if (!state->Yield_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1654 | if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1) |
| 1655 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1656 | state->YieldFrom_type = make_type("YieldFrom", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1657 | YieldFrom_fields, 1, |
| 1658 | "YieldFrom(expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1659 | if (!state->YieldFrom_type) return 0; |
| 1660 | state->Compare_type = make_type("Compare", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1661 | Compare_fields, 3, |
| 1662 | "Compare(expr left, cmpop* ops, expr* comparators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1663 | if (!state->Compare_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1664 | state->Call_type = make_type("Call", state->expr_type, Call_fields, 3, |
| 1665 | "Call(expr func, expr* args, keyword* keywords)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1666 | if (!state->Call_type) return 0; |
| 1667 | state->FormattedValue_type = make_type("FormattedValue", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1668 | FormattedValue_fields, 3, |
| 1669 | "FormattedValue(expr value, int? conversion, expr? format_spec)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1670 | if (!state->FormattedValue_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1671 | if (PyObject_SetAttr(state->FormattedValue_type, state->conversion, |
| 1672 | Py_None) == -1) |
| 1673 | return 0; |
| 1674 | if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec, |
| 1675 | Py_None) == -1) |
| 1676 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1677 | state->JoinedStr_type = make_type("JoinedStr", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1678 | JoinedStr_fields, 1, |
| 1679 | "JoinedStr(expr* values)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1680 | if (!state->JoinedStr_type) return 0; |
| 1681 | state->Constant_type = make_type("Constant", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1682 | Constant_fields, 2, |
| 1683 | "Constant(constant value, string? kind)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1684 | if (!state->Constant_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1685 | if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1) |
| 1686 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1687 | state->Attribute_type = make_type("Attribute", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1688 | Attribute_fields, 3, |
| 1689 | "Attribute(expr value, identifier attr, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1690 | if (!state->Attribute_type) return 0; |
| 1691 | state->Subscript_type = make_type("Subscript", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1692 | Subscript_fields, 3, |
| 1693 | "Subscript(expr value, expr slice, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1694 | if (!state->Subscript_type) return 0; |
| 1695 | state->Starred_type = make_type("Starred", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1696 | Starred_fields, 2, |
| 1697 | "Starred(expr value, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1698 | if (!state->Starred_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1699 | state->Name_type = make_type("Name", state->expr_type, Name_fields, 2, |
| 1700 | "Name(identifier id, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1701 | if (!state->Name_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1702 | state->List_type = make_type("List", state->expr_type, List_fields, 2, |
| 1703 | "List(expr* elts, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1704 | if (!state->List_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1705 | state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2, |
| 1706 | "Tuple(expr* elts, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1707 | if (!state->Tuple_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1708 | state->Slice_type = make_type("Slice", state->expr_type, Slice_fields, 3, |
| 1709 | "Slice(expr? lower, expr? upper, expr? step)"); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 1710 | if (!state->Slice_type) return 0; |
| 1711 | if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1) |
| 1712 | return 0; |
| 1713 | if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1) |
| 1714 | return 0; |
| 1715 | if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1) |
| 1716 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1717 | state->expr_context_type = make_type("expr_context", state->AST_type, NULL, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1718 | 0, |
Serhiy Storchaka | 6b97598 | 2020-03-17 23:41:08 +0200 | [diff] [blame] | 1719 | "expr_context = Load | Store | Del"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1720 | if (!state->expr_context_type) return 0; |
| 1721 | if (!add_attributes(state->expr_context_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1722 | state->Load_type = make_type("Load", state->expr_context_type, NULL, 0, |
| 1723 | "Load"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1724 | if (!state->Load_type) return 0; |
| 1725 | state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type, |
| 1726 | NULL, NULL); |
| 1727 | if (!state->Load_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1728 | state->Store_type = make_type("Store", state->expr_context_type, NULL, 0, |
| 1729 | "Store"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1730 | if (!state->Store_type) return 0; |
| 1731 | state->Store_singleton = PyType_GenericNew((PyTypeObject |
| 1732 | *)state->Store_type, NULL, NULL); |
| 1733 | if (!state->Store_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1734 | state->Del_type = make_type("Del", state->expr_context_type, NULL, 0, |
| 1735 | "Del"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1736 | if (!state->Del_type) return 0; |
| 1737 | state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type, |
| 1738 | NULL, NULL); |
| 1739 | if (!state->Del_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1740 | state->boolop_type = make_type("boolop", state->AST_type, NULL, 0, |
| 1741 | "boolop = And | Or"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1742 | if (!state->boolop_type) return 0; |
| 1743 | if (!add_attributes(state->boolop_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1744 | state->And_type = make_type("And", state->boolop_type, NULL, 0, |
| 1745 | "And"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1746 | if (!state->And_type) return 0; |
| 1747 | state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type, |
| 1748 | NULL, NULL); |
| 1749 | if (!state->And_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1750 | state->Or_type = make_type("Or", state->boolop_type, NULL, 0, |
| 1751 | "Or"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1752 | if (!state->Or_type) return 0; |
| 1753 | state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type, |
| 1754 | NULL, NULL); |
| 1755 | if (!state->Or_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1756 | state->operator_type = make_type("operator", state->AST_type, NULL, 0, |
| 1757 | "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1758 | if (!state->operator_type) return 0; |
| 1759 | if (!add_attributes(state->operator_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1760 | state->Add_type = make_type("Add", state->operator_type, NULL, 0, |
| 1761 | "Add"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1762 | if (!state->Add_type) return 0; |
| 1763 | state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type, |
| 1764 | NULL, NULL); |
| 1765 | if (!state->Add_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1766 | state->Sub_type = make_type("Sub", state->operator_type, NULL, 0, |
| 1767 | "Sub"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1768 | if (!state->Sub_type) return 0; |
| 1769 | state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type, |
| 1770 | NULL, NULL); |
| 1771 | if (!state->Sub_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1772 | state->Mult_type = make_type("Mult", state->operator_type, NULL, 0, |
| 1773 | "Mult"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1774 | if (!state->Mult_type) return 0; |
| 1775 | state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type, |
| 1776 | NULL, NULL); |
| 1777 | if (!state->Mult_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1778 | state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0, |
| 1779 | "MatMult"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1780 | if (!state->MatMult_type) return 0; |
| 1781 | state->MatMult_singleton = PyType_GenericNew((PyTypeObject |
| 1782 | *)state->MatMult_type, NULL, |
| 1783 | NULL); |
| 1784 | if (!state->MatMult_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1785 | state->Div_type = make_type("Div", state->operator_type, NULL, 0, |
| 1786 | "Div"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1787 | if (!state->Div_type) return 0; |
| 1788 | state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type, |
| 1789 | NULL, NULL); |
| 1790 | if (!state->Div_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1791 | state->Mod_type = make_type("Mod", state->operator_type, NULL, 0, |
| 1792 | "Mod"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1793 | if (!state->Mod_type) return 0; |
| 1794 | state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type, |
| 1795 | NULL, NULL); |
| 1796 | if (!state->Mod_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1797 | state->Pow_type = make_type("Pow", state->operator_type, NULL, 0, |
| 1798 | "Pow"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1799 | if (!state->Pow_type) return 0; |
| 1800 | state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type, |
| 1801 | NULL, NULL); |
| 1802 | if (!state->Pow_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1803 | state->LShift_type = make_type("LShift", state->operator_type, NULL, 0, |
| 1804 | "LShift"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1805 | if (!state->LShift_type) return 0; |
| 1806 | state->LShift_singleton = PyType_GenericNew((PyTypeObject |
| 1807 | *)state->LShift_type, NULL, |
| 1808 | NULL); |
| 1809 | if (!state->LShift_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1810 | state->RShift_type = make_type("RShift", state->operator_type, NULL, 0, |
| 1811 | "RShift"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1812 | if (!state->RShift_type) return 0; |
| 1813 | state->RShift_singleton = PyType_GenericNew((PyTypeObject |
| 1814 | *)state->RShift_type, NULL, |
| 1815 | NULL); |
| 1816 | if (!state->RShift_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1817 | state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0, |
| 1818 | "BitOr"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1819 | if (!state->BitOr_type) return 0; |
| 1820 | state->BitOr_singleton = PyType_GenericNew((PyTypeObject |
| 1821 | *)state->BitOr_type, NULL, NULL); |
| 1822 | if (!state->BitOr_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1823 | state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0, |
| 1824 | "BitXor"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1825 | if (!state->BitXor_type) return 0; |
| 1826 | state->BitXor_singleton = PyType_GenericNew((PyTypeObject |
| 1827 | *)state->BitXor_type, NULL, |
| 1828 | NULL); |
| 1829 | if (!state->BitXor_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1830 | state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0, |
| 1831 | "BitAnd"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1832 | if (!state->BitAnd_type) return 0; |
| 1833 | state->BitAnd_singleton = PyType_GenericNew((PyTypeObject |
| 1834 | *)state->BitAnd_type, NULL, |
| 1835 | NULL); |
| 1836 | if (!state->BitAnd_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1837 | state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0, |
| 1838 | "FloorDiv"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1839 | if (!state->FloorDiv_type) return 0; |
| 1840 | state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject |
| 1841 | *)state->FloorDiv_type, NULL, |
| 1842 | NULL); |
| 1843 | if (!state->FloorDiv_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1844 | state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0, |
| 1845 | "unaryop = Invert | Not | UAdd | USub"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1846 | if (!state->unaryop_type) return 0; |
| 1847 | if (!add_attributes(state->unaryop_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1848 | state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0, |
| 1849 | "Invert"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1850 | if (!state->Invert_type) return 0; |
| 1851 | state->Invert_singleton = PyType_GenericNew((PyTypeObject |
| 1852 | *)state->Invert_type, NULL, |
| 1853 | NULL); |
| 1854 | if (!state->Invert_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1855 | state->Not_type = make_type("Not", state->unaryop_type, NULL, 0, |
| 1856 | "Not"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1857 | if (!state->Not_type) return 0; |
| 1858 | state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type, |
| 1859 | NULL, NULL); |
| 1860 | if (!state->Not_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1861 | state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0, |
| 1862 | "UAdd"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1863 | if (!state->UAdd_type) return 0; |
| 1864 | state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type, |
| 1865 | NULL, NULL); |
| 1866 | if (!state->UAdd_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1867 | state->USub_type = make_type("USub", state->unaryop_type, NULL, 0, |
| 1868 | "USub"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1869 | if (!state->USub_type) return 0; |
| 1870 | state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type, |
| 1871 | NULL, NULL); |
| 1872 | if (!state->USub_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1873 | state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0, |
| 1874 | "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1875 | if (!state->cmpop_type) return 0; |
| 1876 | if (!add_attributes(state->cmpop_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1877 | state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0, |
| 1878 | "Eq"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1879 | if (!state->Eq_type) return 0; |
| 1880 | state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type, |
| 1881 | NULL, NULL); |
| 1882 | if (!state->Eq_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1883 | state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0, |
| 1884 | "NotEq"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1885 | if (!state->NotEq_type) return 0; |
| 1886 | state->NotEq_singleton = PyType_GenericNew((PyTypeObject |
| 1887 | *)state->NotEq_type, NULL, NULL); |
| 1888 | if (!state->NotEq_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1889 | state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0, |
| 1890 | "Lt"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1891 | if (!state->Lt_type) return 0; |
| 1892 | state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type, |
| 1893 | NULL, NULL); |
| 1894 | if (!state->Lt_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1895 | state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0, |
| 1896 | "LtE"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1897 | if (!state->LtE_type) return 0; |
| 1898 | state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type, |
| 1899 | NULL, NULL); |
| 1900 | if (!state->LtE_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1901 | state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0, |
| 1902 | "Gt"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1903 | if (!state->Gt_type) return 0; |
| 1904 | state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type, |
| 1905 | NULL, NULL); |
| 1906 | if (!state->Gt_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1907 | state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0, |
| 1908 | "GtE"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1909 | if (!state->GtE_type) return 0; |
| 1910 | state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type, |
| 1911 | NULL, NULL); |
| 1912 | if (!state->GtE_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1913 | state->Is_type = make_type("Is", state->cmpop_type, NULL, 0, |
| 1914 | "Is"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1915 | if (!state->Is_type) return 0; |
| 1916 | state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type, |
| 1917 | NULL, NULL); |
| 1918 | if (!state->Is_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1919 | state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0, |
| 1920 | "IsNot"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1921 | if (!state->IsNot_type) return 0; |
| 1922 | state->IsNot_singleton = PyType_GenericNew((PyTypeObject |
| 1923 | *)state->IsNot_type, NULL, NULL); |
| 1924 | if (!state->IsNot_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1925 | state->In_type = make_type("In", state->cmpop_type, NULL, 0, |
| 1926 | "In"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1927 | if (!state->In_type) return 0; |
| 1928 | state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type, |
| 1929 | NULL, NULL); |
| 1930 | if (!state->In_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1931 | state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0, |
| 1932 | "NotIn"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1933 | if (!state->NotIn_type) return 0; |
| 1934 | state->NotIn_singleton = PyType_GenericNew((PyTypeObject |
| 1935 | *)state->NotIn_type, NULL, NULL); |
| 1936 | if (!state->NotIn_singleton) return 0; |
| 1937 | state->comprehension_type = make_type("comprehension", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1938 | comprehension_fields, 4, |
| 1939 | "comprehension(expr target, expr iter, expr* ifs, int is_async)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1940 | if (!state->comprehension_type) return 0; |
| 1941 | if (!add_attributes(state->comprehension_type, NULL, 0)) return 0; |
| 1942 | state->excepthandler_type = make_type("excepthandler", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1943 | NULL, 0, |
| 1944 | "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1945 | if (!state->excepthandler_type) return 0; |
| 1946 | if (!add_attributes(state->excepthandler_type, excepthandler_attributes, |
| 1947 | 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1948 | if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None) |
| 1949 | == -1) |
| 1950 | return 0; |
| 1951 | if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset, |
| 1952 | Py_None) == -1) |
| 1953 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1954 | state->ExceptHandler_type = make_type("ExceptHandler", |
| 1955 | state->excepthandler_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1956 | ExceptHandler_fields, 3, |
| 1957 | "ExceptHandler(expr? type, identifier? name, stmt* body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1958 | if (!state->ExceptHandler_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1959 | if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1) |
| 1960 | return 0; |
| 1961 | if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1) |
| 1962 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1963 | state->arguments_type = make_type("arguments", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1964 | arguments_fields, 7, |
| 1965 | "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1966 | if (!state->arguments_type) return 0; |
| 1967 | if (!add_attributes(state->arguments_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1968 | if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1) |
| 1969 | return 0; |
| 1970 | if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1) |
| 1971 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1972 | state->arg_type = make_type("arg", state->AST_type, arg_fields, 3, |
| 1973 | "arg(identifier arg, expr? annotation, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1974 | if (!state->arg_type) return 0; |
| 1975 | if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1976 | if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1) |
| 1977 | return 0; |
| 1978 | if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1) |
| 1979 | return 0; |
| 1980 | if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1) |
| 1981 | return 0; |
| 1982 | if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1) |
| 1983 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1984 | state->keyword_type = make_type("keyword", state->AST_type, keyword_fields, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1985 | 2, |
| 1986 | "keyword(identifier? arg, expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1987 | if (!state->keyword_type) return 0; |
| 1988 | if (!add_attributes(state->keyword_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1989 | if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1) |
| 1990 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1991 | state->alias_type = make_type("alias", state->AST_type, alias_fields, 2, |
| 1992 | "alias(identifier name, identifier? asname)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1993 | if (!state->alias_type) return 0; |
| 1994 | if (!add_attributes(state->alias_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1995 | if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1) |
| 1996 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1997 | state->withitem_type = make_type("withitem", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1998 | withitem_fields, 2, |
| 1999 | "withitem(expr context_expr, expr? optional_vars)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2000 | if (!state->withitem_type) return 0; |
| 2001 | if (!add_attributes(state->withitem_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 2002 | if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None) |
| 2003 | == -1) |
| 2004 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2005 | state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, 0, |
| 2006 | "type_ignore = TypeIgnore(int lineno, string tag)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2007 | if (!state->type_ignore_type) return 0; |
| 2008 | if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0; |
| 2009 | state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2010 | TypeIgnore_fields, 2, |
| 2011 | "TypeIgnore(int lineno, string tag)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2012 | if (!state->TypeIgnore_type) return 0; |
| 2013 | state->initialized = 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2014 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2015 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2016 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2017 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 2018 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 2019 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 2020 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 2021 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2022 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 2023 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 2024 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 2025 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 2026 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 2027 | arena); |
| 2028 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 2029 | arena); |
| 2030 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 2031 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 2032 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 2033 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2034 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2035 | static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* |
| 2036 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2037 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2038 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2039 | Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2040 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2041 | mod_ty p; |
| 2042 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2043 | if (!p) |
| 2044 | return NULL; |
| 2045 | p->kind = Module_kind; |
| 2046 | p->v.Module.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2047 | p->v.Module.type_ignores = type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2048 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2049 | } |
| 2050 | |
| 2051 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2052 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2053 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2054 | mod_ty p; |
| 2055 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2056 | if (!p) |
| 2057 | return NULL; |
| 2058 | p->kind = Interactive_kind; |
| 2059 | p->v.Interactive.body = body; |
| 2060 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2064 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2065 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2066 | mod_ty p; |
| 2067 | if (!body) { |
| 2068 | PyErr_SetString(PyExc_ValueError, |
| 2069 | "field body is required for Expression"); |
| 2070 | return NULL; |
| 2071 | } |
| 2072 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2073 | if (!p) |
| 2074 | return NULL; |
| 2075 | p->kind = Expression_kind; |
| 2076 | p->v.Expression.body = body; |
| 2077 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2081 | FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena) |
| 2082 | { |
| 2083 | mod_ty p; |
| 2084 | if (!returns) { |
| 2085 | PyErr_SetString(PyExc_ValueError, |
| 2086 | "field returns is required for FunctionType"); |
| 2087 | return NULL; |
| 2088 | } |
| 2089 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2090 | if (!p) |
| 2091 | return NULL; |
| 2092 | p->kind = FunctionType_kind; |
| 2093 | p->v.FunctionType.argtypes = argtypes; |
| 2094 | p->v.FunctionType.returns = returns; |
| 2095 | return p; |
| 2096 | } |
| 2097 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2098 | stmt_ty |
| 2099 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2100 | decorator_list, expr_ty returns, string type_comment, int lineno, |
| 2101 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2102 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2103 | stmt_ty p; |
| 2104 | if (!name) { |
| 2105 | PyErr_SetString(PyExc_ValueError, |
| 2106 | "field name is required for FunctionDef"); |
| 2107 | return NULL; |
| 2108 | } |
| 2109 | if (!args) { |
| 2110 | PyErr_SetString(PyExc_ValueError, |
| 2111 | "field args is required for FunctionDef"); |
| 2112 | return NULL; |
| 2113 | } |
| 2114 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2115 | if (!p) |
| 2116 | return NULL; |
| 2117 | p->kind = FunctionDef_kind; |
| 2118 | p->v.FunctionDef.name = name; |
| 2119 | p->v.FunctionDef.args = args; |
| 2120 | p->v.FunctionDef.body = body; |
| 2121 | p->v.FunctionDef.decorator_list = decorator_list; |
| 2122 | p->v.FunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2123 | p->v.FunctionDef.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2124 | p->lineno = lineno; |
| 2125 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2126 | p->end_lineno = end_lineno; |
| 2127 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2128 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2132 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2133 | * decorator_list, expr_ty returns, string type_comment, int |
| 2134 | lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2135 | PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2136 | { |
| 2137 | stmt_ty p; |
| 2138 | if (!name) { |
| 2139 | PyErr_SetString(PyExc_ValueError, |
| 2140 | "field name is required for AsyncFunctionDef"); |
| 2141 | return NULL; |
| 2142 | } |
| 2143 | if (!args) { |
| 2144 | PyErr_SetString(PyExc_ValueError, |
| 2145 | "field args is required for AsyncFunctionDef"); |
| 2146 | return NULL; |
| 2147 | } |
| 2148 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2149 | if (!p) |
| 2150 | return NULL; |
| 2151 | p->kind = AsyncFunctionDef_kind; |
| 2152 | p->v.AsyncFunctionDef.name = name; |
| 2153 | p->v.AsyncFunctionDef.args = args; |
| 2154 | p->v.AsyncFunctionDef.body = body; |
| 2155 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 2156 | p->v.AsyncFunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2157 | p->v.AsyncFunctionDef.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2158 | p->lineno = lineno; |
| 2159 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2160 | p->end_lineno = end_lineno; |
| 2161 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2162 | return p; |
| 2163 | } |
| 2164 | |
| 2165 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2166 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2167 | body, asdl_seq * decorator_list, int lineno, int col_offset, int |
| 2168 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2169 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2170 | stmt_ty p; |
| 2171 | if (!name) { |
| 2172 | PyErr_SetString(PyExc_ValueError, |
| 2173 | "field name is required for ClassDef"); |
| 2174 | return NULL; |
| 2175 | } |
| 2176 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2177 | if (!p) |
| 2178 | return NULL; |
| 2179 | p->kind = ClassDef_kind; |
| 2180 | p->v.ClassDef.name = name; |
| 2181 | p->v.ClassDef.bases = bases; |
| 2182 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2183 | p->v.ClassDef.body = body; |
| 2184 | p->v.ClassDef.decorator_list = decorator_list; |
| 2185 | p->lineno = lineno; |
| 2186 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2187 | p->end_lineno = end_lineno; |
| 2188 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2189 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2193 | Return(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2194 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2195 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2196 | stmt_ty p; |
| 2197 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2198 | if (!p) |
| 2199 | return NULL; |
| 2200 | p->kind = Return_kind; |
| 2201 | p->v.Return.value = value; |
| 2202 | p->lineno = lineno; |
| 2203 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2204 | p->end_lineno = end_lineno; |
| 2205 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2206 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2210 | Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int |
| 2211 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2212 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2213 | stmt_ty p; |
| 2214 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2215 | if (!p) |
| 2216 | return NULL; |
| 2217 | p->kind = Delete_kind; |
| 2218 | p->v.Delete.targets = targets; |
| 2219 | p->lineno = lineno; |
| 2220 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2221 | p->end_lineno = end_lineno; |
| 2222 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2223 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2227 | Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int |
| 2228 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2229 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2230 | stmt_ty p; |
| 2231 | if (!value) { |
| 2232 | PyErr_SetString(PyExc_ValueError, |
| 2233 | "field value is required for Assign"); |
| 2234 | return NULL; |
| 2235 | } |
| 2236 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2237 | if (!p) |
| 2238 | return NULL; |
| 2239 | p->kind = Assign_kind; |
| 2240 | p->v.Assign.targets = targets; |
| 2241 | p->v.Assign.value = value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2242 | p->v.Assign.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2243 | p->lineno = lineno; |
| 2244 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2245 | p->end_lineno = end_lineno; |
| 2246 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2247 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2251 | 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] | 2252 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2253 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2254 | stmt_ty p; |
| 2255 | if (!target) { |
| 2256 | PyErr_SetString(PyExc_ValueError, |
| 2257 | "field target is required for AugAssign"); |
| 2258 | return NULL; |
| 2259 | } |
| 2260 | if (!op) { |
| 2261 | PyErr_SetString(PyExc_ValueError, |
| 2262 | "field op is required for AugAssign"); |
| 2263 | return NULL; |
| 2264 | } |
| 2265 | if (!value) { |
| 2266 | PyErr_SetString(PyExc_ValueError, |
| 2267 | "field value is required for AugAssign"); |
| 2268 | return NULL; |
| 2269 | } |
| 2270 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2271 | if (!p) |
| 2272 | return NULL; |
| 2273 | p->kind = AugAssign_kind; |
| 2274 | p->v.AugAssign.target = target; |
| 2275 | p->v.AugAssign.op = op; |
| 2276 | p->v.AugAssign.value = value; |
| 2277 | p->lineno = lineno; |
| 2278 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2279 | p->end_lineno = end_lineno; |
| 2280 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2281 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2285 | 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] | 2286 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2287 | *arena) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2288 | { |
| 2289 | stmt_ty p; |
| 2290 | if (!target) { |
| 2291 | PyErr_SetString(PyExc_ValueError, |
| 2292 | "field target is required for AnnAssign"); |
| 2293 | return NULL; |
| 2294 | } |
| 2295 | if (!annotation) { |
| 2296 | PyErr_SetString(PyExc_ValueError, |
| 2297 | "field annotation is required for AnnAssign"); |
| 2298 | return NULL; |
| 2299 | } |
| 2300 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2301 | if (!p) |
| 2302 | return NULL; |
| 2303 | p->kind = AnnAssign_kind; |
| 2304 | p->v.AnnAssign.target = target; |
| 2305 | p->v.AnnAssign.annotation = annotation; |
| 2306 | p->v.AnnAssign.value = value; |
| 2307 | p->v.AnnAssign.simple = simple; |
| 2308 | p->lineno = lineno; |
| 2309 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2310 | p->end_lineno = end_lineno; |
| 2311 | p->end_col_offset = end_col_offset; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2312 | return p; |
| 2313 | } |
| 2314 | |
| 2315 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2316 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string |
| 2317 | type_comment, int lineno, int col_offset, int end_lineno, int |
| 2318 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2319 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2320 | stmt_ty p; |
| 2321 | if (!target) { |
| 2322 | PyErr_SetString(PyExc_ValueError, |
| 2323 | "field target is required for For"); |
| 2324 | return NULL; |
| 2325 | } |
| 2326 | if (!iter) { |
| 2327 | PyErr_SetString(PyExc_ValueError, |
| 2328 | "field iter is required for For"); |
| 2329 | return NULL; |
| 2330 | } |
| 2331 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2332 | if (!p) |
| 2333 | return NULL; |
| 2334 | p->kind = For_kind; |
| 2335 | p->v.For.target = target; |
| 2336 | p->v.For.iter = iter; |
| 2337 | p->v.For.body = body; |
| 2338 | p->v.For.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2339 | p->v.For.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2340 | p->lineno = lineno; |
| 2341 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2342 | p->end_lineno = end_lineno; |
| 2343 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2344 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2348 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, |
| 2349 | string type_comment, int lineno, int col_offset, int end_lineno, int |
| 2350 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2351 | { |
| 2352 | stmt_ty p; |
| 2353 | if (!target) { |
| 2354 | PyErr_SetString(PyExc_ValueError, |
| 2355 | "field target is required for AsyncFor"); |
| 2356 | return NULL; |
| 2357 | } |
| 2358 | if (!iter) { |
| 2359 | PyErr_SetString(PyExc_ValueError, |
| 2360 | "field iter is required for AsyncFor"); |
| 2361 | return NULL; |
| 2362 | } |
| 2363 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2364 | if (!p) |
| 2365 | return NULL; |
| 2366 | p->kind = AsyncFor_kind; |
| 2367 | p->v.AsyncFor.target = target; |
| 2368 | p->v.AsyncFor.iter = iter; |
| 2369 | p->v.AsyncFor.body = body; |
| 2370 | p->v.AsyncFor.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2371 | p->v.AsyncFor.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2372 | p->lineno = lineno; |
| 2373 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2374 | p->end_lineno = end_lineno; |
| 2375 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2376 | return p; |
| 2377 | } |
| 2378 | |
| 2379 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2380 | 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] | 2381 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2382 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2383 | stmt_ty p; |
| 2384 | if (!test) { |
| 2385 | PyErr_SetString(PyExc_ValueError, |
| 2386 | "field test is required for While"); |
| 2387 | return NULL; |
| 2388 | } |
| 2389 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2390 | if (!p) |
| 2391 | return NULL; |
| 2392 | p->kind = While_kind; |
| 2393 | p->v.While.test = test; |
| 2394 | p->v.While.body = body; |
| 2395 | p->v.While.orelse = orelse; |
| 2396 | p->lineno = lineno; |
| 2397 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2398 | p->end_lineno = end_lineno; |
| 2399 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2400 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2404 | 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] | 2405 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2406 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2407 | stmt_ty p; |
| 2408 | if (!test) { |
| 2409 | PyErr_SetString(PyExc_ValueError, |
| 2410 | "field test is required for If"); |
| 2411 | return NULL; |
| 2412 | } |
| 2413 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2414 | if (!p) |
| 2415 | return NULL; |
| 2416 | p->kind = If_kind; |
| 2417 | p->v.If.test = test; |
| 2418 | p->v.If.body = body; |
| 2419 | p->v.If.orelse = orelse; |
| 2420 | p->lineno = lineno; |
| 2421 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2422 | p->end_lineno = end_lineno; |
| 2423 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2424 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2428 | With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int |
| 2429 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2430 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2431 | stmt_ty p; |
| 2432 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2433 | if (!p) |
| 2434 | return NULL; |
| 2435 | p->kind = With_kind; |
| 2436 | p->v.With.items = items; |
| 2437 | p->v.With.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2438 | p->v.With.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2439 | p->lineno = lineno; |
| 2440 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2441 | p->end_lineno = end_lineno; |
| 2442 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2443 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2447 | AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, |
| 2448 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2449 | { |
| 2450 | stmt_ty p; |
| 2451 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2452 | if (!p) |
| 2453 | return NULL; |
| 2454 | p->kind = AsyncWith_kind; |
| 2455 | p->v.AsyncWith.items = items; |
| 2456 | p->v.AsyncWith.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2457 | p->v.AsyncWith.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2458 | p->lineno = lineno; |
| 2459 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2460 | p->end_lineno = end_lineno; |
| 2461 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2462 | return p; |
| 2463 | } |
| 2464 | |
| 2465 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2466 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, |
| 2467 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2468 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2469 | stmt_ty p; |
| 2470 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2471 | if (!p) |
| 2472 | return NULL; |
| 2473 | p->kind = Raise_kind; |
| 2474 | p->v.Raise.exc = exc; |
| 2475 | p->v.Raise.cause = cause; |
| 2476 | p->lineno = lineno; |
| 2477 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2478 | p->end_lineno = end_lineno; |
| 2479 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2480 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2484 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2485 | finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2486 | 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 | stmt_ty p; |
| 2489 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2490 | if (!p) |
| 2491 | return NULL; |
| 2492 | p->kind = Try_kind; |
| 2493 | p->v.Try.body = body; |
| 2494 | p->v.Try.handlers = handlers; |
| 2495 | p->v.Try.orelse = orelse; |
| 2496 | p->v.Try.finalbody = finalbody; |
| 2497 | p->lineno = lineno; |
| 2498 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2499 | p->end_lineno = end_lineno; |
| 2500 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2501 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2505 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, |
| 2506 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2507 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2508 | stmt_ty p; |
| 2509 | if (!test) { |
| 2510 | PyErr_SetString(PyExc_ValueError, |
| 2511 | "field test is required for Assert"); |
| 2512 | return NULL; |
| 2513 | } |
| 2514 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2515 | if (!p) |
| 2516 | return NULL; |
| 2517 | p->kind = Assert_kind; |
| 2518 | p->v.Assert.test = test; |
| 2519 | p->v.Assert.msg = msg; |
| 2520 | p->lineno = lineno; |
| 2521 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2522 | p->end_lineno = end_lineno; |
| 2523 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2524 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2525 | } |
| 2526 | |
| 2527 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2528 | Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2529 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2530 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2531 | stmt_ty p; |
| 2532 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2533 | if (!p) |
| 2534 | return NULL; |
| 2535 | p->kind = Import_kind; |
| 2536 | p->v.Import.names = names; |
| 2537 | p->lineno = lineno; |
| 2538 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2539 | p->end_lineno = end_lineno; |
| 2540 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2541 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2545 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2546 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2547 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2548 | stmt_ty p; |
| 2549 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2550 | if (!p) |
| 2551 | return NULL; |
| 2552 | p->kind = ImportFrom_kind; |
| 2553 | p->v.ImportFrom.module = module; |
| 2554 | p->v.ImportFrom.names = names; |
| 2555 | p->v.ImportFrom.level = level; |
| 2556 | p->lineno = lineno; |
| 2557 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2558 | p->end_lineno = end_lineno; |
| 2559 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2560 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2561 | } |
| 2562 | |
| 2563 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2564 | Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2565 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2566 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2567 | stmt_ty p; |
| 2568 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2569 | if (!p) |
| 2570 | return NULL; |
| 2571 | p->kind = Global_kind; |
| 2572 | p->v.Global.names = names; |
| 2573 | p->lineno = lineno; |
| 2574 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2575 | p->end_lineno = end_lineno; |
| 2576 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2577 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2581 | Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2582 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2583 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2584 | stmt_ty p; |
| 2585 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2586 | if (!p) |
| 2587 | return NULL; |
| 2588 | p->kind = Nonlocal_kind; |
| 2589 | p->v.Nonlocal.names = names; |
| 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 | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2595 | } |
| 2596 | |
| 2597 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2598 | Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2599 | 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 | stmt_ty p; |
| 2602 | if (!value) { |
| 2603 | PyErr_SetString(PyExc_ValueError, |
| 2604 | "field value is required for Expr"); |
| 2605 | return NULL; |
| 2606 | } |
| 2607 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2608 | if (!p) |
| 2609 | return NULL; |
| 2610 | p->kind = Expr_kind; |
| 2611 | p->v.Expr.value = value; |
| 2612 | p->lineno = lineno; |
| 2613 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2614 | p->end_lineno = end_lineno; |
| 2615 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2616 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2620 | Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2621 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2622 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2623 | stmt_ty p; |
| 2624 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2625 | if (!p) |
| 2626 | return NULL; |
| 2627 | p->kind = Pass_kind; |
| 2628 | p->lineno = lineno; |
| 2629 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2630 | p->end_lineno = end_lineno; |
| 2631 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2632 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2633 | } |
| 2634 | |
| 2635 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2636 | Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2637 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2638 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2639 | stmt_ty p; |
| 2640 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2641 | if (!p) |
| 2642 | return NULL; |
| 2643 | p->kind = Break_kind; |
| 2644 | p->lineno = lineno; |
| 2645 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2646 | p->end_lineno = end_lineno; |
| 2647 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2648 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2649 | } |
| 2650 | |
| 2651 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2652 | Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2653 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2654 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2655 | stmt_ty p; |
| 2656 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2657 | if (!p) |
| 2658 | return NULL; |
| 2659 | p->kind = Continue_kind; |
| 2660 | p->lineno = lineno; |
| 2661 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2662 | p->end_lineno = end_lineno; |
| 2663 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2664 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2668 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int |
| 2669 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2670 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2671 | expr_ty p; |
| 2672 | if (!op) { |
| 2673 | PyErr_SetString(PyExc_ValueError, |
| 2674 | "field op is required for BoolOp"); |
| 2675 | return NULL; |
| 2676 | } |
| 2677 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2678 | if (!p) |
| 2679 | return NULL; |
| 2680 | p->kind = BoolOp_kind; |
| 2681 | p->v.BoolOp.op = op; |
| 2682 | p->v.BoolOp.values = values; |
| 2683 | p->lineno = lineno; |
| 2684 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2685 | p->end_lineno = end_lineno; |
| 2686 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2687 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | expr_ty |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2691 | NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int |
| 2692 | end_lineno, int end_col_offset, PyArena *arena) |
| 2693 | { |
| 2694 | expr_ty p; |
| 2695 | if (!target) { |
| 2696 | PyErr_SetString(PyExc_ValueError, |
| 2697 | "field target is required for NamedExpr"); |
| 2698 | return NULL; |
| 2699 | } |
| 2700 | if (!value) { |
| 2701 | PyErr_SetString(PyExc_ValueError, |
| 2702 | "field value is required for NamedExpr"); |
| 2703 | return NULL; |
| 2704 | } |
| 2705 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2706 | if (!p) |
| 2707 | return NULL; |
| 2708 | p->kind = NamedExpr_kind; |
| 2709 | p->v.NamedExpr.target = target; |
| 2710 | p->v.NamedExpr.value = value; |
| 2711 | p->lineno = lineno; |
| 2712 | p->col_offset = col_offset; |
| 2713 | p->end_lineno = end_lineno; |
| 2714 | p->end_col_offset = end_col_offset; |
| 2715 | return p; |
| 2716 | } |
| 2717 | |
| 2718 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2719 | 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] | 2720 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2721 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2722 | expr_ty p; |
| 2723 | if (!left) { |
| 2724 | PyErr_SetString(PyExc_ValueError, |
| 2725 | "field left is required for BinOp"); |
| 2726 | return NULL; |
| 2727 | } |
| 2728 | if (!op) { |
| 2729 | PyErr_SetString(PyExc_ValueError, |
| 2730 | "field op is required for BinOp"); |
| 2731 | return NULL; |
| 2732 | } |
| 2733 | if (!right) { |
| 2734 | PyErr_SetString(PyExc_ValueError, |
| 2735 | "field right is required for BinOp"); |
| 2736 | return NULL; |
| 2737 | } |
| 2738 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2739 | if (!p) |
| 2740 | return NULL; |
| 2741 | p->kind = BinOp_kind; |
| 2742 | p->v.BinOp.left = left; |
| 2743 | p->v.BinOp.op = op; |
| 2744 | p->v.BinOp.right = right; |
| 2745 | p->lineno = lineno; |
| 2746 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2747 | p->end_lineno = end_lineno; |
| 2748 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2749 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2750 | } |
| 2751 | |
| 2752 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2753 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int |
| 2754 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2755 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2756 | expr_ty p; |
| 2757 | if (!op) { |
| 2758 | PyErr_SetString(PyExc_ValueError, |
| 2759 | "field op is required for UnaryOp"); |
| 2760 | return NULL; |
| 2761 | } |
| 2762 | if (!operand) { |
| 2763 | PyErr_SetString(PyExc_ValueError, |
| 2764 | "field operand is required for UnaryOp"); |
| 2765 | return NULL; |
| 2766 | } |
| 2767 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2768 | if (!p) |
| 2769 | return NULL; |
| 2770 | p->kind = UnaryOp_kind; |
| 2771 | p->v.UnaryOp.op = op; |
| 2772 | p->v.UnaryOp.operand = operand; |
| 2773 | p->lineno = lineno; |
| 2774 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2775 | p->end_lineno = end_lineno; |
| 2776 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2777 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2778 | } |
| 2779 | |
| 2780 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2781 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int |
| 2782 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2783 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2784 | expr_ty p; |
| 2785 | if (!args) { |
| 2786 | PyErr_SetString(PyExc_ValueError, |
| 2787 | "field args is required for Lambda"); |
| 2788 | return NULL; |
| 2789 | } |
| 2790 | if (!body) { |
| 2791 | PyErr_SetString(PyExc_ValueError, |
| 2792 | "field body is required for Lambda"); |
| 2793 | return NULL; |
| 2794 | } |
| 2795 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2796 | if (!p) |
| 2797 | return NULL; |
| 2798 | p->kind = Lambda_kind; |
| 2799 | p->v.Lambda.args = args; |
| 2800 | p->v.Lambda.body = body; |
| 2801 | p->lineno = lineno; |
| 2802 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2803 | p->end_lineno = end_lineno; |
| 2804 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2805 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2806 | } |
| 2807 | |
| 2808 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2809 | 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] | 2810 | int end_lineno, int end_col_offset, PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2811 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2812 | expr_ty p; |
| 2813 | if (!test) { |
| 2814 | PyErr_SetString(PyExc_ValueError, |
| 2815 | "field test is required for IfExp"); |
| 2816 | return NULL; |
| 2817 | } |
| 2818 | if (!body) { |
| 2819 | PyErr_SetString(PyExc_ValueError, |
| 2820 | "field body is required for IfExp"); |
| 2821 | return NULL; |
| 2822 | } |
| 2823 | if (!orelse) { |
| 2824 | PyErr_SetString(PyExc_ValueError, |
| 2825 | "field orelse is required for IfExp"); |
| 2826 | return NULL; |
| 2827 | } |
| 2828 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2829 | if (!p) |
| 2830 | return NULL; |
| 2831 | p->kind = IfExp_kind; |
| 2832 | p->v.IfExp.test = test; |
| 2833 | p->v.IfExp.body = body; |
| 2834 | p->v.IfExp.orelse = orelse; |
| 2835 | p->lineno = lineno; |
| 2836 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2837 | p->end_lineno = end_lineno; |
| 2838 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2839 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2843 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int |
| 2844 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2845 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2846 | expr_ty p; |
| 2847 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2848 | if (!p) |
| 2849 | return NULL; |
| 2850 | p->kind = Dict_kind; |
| 2851 | p->v.Dict.keys = keys; |
| 2852 | p->v.Dict.values = values; |
| 2853 | p->lineno = lineno; |
| 2854 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2855 | p->end_lineno = end_lineno; |
| 2856 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2857 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2858 | } |
| 2859 | |
| 2860 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2861 | Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int |
| 2862 | end_col_offset, PyArena *arena) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2863 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2864 | expr_ty p; |
| 2865 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2866 | if (!p) |
| 2867 | return NULL; |
| 2868 | p->kind = Set_kind; |
| 2869 | p->v.Set.elts = elts; |
| 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; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2878 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2879 | 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 (!elt) { |
| 2883 | PyErr_SetString(PyExc_ValueError, |
| 2884 | "field elt is required for ListComp"); |
| 2885 | return NULL; |
| 2886 | } |
| 2887 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2888 | if (!p) |
| 2889 | return NULL; |
| 2890 | p->kind = ListComp_kind; |
| 2891 | p->v.ListComp.elt = elt; |
| 2892 | p->v.ListComp.generators = generators; |
| 2893 | p->lineno = lineno; |
| 2894 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2895 | p->end_lineno = end_lineno; |
| 2896 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2897 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2898 | } |
| 2899 | |
| 2900 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2901 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2902 | end_lineno, int end_col_offset, PyArena *arena) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2903 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2904 | expr_ty p; |
| 2905 | if (!elt) { |
| 2906 | PyErr_SetString(PyExc_ValueError, |
| 2907 | "field elt is required for SetComp"); |
| 2908 | return NULL; |
| 2909 | } |
| 2910 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2911 | if (!p) |
| 2912 | return NULL; |
| 2913 | p->kind = SetComp_kind; |
| 2914 | p->v.SetComp.elt = elt; |
| 2915 | p->v.SetComp.generators = generators; |
| 2916 | p->lineno = lineno; |
| 2917 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2918 | p->end_lineno = end_lineno; |
| 2919 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2920 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2924 | 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] | 2925 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2926 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2927 | expr_ty p; |
| 2928 | if (!key) { |
| 2929 | PyErr_SetString(PyExc_ValueError, |
| 2930 | "field key is required for DictComp"); |
| 2931 | return NULL; |
| 2932 | } |
| 2933 | if (!value) { |
| 2934 | PyErr_SetString(PyExc_ValueError, |
| 2935 | "field value is required for DictComp"); |
| 2936 | return NULL; |
| 2937 | } |
| 2938 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2939 | if (!p) |
| 2940 | return NULL; |
| 2941 | p->kind = DictComp_kind; |
| 2942 | p->v.DictComp.key = key; |
| 2943 | p->v.DictComp.value = value; |
| 2944 | p->v.DictComp.generators = generators; |
| 2945 | p->lineno = lineno; |
| 2946 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2947 | p->end_lineno = end_lineno; |
| 2948 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2949 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2950 | } |
| 2951 | |
| 2952 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2953 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2954 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2955 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2956 | expr_ty p; |
| 2957 | if (!elt) { |
| 2958 | PyErr_SetString(PyExc_ValueError, |
| 2959 | "field elt is required for GeneratorExp"); |
| 2960 | return NULL; |
| 2961 | } |
| 2962 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2963 | if (!p) |
| 2964 | return NULL; |
| 2965 | p->kind = GeneratorExp_kind; |
| 2966 | p->v.GeneratorExp.elt = elt; |
| 2967 | p->v.GeneratorExp.generators = generators; |
| 2968 | p->lineno = lineno; |
| 2969 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2970 | p->end_lineno = end_lineno; |
| 2971 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2972 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2973 | } |
| 2974 | |
| 2975 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2976 | Await(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2977 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2978 | { |
| 2979 | expr_ty p; |
| 2980 | if (!value) { |
| 2981 | PyErr_SetString(PyExc_ValueError, |
| 2982 | "field value is required for Await"); |
| 2983 | return NULL; |
| 2984 | } |
| 2985 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2986 | if (!p) |
| 2987 | return NULL; |
| 2988 | p->kind = Await_kind; |
| 2989 | p->v.Await.value = value; |
| 2990 | p->lineno = lineno; |
| 2991 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2992 | p->end_lineno = end_lineno; |
| 2993 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2994 | return p; |
| 2995 | } |
| 2996 | |
| 2997 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2998 | Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2999 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3000 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3001 | expr_ty p; |
| 3002 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3003 | if (!p) |
| 3004 | return NULL; |
| 3005 | p->kind = Yield_kind; |
| 3006 | p->v.Yield.value = value; |
| 3007 | p->lineno = lineno; |
| 3008 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3009 | p->end_lineno = end_lineno; |
| 3010 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3011 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3015 | YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 3016 | end_col_offset, PyArena *arena) |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 3017 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3018 | expr_ty p; |
| 3019 | if (!value) { |
| 3020 | PyErr_SetString(PyExc_ValueError, |
| 3021 | "field value is required for YieldFrom"); |
| 3022 | return NULL; |
| 3023 | } |
| 3024 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3025 | if (!p) |
| 3026 | return NULL; |
| 3027 | p->kind = YieldFrom_kind; |
| 3028 | p->v.YieldFrom.value = value; |
| 3029 | p->lineno = lineno; |
| 3030 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3031 | p->end_lineno = end_lineno; |
| 3032 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3033 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 3034 | } |
| 3035 | |
| 3036 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3037 | 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] | 3038 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3039 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3040 | expr_ty p; |
| 3041 | if (!left) { |
| 3042 | PyErr_SetString(PyExc_ValueError, |
| 3043 | "field left is required for Compare"); |
| 3044 | return NULL; |
| 3045 | } |
| 3046 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3047 | if (!p) |
| 3048 | return NULL; |
| 3049 | p->kind = Compare_kind; |
| 3050 | p->v.Compare.left = left; |
| 3051 | p->v.Compare.ops = ops; |
| 3052 | p->v.Compare.comparators = comparators; |
| 3053 | p->lineno = lineno; |
| 3054 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3055 | p->end_lineno = end_lineno; |
| 3056 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3057 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 3061 | 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] | 3062 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3063 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3064 | expr_ty p; |
| 3065 | if (!func) { |
| 3066 | PyErr_SetString(PyExc_ValueError, |
| 3067 | "field func is required for Call"); |
| 3068 | return NULL; |
| 3069 | } |
| 3070 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3071 | if (!p) |
| 3072 | return NULL; |
| 3073 | p->kind = Call_kind; |
| 3074 | p->v.Call.func = func; |
| 3075 | p->v.Call.args = args; |
| 3076 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3077 | p->lineno = lineno; |
| 3078 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3079 | p->end_lineno = end_lineno; |
| 3080 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3081 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3082 | } |
| 3083 | |
| 3084 | expr_ty |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 3085 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
| 3086 | int col_offset, int end_lineno, int end_col_offset, PyArena |
| 3087 | *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3088 | { |
| 3089 | expr_ty p; |
| 3090 | if (!value) { |
| 3091 | PyErr_SetString(PyExc_ValueError, |
| 3092 | "field value is required for FormattedValue"); |
| 3093 | return NULL; |
| 3094 | } |
| 3095 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3096 | if (!p) |
| 3097 | return NULL; |
| 3098 | p->kind = FormattedValue_kind; |
| 3099 | p->v.FormattedValue.value = value; |
| 3100 | p->v.FormattedValue.conversion = conversion; |
| 3101 | p->v.FormattedValue.format_spec = format_spec; |
| 3102 | p->lineno = lineno; |
| 3103 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3104 | p->end_lineno = end_lineno; |
| 3105 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3106 | return p; |
| 3107 | } |
| 3108 | |
| 3109 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3110 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 3111 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3112 | { |
| 3113 | expr_ty p; |
| 3114 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3115 | if (!p) |
| 3116 | return NULL; |
| 3117 | p->kind = JoinedStr_kind; |
| 3118 | p->v.JoinedStr.values = values; |
| 3119 | p->lineno = lineno; |
| 3120 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3121 | p->end_lineno = end_lineno; |
| 3122 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3123 | return p; |
| 3124 | } |
| 3125 | |
| 3126 | expr_ty |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 3127 | Constant(constant value, string kind, int lineno, int col_offset, int |
| 3128 | end_lineno, int end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3129 | { |
| 3130 | expr_ty p; |
| 3131 | if (!value) { |
| 3132 | PyErr_SetString(PyExc_ValueError, |
| 3133 | "field value is required for Constant"); |
| 3134 | return NULL; |
| 3135 | } |
| 3136 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3137 | if (!p) |
| 3138 | return NULL; |
| 3139 | p->kind = Constant_kind; |
| 3140 | p->v.Constant.value = value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 3141 | p->v.Constant.kind = kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3142 | p->lineno = lineno; |
| 3143 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3144 | p->end_lineno = end_lineno; |
| 3145 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3146 | return p; |
| 3147 | } |
| 3148 | |
| 3149 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3150 | 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] | 3151 | col_offset, int end_lineno, int end_col_offset, 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 | expr_ty p; |
| 3154 | if (!value) { |
| 3155 | PyErr_SetString(PyExc_ValueError, |
| 3156 | "field value is required for Attribute"); |
| 3157 | return NULL; |
| 3158 | } |
| 3159 | if (!attr) { |
| 3160 | PyErr_SetString(PyExc_ValueError, |
| 3161 | "field attr is required for Attribute"); |
| 3162 | return NULL; |
| 3163 | } |
| 3164 | if (!ctx) { |
| 3165 | PyErr_SetString(PyExc_ValueError, |
| 3166 | "field ctx is required for Attribute"); |
| 3167 | return NULL; |
| 3168 | } |
| 3169 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3170 | if (!p) |
| 3171 | return NULL; |
| 3172 | p->kind = Attribute_kind; |
| 3173 | p->v.Attribute.value = value; |
| 3174 | p->v.Attribute.attr = attr; |
| 3175 | p->v.Attribute.ctx = ctx; |
| 3176 | p->lineno = lineno; |
| 3177 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3178 | p->end_lineno = end_lineno; |
| 3179 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3180 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3181 | } |
| 3182 | |
| 3183 | expr_ty |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3184 | Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3185 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3186 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3187 | expr_ty p; |
| 3188 | if (!value) { |
| 3189 | PyErr_SetString(PyExc_ValueError, |
| 3190 | "field value is required for Subscript"); |
| 3191 | return NULL; |
| 3192 | } |
| 3193 | if (!slice) { |
| 3194 | PyErr_SetString(PyExc_ValueError, |
| 3195 | "field slice is required for Subscript"); |
| 3196 | return NULL; |
| 3197 | } |
| 3198 | if (!ctx) { |
| 3199 | PyErr_SetString(PyExc_ValueError, |
| 3200 | "field ctx is required for Subscript"); |
| 3201 | return NULL; |
| 3202 | } |
| 3203 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3204 | if (!p) |
| 3205 | return NULL; |
| 3206 | p->kind = Subscript_kind; |
| 3207 | p->v.Subscript.value = value; |
| 3208 | p->v.Subscript.slice = slice; |
| 3209 | p->v.Subscript.ctx = ctx; |
| 3210 | p->lineno = lineno; |
| 3211 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3212 | p->end_lineno = end_lineno; |
| 3213 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3214 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3215 | } |
| 3216 | |
| 3217 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3218 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 3219 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3220 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3221 | expr_ty p; |
| 3222 | if (!value) { |
| 3223 | PyErr_SetString(PyExc_ValueError, |
| 3224 | "field value is required for Starred"); |
| 3225 | return NULL; |
| 3226 | } |
| 3227 | if (!ctx) { |
| 3228 | PyErr_SetString(PyExc_ValueError, |
| 3229 | "field ctx is required for Starred"); |
| 3230 | return NULL; |
| 3231 | } |
| 3232 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3233 | if (!p) |
| 3234 | return NULL; |
| 3235 | p->kind = Starred_kind; |
| 3236 | p->v.Starred.value = value; |
| 3237 | p->v.Starred.ctx = ctx; |
| 3238 | p->lineno = lineno; |
| 3239 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3240 | p->end_lineno = end_lineno; |
| 3241 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3242 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3246 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 3247 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3248 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3249 | expr_ty p; |
| 3250 | if (!id) { |
| 3251 | PyErr_SetString(PyExc_ValueError, |
| 3252 | "field id is required for Name"); |
| 3253 | return NULL; |
| 3254 | } |
| 3255 | if (!ctx) { |
| 3256 | PyErr_SetString(PyExc_ValueError, |
| 3257 | "field ctx is required for Name"); |
| 3258 | return NULL; |
| 3259 | } |
| 3260 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3261 | if (!p) |
| 3262 | return NULL; |
| 3263 | p->kind = Name_kind; |
| 3264 | p->v.Name.id = id; |
| 3265 | p->v.Name.ctx = ctx; |
| 3266 | p->lineno = lineno; |
| 3267 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3268 | p->end_lineno = end_lineno; |
| 3269 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3270 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3274 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3275 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3276 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3277 | expr_ty p; |
| 3278 | if (!ctx) { |
| 3279 | PyErr_SetString(PyExc_ValueError, |
| 3280 | "field ctx is required for List"); |
| 3281 | return NULL; |
| 3282 | } |
| 3283 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3284 | if (!p) |
| 3285 | return NULL; |
| 3286 | p->kind = List_kind; |
| 3287 | p->v.List.elts = elts; |
| 3288 | p->v.List.ctx = ctx; |
| 3289 | p->lineno = lineno; |
| 3290 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3291 | p->end_lineno = end_lineno; |
| 3292 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3293 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3294 | } |
| 3295 | |
| 3296 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3297 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3298 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3299 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3300 | expr_ty p; |
| 3301 | if (!ctx) { |
| 3302 | PyErr_SetString(PyExc_ValueError, |
| 3303 | "field ctx is required for Tuple"); |
| 3304 | return NULL; |
| 3305 | } |
| 3306 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3307 | if (!p) |
| 3308 | return NULL; |
| 3309 | p->kind = Tuple_kind; |
| 3310 | p->v.Tuple.elts = elts; |
| 3311 | p->v.Tuple.ctx = ctx; |
| 3312 | p->lineno = lineno; |
| 3313 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3314 | p->end_lineno = end_lineno; |
| 3315 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3316 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3317 | } |
| 3318 | |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3319 | expr_ty |
| 3320 | Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int col_offset, |
| 3321 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3322 | { |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3323 | expr_ty p; |
| 3324 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3325 | if (!p) |
| 3326 | return NULL; |
| 3327 | p->kind = Slice_kind; |
| 3328 | p->v.Slice.lower = lower; |
| 3329 | p->v.Slice.upper = upper; |
| 3330 | p->v.Slice.step = step; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3331 | p->lineno = lineno; |
| 3332 | p->col_offset = col_offset; |
| 3333 | p->end_lineno = end_lineno; |
| 3334 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3335 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3339 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 3340 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3341 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3342 | comprehension_ty p; |
| 3343 | if (!target) { |
| 3344 | PyErr_SetString(PyExc_ValueError, |
| 3345 | "field target is required for comprehension"); |
| 3346 | return NULL; |
| 3347 | } |
| 3348 | if (!iter) { |
| 3349 | PyErr_SetString(PyExc_ValueError, |
| 3350 | "field iter is required for comprehension"); |
| 3351 | return NULL; |
| 3352 | } |
| 3353 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3354 | if (!p) |
| 3355 | return NULL; |
| 3356 | p->target = target; |
| 3357 | p->iter = iter; |
| 3358 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3359 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3360 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3364 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3365 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3366 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3367 | excepthandler_ty p; |
| 3368 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3369 | if (!p) |
| 3370 | return NULL; |
| 3371 | p->kind = ExceptHandler_kind; |
| 3372 | p->v.ExceptHandler.type = type; |
| 3373 | p->v.ExceptHandler.name = name; |
| 3374 | p->v.ExceptHandler.body = body; |
| 3375 | p->lineno = lineno; |
| 3376 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3377 | p->end_lineno = end_lineno; |
| 3378 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3379 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | arguments_ty |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3383 | arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq * |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3384 | kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq * |
| 3385 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3386 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3387 | arguments_ty p; |
| 3388 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3389 | if (!p) |
| 3390 | return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3391 | p->posonlyargs = posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3392 | p->args = args; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3393 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3394 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3395 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3396 | p->kwarg = kwarg; |
| 3397 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3398 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3399 | } |
| 3400 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3401 | arg_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3402 | arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int |
| 3403 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3404 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3405 | arg_ty p; |
| 3406 | if (!arg) { |
| 3407 | PyErr_SetString(PyExc_ValueError, |
| 3408 | "field arg is required for arg"); |
| 3409 | return NULL; |
| 3410 | } |
| 3411 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3412 | if (!p) |
| 3413 | return NULL; |
| 3414 | p->arg = arg; |
| 3415 | p->annotation = annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3416 | p->type_comment = type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 3417 | p->lineno = lineno; |
| 3418 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3419 | p->end_lineno = end_lineno; |
| 3420 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3421 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3422 | } |
| 3423 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3424 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3425 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3426 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3427 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3428 | if (!value) { |
| 3429 | PyErr_SetString(PyExc_ValueError, |
| 3430 | "field value is required for keyword"); |
| 3431 | return NULL; |
| 3432 | } |
| 3433 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3434 | if (!p) |
| 3435 | return NULL; |
| 3436 | p->arg = arg; |
| 3437 | p->value = value; |
| 3438 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3439 | } |
| 3440 | |
| 3441 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3442 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3443 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3444 | alias_ty p; |
| 3445 | if (!name) { |
| 3446 | PyErr_SetString(PyExc_ValueError, |
| 3447 | "field name is required for alias"); |
| 3448 | return NULL; |
| 3449 | } |
| 3450 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3451 | if (!p) |
| 3452 | return NULL; |
| 3453 | p->name = name; |
| 3454 | p->asname = asname; |
| 3455 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3456 | } |
| 3457 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3458 | withitem_ty |
| 3459 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 3460 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3461 | withitem_ty p; |
| 3462 | if (!context_expr) { |
| 3463 | PyErr_SetString(PyExc_ValueError, |
| 3464 | "field context_expr is required for withitem"); |
| 3465 | return NULL; |
| 3466 | } |
| 3467 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3468 | if (!p) |
| 3469 | return NULL; |
| 3470 | p->context_expr = context_expr; |
| 3471 | p->optional_vars = optional_vars; |
| 3472 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3473 | } |
| 3474 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3475 | type_ignore_ty |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3476 | TypeIgnore(int lineno, string tag, PyArena *arena) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3477 | { |
| 3478 | type_ignore_ty p; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3479 | if (!tag) { |
| 3480 | PyErr_SetString(PyExc_ValueError, |
| 3481 | "field tag is required for TypeIgnore"); |
| 3482 | return NULL; |
| 3483 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3484 | p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3485 | if (!p) |
| 3486 | return NULL; |
| 3487 | p->kind = TypeIgnore_kind; |
| 3488 | p->v.TypeIgnore.lineno = lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3489 | p->v.TypeIgnore.tag = tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3490 | return p; |
| 3491 | } |
| 3492 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3493 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3494 | PyObject* |
| 3495 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3496 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3497 | mod_ty o = (mod_ty)_o; |
| 3498 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3499 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3500 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3501 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3502 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3503 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3504 | switch (o->kind) { |
| 3505 | case Module_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3506 | tp = (PyTypeObject *)astmodulestate_global->Module_type; |
| 3507 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3508 | if (!result) goto failed; |
| 3509 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 3510 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3511 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3512 | goto failed; |
| 3513 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3514 | value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); |
| 3515 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3516 | if (PyObject_SetAttr(result, astmodulestate_global->type_ignores, |
| 3517 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3518 | goto failed; |
| 3519 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3520 | break; |
| 3521 | case Interactive_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3522 | tp = (PyTypeObject *)astmodulestate_global->Interactive_type; |
| 3523 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3524 | if (!result) goto failed; |
| 3525 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 3526 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3527 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3528 | goto failed; |
| 3529 | Py_DECREF(value); |
| 3530 | break; |
| 3531 | case Expression_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3532 | tp = (PyTypeObject *)astmodulestate_global->Expression_type; |
| 3533 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3534 | if (!result) goto failed; |
| 3535 | value = ast2obj_expr(o->v.Expression.body); |
| 3536 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3537 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3538 | goto failed; |
| 3539 | Py_DECREF(value); |
| 3540 | break; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3541 | case FunctionType_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3542 | tp = (PyTypeObject *)astmodulestate_global->FunctionType_type; |
| 3543 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3544 | if (!result) goto failed; |
| 3545 | value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); |
| 3546 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3547 | if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) == |
| 3548 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3549 | goto failed; |
| 3550 | Py_DECREF(value); |
| 3551 | value = ast2obj_expr(o->v.FunctionType.returns); |
| 3552 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3553 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3554 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3555 | goto failed; |
| 3556 | Py_DECREF(value); |
| 3557 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3558 | } |
| 3559 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3560 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3561 | Py_XDECREF(value); |
| 3562 | Py_XDECREF(result); |
| 3563 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3564 | } |
| 3565 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3566 | PyObject* |
| 3567 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3568 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3569 | stmt_ty o = (stmt_ty)_o; |
| 3570 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3571 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3572 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3573 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3574 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3575 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3576 | switch (o->kind) { |
| 3577 | case FunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3578 | tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type; |
| 3579 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3580 | if (!result) goto failed; |
| 3581 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3582 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3583 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3584 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3585 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3586 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3587 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3588 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3589 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3590 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3591 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 3592 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3593 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3594 | goto failed; |
| 3595 | Py_DECREF(value); |
| 3596 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 3597 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3598 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3599 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3600 | goto failed; |
| 3601 | Py_DECREF(value); |
| 3602 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 3603 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3604 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3605 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3606 | goto failed; |
| 3607 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3608 | value = ast2obj_string(o->v.FunctionDef.type_comment); |
| 3609 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3610 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3611 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3612 | goto failed; |
| 3613 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3614 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3615 | case AsyncFunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3616 | tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type; |
| 3617 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3618 | if (!result) goto failed; |
| 3619 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 3620 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3621 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3622 | goto failed; |
| 3623 | Py_DECREF(value); |
| 3624 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 3625 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3626 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3627 | goto failed; |
| 3628 | Py_DECREF(value); |
| 3629 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 3630 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3631 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3632 | goto failed; |
| 3633 | Py_DECREF(value); |
| 3634 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 3635 | ast2obj_expr); |
| 3636 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3637 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3638 | value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3639 | goto failed; |
| 3640 | Py_DECREF(value); |
| 3641 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 3642 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3643 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3644 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3645 | goto failed; |
| 3646 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3647 | value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); |
| 3648 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3649 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3650 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3651 | goto failed; |
| 3652 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3653 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3654 | case ClassDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3655 | tp = (PyTypeObject *)astmodulestate_global->ClassDef_type; |
| 3656 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3657 | if (!result) goto failed; |
| 3658 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 3659 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3660 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3661 | goto failed; |
| 3662 | Py_DECREF(value); |
| 3663 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 3664 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3665 | if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3666 | goto failed; |
| 3667 | Py_DECREF(value); |
| 3668 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 3669 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3670 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 3671 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3672 | goto failed; |
| 3673 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3674 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 3675 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3676 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3677 | goto failed; |
| 3678 | Py_DECREF(value); |
| 3679 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 3680 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3681 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3682 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3683 | goto failed; |
| 3684 | Py_DECREF(value); |
| 3685 | break; |
| 3686 | case Return_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3687 | tp = (PyTypeObject *)astmodulestate_global->Return_type; |
| 3688 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3689 | if (!result) goto failed; |
| 3690 | value = ast2obj_expr(o->v.Return.value); |
| 3691 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3692 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3693 | goto failed; |
| 3694 | Py_DECREF(value); |
| 3695 | break; |
| 3696 | case Delete_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3697 | tp = (PyTypeObject *)astmodulestate_global->Delete_type; |
| 3698 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3699 | if (!result) goto failed; |
| 3700 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 3701 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3702 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3703 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3704 | goto failed; |
| 3705 | Py_DECREF(value); |
| 3706 | break; |
| 3707 | case Assign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3708 | tp = (PyTypeObject *)astmodulestate_global->Assign_type; |
| 3709 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3710 | if (!result) goto failed; |
| 3711 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 3712 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3713 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3714 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3715 | goto failed; |
| 3716 | Py_DECREF(value); |
| 3717 | value = ast2obj_expr(o->v.Assign.value); |
| 3718 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3719 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3720 | goto failed; |
| 3721 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3722 | value = ast2obj_string(o->v.Assign.type_comment); |
| 3723 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3724 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3725 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3726 | goto failed; |
| 3727 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3728 | break; |
| 3729 | case AugAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3730 | tp = (PyTypeObject *)astmodulestate_global->AugAssign_type; |
| 3731 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3732 | if (!result) goto failed; |
| 3733 | value = ast2obj_expr(o->v.AugAssign.target); |
| 3734 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3735 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3736 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3737 | goto failed; |
| 3738 | Py_DECREF(value); |
| 3739 | value = ast2obj_operator(o->v.AugAssign.op); |
| 3740 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3741 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3742 | goto failed; |
| 3743 | Py_DECREF(value); |
| 3744 | value = ast2obj_expr(o->v.AugAssign.value); |
| 3745 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3746 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3747 | goto failed; |
| 3748 | Py_DECREF(value); |
| 3749 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3750 | case AnnAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3751 | tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type; |
| 3752 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3753 | if (!result) goto failed; |
| 3754 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 3755 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3756 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3757 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3758 | goto failed; |
| 3759 | Py_DECREF(value); |
| 3760 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 3761 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3762 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) |
| 3763 | == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3764 | goto failed; |
| 3765 | Py_DECREF(value); |
| 3766 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 3767 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3768 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3769 | goto failed; |
| 3770 | Py_DECREF(value); |
| 3771 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 3772 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3773 | if (PyObject_SetAttr(result, astmodulestate_global->simple, value) == |
| 3774 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3775 | goto failed; |
| 3776 | Py_DECREF(value); |
| 3777 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3778 | case For_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3779 | tp = (PyTypeObject *)astmodulestate_global->For_type; |
| 3780 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3781 | if (!result) goto failed; |
| 3782 | value = ast2obj_expr(o->v.For.target); |
| 3783 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3784 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3785 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3786 | goto failed; |
| 3787 | Py_DECREF(value); |
| 3788 | value = ast2obj_expr(o->v.For.iter); |
| 3789 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3790 | if (PyObject_SetAttr(result, astmodulestate_global->iter, 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.For.body, ast2obj_stmt); |
| 3794 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3795 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3796 | goto failed; |
| 3797 | Py_DECREF(value); |
| 3798 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 3799 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3800 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3801 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3802 | goto failed; |
| 3803 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3804 | value = ast2obj_string(o->v.For.type_comment); |
| 3805 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3806 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3807 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3808 | goto failed; |
| 3809 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3810 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3811 | case AsyncFor_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3812 | tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type; |
| 3813 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3814 | if (!result) goto failed; |
| 3815 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 3816 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3817 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3818 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3819 | goto failed; |
| 3820 | Py_DECREF(value); |
| 3821 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 3822 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3823 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3824 | goto failed; |
| 3825 | Py_DECREF(value); |
| 3826 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 3827 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3828 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3829 | goto failed; |
| 3830 | Py_DECREF(value); |
| 3831 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 3832 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3833 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3834 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3835 | goto failed; |
| 3836 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3837 | value = ast2obj_string(o->v.AsyncFor.type_comment); |
| 3838 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3839 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3840 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3841 | goto failed; |
| 3842 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3843 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3844 | case While_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3845 | tp = (PyTypeObject *)astmodulestate_global->While_type; |
| 3846 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3847 | if (!result) goto failed; |
| 3848 | value = ast2obj_expr(o->v.While.test); |
| 3849 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3850 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3851 | goto failed; |
| 3852 | Py_DECREF(value); |
| 3853 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 3854 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3855 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3856 | goto failed; |
| 3857 | Py_DECREF(value); |
| 3858 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 3859 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3860 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3861 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3862 | goto failed; |
| 3863 | Py_DECREF(value); |
| 3864 | break; |
| 3865 | case If_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3866 | tp = (PyTypeObject *)astmodulestate_global->If_type; |
| 3867 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3868 | if (!result) goto failed; |
| 3869 | value = ast2obj_expr(o->v.If.test); |
| 3870 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3871 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3872 | goto failed; |
| 3873 | Py_DECREF(value); |
| 3874 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 3875 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3876 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3877 | goto failed; |
| 3878 | Py_DECREF(value); |
| 3879 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 3880 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3881 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3882 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3883 | goto failed; |
| 3884 | Py_DECREF(value); |
| 3885 | break; |
| 3886 | case With_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3887 | tp = (PyTypeObject *)astmodulestate_global->With_type; |
| 3888 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3889 | if (!result) goto failed; |
| 3890 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 3891 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3892 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3893 | goto failed; |
| 3894 | Py_DECREF(value); |
| 3895 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 3896 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3897 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3898 | goto failed; |
| 3899 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3900 | value = ast2obj_string(o->v.With.type_comment); |
| 3901 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3902 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3903 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3904 | goto failed; |
| 3905 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3906 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3907 | case AsyncWith_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3908 | tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type; |
| 3909 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3910 | if (!result) goto failed; |
| 3911 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 3912 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3913 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3914 | goto failed; |
| 3915 | Py_DECREF(value); |
| 3916 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 3917 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3918 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3919 | goto failed; |
| 3920 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3921 | value = ast2obj_string(o->v.AsyncWith.type_comment); |
| 3922 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3923 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3924 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3925 | goto failed; |
| 3926 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3927 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3928 | case Raise_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3929 | tp = (PyTypeObject *)astmodulestate_global->Raise_type; |
| 3930 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3931 | if (!result) goto failed; |
| 3932 | value = ast2obj_expr(o->v.Raise.exc); |
| 3933 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3934 | if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3935 | goto failed; |
| 3936 | Py_DECREF(value); |
| 3937 | value = ast2obj_expr(o->v.Raise.cause); |
| 3938 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3939 | if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3940 | goto failed; |
| 3941 | Py_DECREF(value); |
| 3942 | break; |
| 3943 | case Try_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3944 | tp = (PyTypeObject *)astmodulestate_global->Try_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_list(o->v.Try.body, ast2obj_stmt); |
| 3948 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3949 | if (PyObject_SetAttr(result, astmodulestate_global->body, 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.Try.handlers, ast2obj_excepthandler); |
| 3953 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3954 | if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) == |
| 3955 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3956 | goto failed; |
| 3957 | Py_DECREF(value); |
| 3958 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 3959 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3960 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3961 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3962 | goto failed; |
| 3963 | Py_DECREF(value); |
| 3964 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 3965 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3966 | if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value) |
| 3967 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3968 | goto failed; |
| 3969 | Py_DECREF(value); |
| 3970 | break; |
| 3971 | case Assert_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3972 | tp = (PyTypeObject *)astmodulestate_global->Assert_type; |
| 3973 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3974 | if (!result) goto failed; |
| 3975 | value = ast2obj_expr(o->v.Assert.test); |
| 3976 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3977 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3978 | goto failed; |
| 3979 | Py_DECREF(value); |
| 3980 | value = ast2obj_expr(o->v.Assert.msg); |
| 3981 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3982 | if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3983 | goto failed; |
| 3984 | Py_DECREF(value); |
| 3985 | break; |
| 3986 | case Import_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3987 | tp = (PyTypeObject *)astmodulestate_global->Import_type; |
| 3988 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3989 | if (!result) goto failed; |
| 3990 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 3991 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3992 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3993 | goto failed; |
| 3994 | Py_DECREF(value); |
| 3995 | break; |
| 3996 | case ImportFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3997 | tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type; |
| 3998 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3999 | if (!result) goto failed; |
| 4000 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 4001 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4002 | if (PyObject_SetAttr(result, astmodulestate_global->module, value) == |
| 4003 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4004 | goto failed; |
| 4005 | Py_DECREF(value); |
| 4006 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 4007 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4008 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4009 | goto failed; |
| 4010 | Py_DECREF(value); |
| 4011 | value = ast2obj_int(o->v.ImportFrom.level); |
| 4012 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4013 | if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4014 | goto failed; |
| 4015 | Py_DECREF(value); |
| 4016 | break; |
| 4017 | case Global_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4018 | tp = (PyTypeObject *)astmodulestate_global->Global_type; |
| 4019 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4020 | if (!result) goto failed; |
| 4021 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 4022 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4023 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4024 | goto failed; |
| 4025 | Py_DECREF(value); |
| 4026 | break; |
| 4027 | case Nonlocal_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4028 | tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type; |
| 4029 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4030 | if (!result) goto failed; |
| 4031 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 4032 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4033 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4034 | goto failed; |
| 4035 | Py_DECREF(value); |
| 4036 | break; |
| 4037 | case Expr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4038 | tp = (PyTypeObject *)astmodulestate_global->Expr_type; |
| 4039 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4040 | if (!result) goto failed; |
| 4041 | value = ast2obj_expr(o->v.Expr.value); |
| 4042 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4043 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4044 | goto failed; |
| 4045 | Py_DECREF(value); |
| 4046 | break; |
| 4047 | case Pass_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4048 | tp = (PyTypeObject *)astmodulestate_global->Pass_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 | break; |
| 4052 | case Break_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4053 | tp = (PyTypeObject *)astmodulestate_global->Break_type; |
| 4054 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4055 | if (!result) goto failed; |
| 4056 | break; |
| 4057 | case Continue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4058 | tp = (PyTypeObject *)astmodulestate_global->Continue_type; |
| 4059 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4060 | if (!result) goto failed; |
| 4061 | break; |
| 4062 | } |
| 4063 | value = ast2obj_int(o->lineno); |
| 4064 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4065 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4066 | goto failed; |
| 4067 | Py_DECREF(value); |
| 4068 | value = ast2obj_int(o->col_offset); |
| 4069 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4070 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4071 | goto failed; |
| 4072 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4073 | value = ast2obj_int(o->end_lineno); |
| 4074 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4075 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4076 | goto failed; |
| 4077 | Py_DECREF(value); |
| 4078 | value = ast2obj_int(o->end_col_offset); |
| 4079 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4080 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4081 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4082 | goto failed; |
| 4083 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4084 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4085 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4086 | Py_XDECREF(value); |
| 4087 | Py_XDECREF(result); |
| 4088 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4089 | } |
| 4090 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4091 | PyObject* |
| 4092 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4093 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4094 | expr_ty o = (expr_ty)_o; |
| 4095 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4096 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4097 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4098 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4099 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4100 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4101 | switch (o->kind) { |
| 4102 | case BoolOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4103 | tp = (PyTypeObject *)astmodulestate_global->BoolOp_type; |
| 4104 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4105 | if (!result) goto failed; |
| 4106 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 4107 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4108 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4109 | goto failed; |
| 4110 | Py_DECREF(value); |
| 4111 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 4112 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4113 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4114 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4115 | goto failed; |
| 4116 | Py_DECREF(value); |
| 4117 | break; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4118 | case NamedExpr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4119 | tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type; |
| 4120 | result = PyType_GenericNew(tp, NULL, NULL); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4121 | if (!result) goto failed; |
| 4122 | value = ast2obj_expr(o->v.NamedExpr.target); |
| 4123 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4124 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 4125 | -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4126 | goto failed; |
| 4127 | Py_DECREF(value); |
| 4128 | value = ast2obj_expr(o->v.NamedExpr.value); |
| 4129 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4130 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4131 | goto failed; |
| 4132 | Py_DECREF(value); |
| 4133 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4134 | case BinOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4135 | tp = (PyTypeObject *)astmodulestate_global->BinOp_type; |
| 4136 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4137 | if (!result) goto failed; |
| 4138 | value = ast2obj_expr(o->v.BinOp.left); |
| 4139 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4140 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4141 | goto failed; |
| 4142 | Py_DECREF(value); |
| 4143 | value = ast2obj_operator(o->v.BinOp.op); |
| 4144 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4145 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4146 | goto failed; |
| 4147 | Py_DECREF(value); |
| 4148 | value = ast2obj_expr(o->v.BinOp.right); |
| 4149 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4150 | if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4151 | goto failed; |
| 4152 | Py_DECREF(value); |
| 4153 | break; |
| 4154 | case UnaryOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4155 | tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type; |
| 4156 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4157 | if (!result) goto failed; |
| 4158 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 4159 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4160 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4161 | goto failed; |
| 4162 | Py_DECREF(value); |
| 4163 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 4164 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4165 | if (PyObject_SetAttr(result, astmodulestate_global->operand, value) == |
| 4166 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4167 | goto failed; |
| 4168 | Py_DECREF(value); |
| 4169 | break; |
| 4170 | case Lambda_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4171 | tp = (PyTypeObject *)astmodulestate_global->Lambda_type; |
| 4172 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4173 | if (!result) goto failed; |
| 4174 | value = ast2obj_arguments(o->v.Lambda.args); |
| 4175 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4176 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4177 | goto failed; |
| 4178 | Py_DECREF(value); |
| 4179 | value = ast2obj_expr(o->v.Lambda.body); |
| 4180 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4181 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4182 | goto failed; |
| 4183 | Py_DECREF(value); |
| 4184 | break; |
| 4185 | case IfExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4186 | tp = (PyTypeObject *)astmodulestate_global->IfExp_type; |
| 4187 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4188 | if (!result) goto failed; |
| 4189 | value = ast2obj_expr(o->v.IfExp.test); |
| 4190 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4191 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4192 | goto failed; |
| 4193 | Py_DECREF(value); |
| 4194 | value = ast2obj_expr(o->v.IfExp.body); |
| 4195 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4196 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4197 | goto failed; |
| 4198 | Py_DECREF(value); |
| 4199 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 4200 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4201 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 4202 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4203 | goto failed; |
| 4204 | Py_DECREF(value); |
| 4205 | break; |
| 4206 | case Dict_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4207 | tp = (PyTypeObject *)astmodulestate_global->Dict_type; |
| 4208 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4209 | if (!result) goto failed; |
| 4210 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 4211 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4212 | if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4213 | goto failed; |
| 4214 | Py_DECREF(value); |
| 4215 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 4216 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4217 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4218 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4219 | goto failed; |
| 4220 | Py_DECREF(value); |
| 4221 | break; |
| 4222 | case Set_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4223 | tp = (PyTypeObject *)astmodulestate_global->Set_type; |
| 4224 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4225 | if (!result) goto failed; |
| 4226 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 4227 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4228 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4229 | goto failed; |
| 4230 | Py_DECREF(value); |
| 4231 | break; |
| 4232 | case ListComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4233 | tp = (PyTypeObject *)astmodulestate_global->ListComp_type; |
| 4234 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4235 | if (!result) goto failed; |
| 4236 | value = ast2obj_expr(o->v.ListComp.elt); |
| 4237 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4238 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4239 | goto failed; |
| 4240 | Py_DECREF(value); |
| 4241 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 4242 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4243 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4244 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4245 | goto failed; |
| 4246 | Py_DECREF(value); |
| 4247 | break; |
| 4248 | case SetComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4249 | tp = (PyTypeObject *)astmodulestate_global->SetComp_type; |
| 4250 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4251 | if (!result) goto failed; |
| 4252 | value = ast2obj_expr(o->v.SetComp.elt); |
| 4253 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4254 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4255 | goto failed; |
| 4256 | Py_DECREF(value); |
| 4257 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 4258 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4259 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4260 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4261 | goto failed; |
| 4262 | Py_DECREF(value); |
| 4263 | break; |
| 4264 | case DictComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4265 | tp = (PyTypeObject *)astmodulestate_global->DictComp_type; |
| 4266 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4267 | if (!result) goto failed; |
| 4268 | value = ast2obj_expr(o->v.DictComp.key); |
| 4269 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4270 | if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4271 | goto failed; |
| 4272 | Py_DECREF(value); |
| 4273 | value = ast2obj_expr(o->v.DictComp.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_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 4279 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4280 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4281 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4282 | goto failed; |
| 4283 | Py_DECREF(value); |
| 4284 | break; |
| 4285 | case GeneratorExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4286 | tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type; |
| 4287 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4288 | if (!result) goto failed; |
| 4289 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 4290 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4291 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4292 | goto failed; |
| 4293 | Py_DECREF(value); |
| 4294 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 4295 | ast2obj_comprehension); |
| 4296 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4297 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4298 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4299 | goto failed; |
| 4300 | Py_DECREF(value); |
| 4301 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4302 | case Await_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4303 | tp = (PyTypeObject *)astmodulestate_global->Await_type; |
| 4304 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4305 | if (!result) goto failed; |
| 4306 | value = ast2obj_expr(o->v.Await.value); |
| 4307 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4308 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4309 | goto failed; |
| 4310 | Py_DECREF(value); |
| 4311 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4312 | case Yield_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4313 | tp = (PyTypeObject *)astmodulestate_global->Yield_type; |
| 4314 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4315 | if (!result) goto failed; |
| 4316 | value = ast2obj_expr(o->v.Yield.value); |
| 4317 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4318 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4319 | goto failed; |
| 4320 | Py_DECREF(value); |
| 4321 | break; |
| 4322 | case YieldFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4323 | tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type; |
| 4324 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4325 | if (!result) goto failed; |
| 4326 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 4327 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4328 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4329 | goto failed; |
| 4330 | Py_DECREF(value); |
| 4331 | break; |
| 4332 | case Compare_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4333 | tp = (PyTypeObject *)astmodulestate_global->Compare_type; |
| 4334 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4335 | if (!result) goto failed; |
| 4336 | value = ast2obj_expr(o->v.Compare.left); |
| 4337 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4338 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4339 | goto failed; |
| 4340 | Py_DECREF(value); |
| 4341 | { |
| 4342 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 4343 | value = PyList_New(n); |
| 4344 | if (!value) goto failed; |
| 4345 | for(i = 0; i < n; i++) |
| 4346 | 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] | 4347 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 4348 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4349 | if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4350 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4351 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4352 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 4353 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4354 | if (PyObject_SetAttr(result, astmodulestate_global->comparators, value) |
| 4355 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4356 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4357 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4358 | break; |
| 4359 | case Call_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4360 | tp = (PyTypeObject *)astmodulestate_global->Call_type; |
| 4361 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4362 | if (!result) goto failed; |
| 4363 | value = ast2obj_expr(o->v.Call.func); |
| 4364 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4365 | if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4366 | goto failed; |
| 4367 | Py_DECREF(value); |
| 4368 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 4369 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4370 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4371 | goto failed; |
| 4372 | Py_DECREF(value); |
| 4373 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 4374 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4375 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 4376 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4377 | goto failed; |
| 4378 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4379 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4380 | case FormattedValue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4381 | tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type; |
| 4382 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4383 | if (!result) goto failed; |
| 4384 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 4385 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4386 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4387 | goto failed; |
| 4388 | Py_DECREF(value); |
| 4389 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 4390 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4391 | if (PyObject_SetAttr(result, astmodulestate_global->conversion, value) |
| 4392 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4393 | goto failed; |
| 4394 | Py_DECREF(value); |
| 4395 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 4396 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4397 | if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value) |
| 4398 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4399 | goto failed; |
| 4400 | Py_DECREF(value); |
| 4401 | break; |
| 4402 | case JoinedStr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4403 | tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type; |
| 4404 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4405 | if (!result) goto failed; |
| 4406 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 4407 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4408 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4409 | -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4410 | goto failed; |
| 4411 | Py_DECREF(value); |
| 4412 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4413 | case Constant_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4414 | tp = (PyTypeObject *)astmodulestate_global->Constant_type; |
| 4415 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4416 | if (!result) goto failed; |
| 4417 | value = ast2obj_constant(o->v.Constant.value); |
| 4418 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4419 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4420 | goto failed; |
| 4421 | Py_DECREF(value); |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4422 | value = ast2obj_string(o->v.Constant.kind); |
| 4423 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4424 | if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1) |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4425 | goto failed; |
| 4426 | Py_DECREF(value); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4427 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4428 | case Attribute_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4429 | tp = (PyTypeObject *)astmodulestate_global->Attribute_type; |
| 4430 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4431 | if (!result) goto failed; |
| 4432 | value = ast2obj_expr(o->v.Attribute.value); |
| 4433 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4434 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4435 | goto failed; |
| 4436 | Py_DECREF(value); |
| 4437 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 4438 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4439 | if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4440 | goto failed; |
| 4441 | Py_DECREF(value); |
| 4442 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 4443 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4444 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4445 | goto failed; |
| 4446 | Py_DECREF(value); |
| 4447 | break; |
| 4448 | case Subscript_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4449 | tp = (PyTypeObject *)astmodulestate_global->Subscript_type; |
| 4450 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4451 | if (!result) goto failed; |
| 4452 | value = ast2obj_expr(o->v.Subscript.value); |
| 4453 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4454 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4455 | goto failed; |
| 4456 | Py_DECREF(value); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 4457 | value = ast2obj_expr(o->v.Subscript.slice); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4458 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4459 | if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4460 | goto failed; |
| 4461 | Py_DECREF(value); |
| 4462 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 4463 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4464 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4465 | goto failed; |
| 4466 | Py_DECREF(value); |
| 4467 | break; |
| 4468 | case Starred_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4469 | tp = (PyTypeObject *)astmodulestate_global->Starred_type; |
| 4470 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4471 | if (!result) goto failed; |
| 4472 | value = ast2obj_expr(o->v.Starred.value); |
| 4473 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4474 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4475 | goto failed; |
| 4476 | Py_DECREF(value); |
| 4477 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 4478 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4479 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4480 | goto failed; |
| 4481 | Py_DECREF(value); |
| 4482 | break; |
| 4483 | case Name_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4484 | tp = (PyTypeObject *)astmodulestate_global->Name_type; |
| 4485 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4486 | if (!result) goto failed; |
| 4487 | value = ast2obj_identifier(o->v.Name.id); |
| 4488 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4489 | if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4490 | goto failed; |
| 4491 | Py_DECREF(value); |
| 4492 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 4493 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4494 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4495 | goto failed; |
| 4496 | Py_DECREF(value); |
| 4497 | break; |
| 4498 | case List_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4499 | tp = (PyTypeObject *)astmodulestate_global->List_type; |
| 4500 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4501 | if (!result) goto failed; |
| 4502 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 4503 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4504 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4505 | goto failed; |
| 4506 | Py_DECREF(value); |
| 4507 | value = ast2obj_expr_context(o->v.List.ctx); |
| 4508 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4509 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4510 | goto failed; |
| 4511 | Py_DECREF(value); |
| 4512 | break; |
| 4513 | case Tuple_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4514 | tp = (PyTypeObject *)astmodulestate_global->Tuple_type; |
| 4515 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4516 | if (!result) goto failed; |
| 4517 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 4518 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4519 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4520 | goto failed; |
| 4521 | Py_DECREF(value); |
| 4522 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 4523 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4524 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4525 | goto failed; |
| 4526 | Py_DECREF(value); |
| 4527 | break; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 4528 | case Slice_kind: |
| 4529 | tp = (PyTypeObject *)astmodulestate_global->Slice_type; |
| 4530 | result = PyType_GenericNew(tp, NULL, NULL); |
| 4531 | if (!result) goto failed; |
| 4532 | value = ast2obj_expr(o->v.Slice.lower); |
| 4533 | if (!value) goto failed; |
| 4534 | if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1) |
| 4535 | goto failed; |
| 4536 | Py_DECREF(value); |
| 4537 | value = ast2obj_expr(o->v.Slice.upper); |
| 4538 | if (!value) goto failed; |
| 4539 | if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1) |
| 4540 | goto failed; |
| 4541 | Py_DECREF(value); |
| 4542 | value = ast2obj_expr(o->v.Slice.step); |
| 4543 | if (!value) goto failed; |
| 4544 | if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1) |
| 4545 | goto failed; |
| 4546 | Py_DECREF(value); |
| 4547 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4548 | } |
| 4549 | value = ast2obj_int(o->lineno); |
| 4550 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4551 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4552 | goto failed; |
| 4553 | Py_DECREF(value); |
| 4554 | value = ast2obj_int(o->col_offset); |
| 4555 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4556 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4557 | goto failed; |
| 4558 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4559 | value = ast2obj_int(o->end_lineno); |
| 4560 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4561 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4562 | goto failed; |
| 4563 | Py_DECREF(value); |
| 4564 | value = ast2obj_int(o->end_col_offset); |
| 4565 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4566 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4567 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4568 | goto failed; |
| 4569 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4570 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4571 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4572 | Py_XDECREF(value); |
| 4573 | Py_XDECREF(result); |
| 4574 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4575 | } |
| 4576 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4577 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4578 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4579 | switch(o) { |
| 4580 | case Load: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4581 | Py_INCREF(astmodulestate_global->Load_singleton); |
| 4582 | return astmodulestate_global->Load_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4583 | case Store: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4584 | Py_INCREF(astmodulestate_global->Store_singleton); |
| 4585 | return astmodulestate_global->Store_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4586 | case Del: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4587 | Py_INCREF(astmodulestate_global->Del_singleton); |
| 4588 | return astmodulestate_global->Del_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4589 | default: |
| 4590 | /* should never happen, but just in case ... */ |
| 4591 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 4592 | return NULL; |
| 4593 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4594 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4595 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4596 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4597 | switch(o) { |
| 4598 | case And: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4599 | Py_INCREF(astmodulestate_global->And_singleton); |
| 4600 | return astmodulestate_global->And_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4601 | case Or: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4602 | Py_INCREF(astmodulestate_global->Or_singleton); |
| 4603 | return astmodulestate_global->Or_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4604 | default: |
| 4605 | /* should never happen, but just in case ... */ |
| 4606 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 4607 | return NULL; |
| 4608 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4609 | } |
| 4610 | PyObject* ast2obj_operator(operator_ty o) |
| 4611 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4612 | switch(o) { |
| 4613 | case Add: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4614 | Py_INCREF(astmodulestate_global->Add_singleton); |
| 4615 | return astmodulestate_global->Add_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4616 | case Sub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4617 | Py_INCREF(astmodulestate_global->Sub_singleton); |
| 4618 | return astmodulestate_global->Sub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4619 | case Mult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4620 | Py_INCREF(astmodulestate_global->Mult_singleton); |
| 4621 | return astmodulestate_global->Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 4622 | case MatMult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4623 | Py_INCREF(astmodulestate_global->MatMult_singleton); |
| 4624 | return astmodulestate_global->MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4625 | case Div: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4626 | Py_INCREF(astmodulestate_global->Div_singleton); |
| 4627 | return astmodulestate_global->Div_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4628 | case Mod: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4629 | Py_INCREF(astmodulestate_global->Mod_singleton); |
| 4630 | return astmodulestate_global->Mod_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4631 | case Pow: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4632 | Py_INCREF(astmodulestate_global->Pow_singleton); |
| 4633 | return astmodulestate_global->Pow_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4634 | case LShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4635 | Py_INCREF(astmodulestate_global->LShift_singleton); |
| 4636 | return astmodulestate_global->LShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4637 | case RShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4638 | Py_INCREF(astmodulestate_global->RShift_singleton); |
| 4639 | return astmodulestate_global->RShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4640 | case BitOr: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4641 | Py_INCREF(astmodulestate_global->BitOr_singleton); |
| 4642 | return astmodulestate_global->BitOr_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4643 | case BitXor: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4644 | Py_INCREF(astmodulestate_global->BitXor_singleton); |
| 4645 | return astmodulestate_global->BitXor_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4646 | case BitAnd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4647 | Py_INCREF(astmodulestate_global->BitAnd_singleton); |
| 4648 | return astmodulestate_global->BitAnd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4649 | case FloorDiv: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4650 | Py_INCREF(astmodulestate_global->FloorDiv_singleton); |
| 4651 | return astmodulestate_global->FloorDiv_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4652 | default: |
| 4653 | /* should never happen, but just in case ... */ |
| 4654 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 4655 | return NULL; |
| 4656 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4657 | } |
| 4658 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 4659 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4660 | switch(o) { |
| 4661 | case Invert: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4662 | Py_INCREF(astmodulestate_global->Invert_singleton); |
| 4663 | return astmodulestate_global->Invert_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4664 | case Not: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4665 | Py_INCREF(astmodulestate_global->Not_singleton); |
| 4666 | return astmodulestate_global->Not_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4667 | case UAdd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4668 | Py_INCREF(astmodulestate_global->UAdd_singleton); |
| 4669 | return astmodulestate_global->UAdd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4670 | case USub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4671 | Py_INCREF(astmodulestate_global->USub_singleton); |
| 4672 | return astmodulestate_global->USub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4673 | default: |
| 4674 | /* should never happen, but just in case ... */ |
| 4675 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 4676 | return NULL; |
| 4677 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4678 | } |
| 4679 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 4680 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4681 | switch(o) { |
| 4682 | case Eq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4683 | Py_INCREF(astmodulestate_global->Eq_singleton); |
| 4684 | return astmodulestate_global->Eq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4685 | case NotEq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4686 | Py_INCREF(astmodulestate_global->NotEq_singleton); |
| 4687 | return astmodulestate_global->NotEq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4688 | case Lt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4689 | Py_INCREF(astmodulestate_global->Lt_singleton); |
| 4690 | return astmodulestate_global->Lt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4691 | case LtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4692 | Py_INCREF(astmodulestate_global->LtE_singleton); |
| 4693 | return astmodulestate_global->LtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4694 | case Gt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4695 | Py_INCREF(astmodulestate_global->Gt_singleton); |
| 4696 | return astmodulestate_global->Gt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4697 | case GtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4698 | Py_INCREF(astmodulestate_global->GtE_singleton); |
| 4699 | return astmodulestate_global->GtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4700 | case Is: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4701 | Py_INCREF(astmodulestate_global->Is_singleton); |
| 4702 | return astmodulestate_global->Is_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4703 | case IsNot: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4704 | Py_INCREF(astmodulestate_global->IsNot_singleton); |
| 4705 | return astmodulestate_global->IsNot_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4706 | case In: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4707 | Py_INCREF(astmodulestate_global->In_singleton); |
| 4708 | return astmodulestate_global->In_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4709 | case NotIn: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4710 | Py_INCREF(astmodulestate_global->NotIn_singleton); |
| 4711 | return astmodulestate_global->NotIn_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4712 | default: |
| 4713 | /* should never happen, but just in case ... */ |
| 4714 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 4715 | return NULL; |
| 4716 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4717 | } |
| 4718 | PyObject* |
| 4719 | ast2obj_comprehension(void* _o) |
| 4720 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4721 | comprehension_ty o = (comprehension_ty)_o; |
| 4722 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4723 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4724 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4725 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4726 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4727 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4728 | tp = (PyTypeObject *)astmodulestate_global->comprehension_type; |
| 4729 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4730 | if (!result) return NULL; |
| 4731 | value = ast2obj_expr(o->target); |
| 4732 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4733 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4734 | goto failed; |
| 4735 | Py_DECREF(value); |
| 4736 | value = ast2obj_expr(o->iter); |
| 4737 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4738 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4739 | goto failed; |
| 4740 | Py_DECREF(value); |
| 4741 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 4742 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4743 | if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4744 | goto failed; |
| 4745 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4746 | value = ast2obj_int(o->is_async); |
| 4747 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4748 | if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1) |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4749 | goto failed; |
| 4750 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4751 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4752 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4753 | Py_XDECREF(value); |
| 4754 | Py_XDECREF(result); |
| 4755 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4756 | } |
| 4757 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4758 | PyObject* |
| 4759 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4760 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4761 | excepthandler_ty o = (excepthandler_ty)_o; |
| 4762 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4763 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4764 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4765 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4766 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4767 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4768 | switch (o->kind) { |
| 4769 | case ExceptHandler_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4770 | tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type; |
| 4771 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4772 | if (!result) goto failed; |
| 4773 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4774 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4775 | if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4776 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4777 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4778 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4779 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4780 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4781 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4782 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4783 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 4784 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4785 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4786 | goto failed; |
| 4787 | Py_DECREF(value); |
| 4788 | break; |
| 4789 | } |
| 4790 | value = ast2obj_int(o->lineno); |
| 4791 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4792 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4793 | goto failed; |
| 4794 | Py_DECREF(value); |
| 4795 | value = ast2obj_int(o->col_offset); |
| 4796 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4797 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4798 | goto failed; |
| 4799 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4800 | value = ast2obj_int(o->end_lineno); |
| 4801 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4802 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4803 | goto failed; |
| 4804 | Py_DECREF(value); |
| 4805 | value = ast2obj_int(o->end_col_offset); |
| 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_col_offset, value) |
| 4808 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4809 | goto failed; |
| 4810 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4811 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4812 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4813 | Py_XDECREF(value); |
| 4814 | Py_XDECREF(result); |
| 4815 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4816 | } |
| 4817 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4818 | PyObject* |
| 4819 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4820 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4821 | arguments_ty o = (arguments_ty)_o; |
| 4822 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4823 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4824 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4825 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4826 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4827 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4828 | tp = (PyTypeObject *)astmodulestate_global->arguments_type; |
| 4829 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4830 | if (!result) return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4831 | value = ast2obj_list(o->posonlyargs, ast2obj_arg); |
| 4832 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4833 | if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) == |
| 4834 | -1) |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4835 | goto failed; |
| 4836 | Py_DECREF(value); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4837 | value = ast2obj_list(o->args, ast2obj_arg); |
| 4838 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4839 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4840 | goto failed; |
| 4841 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4842 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4843 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4844 | if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4845 | goto failed; |
| 4846 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4847 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 4848 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4849 | if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) == |
| 4850 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4851 | goto failed; |
| 4852 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4853 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4854 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4855 | if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) == |
| 4856 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4857 | goto failed; |
| 4858 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4859 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4860 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4861 | if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4862 | goto failed; |
| 4863 | Py_DECREF(value); |
| 4864 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 4865 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4866 | if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4867 | goto failed; |
| 4868 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4869 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4870 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4871 | Py_XDECREF(value); |
| 4872 | Py_XDECREF(result); |
| 4873 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4874 | } |
| 4875 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4876 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4877 | ast2obj_arg(void* _o) |
| 4878 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4879 | arg_ty o = (arg_ty)_o; |
| 4880 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4881 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4882 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4883 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4884 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4885 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4886 | tp = (PyTypeObject *)astmodulestate_global->arg_type; |
| 4887 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4888 | if (!result) return NULL; |
| 4889 | value = ast2obj_identifier(o->arg); |
| 4890 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4891 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4892 | goto failed; |
| 4893 | Py_DECREF(value); |
| 4894 | value = ast2obj_expr(o->annotation); |
| 4895 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4896 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) == |
| 4897 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4898 | goto failed; |
| 4899 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4900 | value = ast2obj_string(o->type_comment); |
| 4901 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4902 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) == |
| 4903 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4904 | goto failed; |
| 4905 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4906 | value = ast2obj_int(o->lineno); |
| 4907 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4908 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4909 | goto failed; |
| 4910 | Py_DECREF(value); |
| 4911 | value = ast2obj_int(o->col_offset); |
| 4912 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4913 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4914 | goto failed; |
| 4915 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4916 | value = ast2obj_int(o->end_lineno); |
| 4917 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4918 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4919 | goto failed; |
| 4920 | Py_DECREF(value); |
| 4921 | value = ast2obj_int(o->end_col_offset); |
| 4922 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4923 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4924 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4925 | goto failed; |
| 4926 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4927 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4928 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4929 | Py_XDECREF(value); |
| 4930 | Py_XDECREF(result); |
| 4931 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4935 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4936 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4937 | keyword_ty o = (keyword_ty)_o; |
| 4938 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4939 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4940 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4941 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4942 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4943 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4944 | tp = (PyTypeObject *)astmodulestate_global->keyword_type; |
| 4945 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4946 | if (!result) return NULL; |
| 4947 | value = ast2obj_identifier(o->arg); |
| 4948 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4949 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4950 | goto failed; |
| 4951 | Py_DECREF(value); |
| 4952 | value = ast2obj_expr(o->value); |
| 4953 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4954 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4955 | goto failed; |
| 4956 | Py_DECREF(value); |
| 4957 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4958 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4959 | Py_XDECREF(value); |
| 4960 | Py_XDECREF(result); |
| 4961 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4962 | } |
| 4963 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4964 | PyObject* |
| 4965 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4966 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4967 | alias_ty o = (alias_ty)_o; |
| 4968 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4969 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4970 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4971 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4972 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4973 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4974 | tp = (PyTypeObject *)astmodulestate_global->alias_type; |
| 4975 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4976 | if (!result) return NULL; |
| 4977 | value = ast2obj_identifier(o->name); |
| 4978 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4979 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4980 | goto failed; |
| 4981 | Py_DECREF(value); |
| 4982 | value = ast2obj_identifier(o->asname); |
| 4983 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4984 | if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4985 | goto failed; |
| 4986 | Py_DECREF(value); |
| 4987 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4988 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4989 | Py_XDECREF(value); |
| 4990 | Py_XDECREF(result); |
| 4991 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4992 | } |
| 4993 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4994 | PyObject* |
| 4995 | ast2obj_withitem(void* _o) |
| 4996 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4997 | withitem_ty o = (withitem_ty)_o; |
| 4998 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4999 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5000 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 5001 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5002 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5003 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5004 | tp = (PyTypeObject *)astmodulestate_global->withitem_type; |
| 5005 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5006 | if (!result) return NULL; |
| 5007 | value = ast2obj_expr(o->context_expr); |
| 5008 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5009 | if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) == |
| 5010 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5011 | goto failed; |
| 5012 | Py_DECREF(value); |
| 5013 | value = ast2obj_expr(o->optional_vars); |
| 5014 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5015 | if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value) |
| 5016 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5017 | goto failed; |
| 5018 | Py_DECREF(value); |
| 5019 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5020 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5021 | Py_XDECREF(value); |
| 5022 | Py_XDECREF(result); |
| 5023 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5024 | } |
| 5025 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5026 | PyObject* |
| 5027 | ast2obj_type_ignore(void* _o) |
| 5028 | { |
| 5029 | type_ignore_ty o = (type_ignore_ty)_o; |
| 5030 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5031 | PyTypeObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5032 | if (!o) { |
| 5033 | Py_RETURN_NONE; |
| 5034 | } |
| 5035 | |
| 5036 | switch (o->kind) { |
| 5037 | case TypeIgnore_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5038 | tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type; |
| 5039 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5040 | if (!result) goto failed; |
| 5041 | value = ast2obj_int(o->v.TypeIgnore.lineno); |
| 5042 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5043 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) == |
| 5044 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5045 | goto failed; |
| 5046 | Py_DECREF(value); |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 5047 | value = ast2obj_string(o->v.TypeIgnore.tag); |
| 5048 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5049 | if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1) |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 5050 | goto failed; |
| 5051 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5052 | break; |
| 5053 | } |
| 5054 | return result; |
| 5055 | failed: |
| 5056 | Py_XDECREF(value); |
| 5057 | Py_XDECREF(result); |
| 5058 | return NULL; |
| 5059 | } |
| 5060 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5061 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5062 | int |
| 5063 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 5064 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5065 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5066 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5067 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5068 | PyObject *tp; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5069 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5070 | if (obj == Py_None) { |
| 5071 | *out = NULL; |
| 5072 | return 0; |
| 5073 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5074 | tp = astmodulestate_global->Module_type; |
| 5075 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5076 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5077 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5078 | } |
| 5079 | if (isinstance) { |
| 5080 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5081 | asdl_seq* type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5082 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5083 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5084 | return 1; |
| 5085 | } |
| 5086 | if (tmp == NULL) { |
| 5087 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 5088 | return 1; |
| 5089 | } |
| 5090 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5091 | int res; |
| 5092 | Py_ssize_t len; |
| 5093 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5094 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5095 | 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] | 5096 | goto failed; |
| 5097 | } |
| 5098 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5099 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5100 | if (body == NULL) goto failed; |
| 5101 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5102 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5103 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5104 | Py_INCREF(tmp2); |
| 5105 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5106 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5107 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5108 | if (len != PyList_GET_SIZE(tmp)) { |
| 5109 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 5110 | goto failed; |
| 5111 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5112 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5113 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5114 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5115 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5116 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores, |
| 5117 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5118 | return 1; |
| 5119 | } |
| 5120 | if (tmp == NULL) { |
| 5121 | PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module"); |
| 5122 | return 1; |
| 5123 | } |
| 5124 | else { |
| 5125 | int res; |
| 5126 | Py_ssize_t len; |
| 5127 | Py_ssize_t i; |
| 5128 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5129 | 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] | 5130 | goto failed; |
| 5131 | } |
| 5132 | len = PyList_GET_SIZE(tmp); |
| 5133 | type_ignores = _Py_asdl_seq_new(len, arena); |
| 5134 | if (type_ignores == NULL) goto failed; |
| 5135 | for (i = 0; i < len; i++) { |
| 5136 | type_ignore_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5137 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5138 | Py_INCREF(tmp2); |
| 5139 | res = obj2ast_type_ignore(tmp2, &val, arena); |
| 5140 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5141 | if (res != 0) goto failed; |
| 5142 | if (len != PyList_GET_SIZE(tmp)) { |
| 5143 | PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration"); |
| 5144 | goto failed; |
| 5145 | } |
| 5146 | asdl_seq_SET(type_ignores, i, val); |
| 5147 | } |
| 5148 | Py_CLEAR(tmp); |
| 5149 | } |
| 5150 | *out = Module(body, type_ignores, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5151 | if (*out == NULL) goto failed; |
| 5152 | return 0; |
| 5153 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5154 | tp = astmodulestate_global->Interactive_type; |
| 5155 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5156 | if (isinstance == -1) { |
| 5157 | return 1; |
| 5158 | } |
| 5159 | if (isinstance) { |
| 5160 | asdl_seq* body; |
| 5161 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5162 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5163 | return 1; |
| 5164 | } |
| 5165 | if (tmp == NULL) { |
| 5166 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 5167 | return 1; |
| 5168 | } |
| 5169 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5170 | int res; |
| 5171 | Py_ssize_t len; |
| 5172 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5173 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5174 | 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] | 5175 | goto failed; |
| 5176 | } |
| 5177 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5178 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5179 | if (body == NULL) goto failed; |
| 5180 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5181 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5182 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5183 | Py_INCREF(tmp2); |
| 5184 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5185 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5186 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5187 | if (len != PyList_GET_SIZE(tmp)) { |
| 5188 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 5189 | goto failed; |
| 5190 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5191 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5192 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5193 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5194 | } |
| 5195 | *out = Interactive(body, arena); |
| 5196 | if (*out == NULL) goto failed; |
| 5197 | return 0; |
| 5198 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5199 | tp = astmodulestate_global->Expression_type; |
| 5200 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5201 | if (isinstance == -1) { |
| 5202 | return 1; |
| 5203 | } |
| 5204 | if (isinstance) { |
| 5205 | expr_ty body; |
| 5206 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5207 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5208 | return 1; |
| 5209 | } |
| 5210 | if (tmp == NULL) { |
| 5211 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 5212 | return 1; |
| 5213 | } |
| 5214 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5215 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5216 | res = obj2ast_expr(tmp, &body, arena); |
| 5217 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5218 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5219 | } |
| 5220 | *out = Expression(body, arena); |
| 5221 | if (*out == NULL) goto failed; |
| 5222 | return 0; |
| 5223 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5224 | tp = astmodulestate_global->FunctionType_type; |
| 5225 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5226 | if (isinstance == -1) { |
| 5227 | return 1; |
| 5228 | } |
| 5229 | if (isinstance) { |
| 5230 | asdl_seq* argtypes; |
| 5231 | expr_ty returns; |
| 5232 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5233 | if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) < |
| 5234 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5235 | return 1; |
| 5236 | } |
| 5237 | if (tmp == NULL) { |
| 5238 | PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType"); |
| 5239 | return 1; |
| 5240 | } |
| 5241 | else { |
| 5242 | int res; |
| 5243 | Py_ssize_t len; |
| 5244 | Py_ssize_t i; |
| 5245 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5246 | 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] | 5247 | goto failed; |
| 5248 | } |
| 5249 | len = PyList_GET_SIZE(tmp); |
| 5250 | argtypes = _Py_asdl_seq_new(len, arena); |
| 5251 | if (argtypes == NULL) goto failed; |
| 5252 | for (i = 0; i < len; i++) { |
| 5253 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5254 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5255 | Py_INCREF(tmp2); |
| 5256 | res = obj2ast_expr(tmp2, &val, arena); |
| 5257 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5258 | if (res != 0) goto failed; |
| 5259 | if (len != PyList_GET_SIZE(tmp)) { |
| 5260 | PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration"); |
| 5261 | goto failed; |
| 5262 | } |
| 5263 | asdl_seq_SET(argtypes, i, val); |
| 5264 | } |
| 5265 | Py_CLEAR(tmp); |
| 5266 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5267 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5268 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5269 | return 1; |
| 5270 | } |
| 5271 | if (tmp == NULL) { |
| 5272 | PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType"); |
| 5273 | return 1; |
| 5274 | } |
| 5275 | else { |
| 5276 | int res; |
| 5277 | res = obj2ast_expr(tmp, &returns, arena); |
| 5278 | if (res != 0) goto failed; |
| 5279 | Py_CLEAR(tmp); |
| 5280 | } |
| 5281 | *out = FunctionType(argtypes, returns, arena); |
| 5282 | if (*out == NULL) goto failed; |
| 5283 | return 0; |
| 5284 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5285 | |
| 5286 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 5287 | failed: |
| 5288 | Py_XDECREF(tmp); |
| 5289 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | int |
| 5293 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 5294 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5295 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5296 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5297 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5298 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5299 | int lineno; |
| 5300 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5301 | int end_lineno; |
| 5302 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5303 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5304 | if (obj == Py_None) { |
| 5305 | *out = NULL; |
| 5306 | return 0; |
| 5307 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5308 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5309 | return 1; |
| 5310 | } |
| 5311 | if (tmp == NULL) { |
| 5312 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 5313 | return 1; |
| 5314 | } |
| 5315 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5316 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5317 | res = obj2ast_int(tmp, &lineno, arena); |
| 5318 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5319 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5320 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5321 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 5322 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5323 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5324 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5325 | if (tmp == NULL) { |
| 5326 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 5327 | return 1; |
| 5328 | } |
| 5329 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5330 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5331 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5332 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5333 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5334 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5335 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 5336 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5337 | return 1; |
| 5338 | } |
| 5339 | if (tmp == NULL || tmp == Py_None) { |
| 5340 | Py_CLEAR(tmp); |
| 5341 | end_lineno = 0; |
| 5342 | } |
| 5343 | else { |
| 5344 | int res; |
| 5345 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 5346 | if (res != 0) goto failed; |
| 5347 | Py_CLEAR(tmp); |
| 5348 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5349 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 5350 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5351 | return 1; |
| 5352 | } |
| 5353 | if (tmp == NULL || tmp == Py_None) { |
| 5354 | Py_CLEAR(tmp); |
| 5355 | end_col_offset = 0; |
| 5356 | } |
| 5357 | else { |
| 5358 | int res; |
| 5359 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 5360 | if (res != 0) goto failed; |
| 5361 | Py_CLEAR(tmp); |
| 5362 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5363 | tp = astmodulestate_global->FunctionDef_type; |
| 5364 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5365 | if (isinstance == -1) { |
| 5366 | return 1; |
| 5367 | } |
| 5368 | if (isinstance) { |
| 5369 | identifier name; |
| 5370 | arguments_ty args; |
| 5371 | asdl_seq* body; |
| 5372 | asdl_seq* decorator_list; |
| 5373 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5374 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5375 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5376 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5377 | return 1; |
| 5378 | } |
| 5379 | if (tmp == NULL) { |
| 5380 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 5381 | return 1; |
| 5382 | } |
| 5383 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5384 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5385 | res = obj2ast_identifier(tmp, &name, arena); |
| 5386 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5387 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5388 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5389 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5390 | return 1; |
| 5391 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5392 | if (tmp == NULL) { |
| 5393 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 5394 | return 1; |
| 5395 | } |
| 5396 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5397 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5398 | res = obj2ast_arguments(tmp, &args, arena); |
| 5399 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5400 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5401 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5402 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5403 | return 1; |
| 5404 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5405 | if (tmp == NULL) { |
| 5406 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 5407 | return 1; |
| 5408 | } |
| 5409 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5410 | int res; |
| 5411 | Py_ssize_t len; |
| 5412 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5413 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5414 | 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] | 5415 | goto failed; |
| 5416 | } |
| 5417 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5418 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5419 | if (body == NULL) goto failed; |
| 5420 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5421 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5422 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5423 | Py_INCREF(tmp2); |
| 5424 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5425 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5426 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5427 | if (len != PyList_GET_SIZE(tmp)) { |
| 5428 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 5429 | goto failed; |
| 5430 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5431 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5432 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5433 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5434 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5435 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5436 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5437 | return 1; |
| 5438 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5439 | if (tmp == NULL) { |
| 5440 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 5441 | return 1; |
| 5442 | } |
| 5443 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5444 | int res; |
| 5445 | Py_ssize_t len; |
| 5446 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5447 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5448 | 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] | 5449 | goto failed; |
| 5450 | } |
| 5451 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5452 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5453 | if (decorator_list == NULL) goto failed; |
| 5454 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5455 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5456 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5457 | Py_INCREF(tmp2); |
| 5458 | res = obj2ast_expr(tmp2, &val, arena); |
| 5459 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5460 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5461 | if (len != PyList_GET_SIZE(tmp)) { |
| 5462 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 5463 | goto failed; |
| 5464 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5465 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5466 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5467 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5468 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5469 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5470 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5471 | return 1; |
| 5472 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5473 | if (tmp == NULL || tmp == Py_None) { |
| 5474 | Py_CLEAR(tmp); |
| 5475 | returns = NULL; |
| 5476 | } |
| 5477 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5478 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5479 | res = obj2ast_expr(tmp, &returns, arena); |
| 5480 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5481 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5482 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5483 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5484 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5485 | return 1; |
| 5486 | } |
| 5487 | if (tmp == NULL || tmp == Py_None) { |
| 5488 | Py_CLEAR(tmp); |
| 5489 | type_comment = NULL; |
| 5490 | } |
| 5491 | else { |
| 5492 | int res; |
| 5493 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5494 | if (res != 0) goto failed; |
| 5495 | Py_CLEAR(tmp); |
| 5496 | } |
| 5497 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 5498 | type_comment, lineno, col_offset, end_lineno, |
| 5499 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5500 | if (*out == NULL) goto failed; |
| 5501 | return 0; |
| 5502 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5503 | tp = astmodulestate_global->AsyncFunctionDef_type; |
| 5504 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5505 | if (isinstance == -1) { |
| 5506 | return 1; |
| 5507 | } |
| 5508 | if (isinstance) { |
| 5509 | identifier name; |
| 5510 | arguments_ty args; |
| 5511 | asdl_seq* body; |
| 5512 | asdl_seq* decorator_list; |
| 5513 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5514 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5515 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5516 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5517 | return 1; |
| 5518 | } |
| 5519 | if (tmp == NULL) { |
| 5520 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 5521 | return 1; |
| 5522 | } |
| 5523 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5524 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5525 | res = obj2ast_identifier(tmp, &name, arena); |
| 5526 | if (res != 0) goto failed; |
| 5527 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5528 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5529 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5530 | return 1; |
| 5531 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5532 | if (tmp == NULL) { |
| 5533 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 5534 | return 1; |
| 5535 | } |
| 5536 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5537 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5538 | res = obj2ast_arguments(tmp, &args, arena); |
| 5539 | if (res != 0) goto failed; |
| 5540 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5541 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5542 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5543 | return 1; |
| 5544 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5545 | if (tmp == NULL) { |
| 5546 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 5547 | return 1; |
| 5548 | } |
| 5549 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5550 | int res; |
| 5551 | Py_ssize_t len; |
| 5552 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5553 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5554 | 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] | 5555 | goto failed; |
| 5556 | } |
| 5557 | len = PyList_GET_SIZE(tmp); |
| 5558 | body = _Py_asdl_seq_new(len, arena); |
| 5559 | if (body == NULL) goto failed; |
| 5560 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5561 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5562 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5563 | Py_INCREF(tmp2); |
| 5564 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5565 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5566 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5567 | if (len != PyList_GET_SIZE(tmp)) { |
| 5568 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 5569 | goto failed; |
| 5570 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5571 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5572 | } |
| 5573 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5574 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5575 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5576 | &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5577 | return 1; |
| 5578 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5579 | if (tmp == NULL) { |
| 5580 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 5581 | return 1; |
| 5582 | } |
| 5583 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5584 | int res; |
| 5585 | Py_ssize_t len; |
| 5586 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5587 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5588 | 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] | 5589 | goto failed; |
| 5590 | } |
| 5591 | len = PyList_GET_SIZE(tmp); |
| 5592 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 5593 | if (decorator_list == NULL) goto failed; |
| 5594 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5595 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5596 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5597 | Py_INCREF(tmp2); |
| 5598 | res = obj2ast_expr(tmp2, &val, arena); |
| 5599 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5600 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5601 | if (len != PyList_GET_SIZE(tmp)) { |
| 5602 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 5603 | goto failed; |
| 5604 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5605 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5606 | } |
| 5607 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5608 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5609 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5610 | 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5611 | return 1; |
| 5612 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5613 | if (tmp == NULL || tmp == Py_None) { |
| 5614 | Py_CLEAR(tmp); |
| 5615 | returns = NULL; |
| 5616 | } |
| 5617 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5618 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5619 | res = obj2ast_expr(tmp, &returns, arena); |
| 5620 | if (res != 0) goto failed; |
| 5621 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5622 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5623 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5624 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5625 | return 1; |
| 5626 | } |
| 5627 | if (tmp == NULL || tmp == Py_None) { |
| 5628 | Py_CLEAR(tmp); |
| 5629 | type_comment = NULL; |
| 5630 | } |
| 5631 | else { |
| 5632 | int res; |
| 5633 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5634 | if (res != 0) goto failed; |
| 5635 | Py_CLEAR(tmp); |
| 5636 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5637 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5638 | type_comment, lineno, col_offset, end_lineno, |
| 5639 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5640 | if (*out == NULL) goto failed; |
| 5641 | return 0; |
| 5642 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5643 | tp = astmodulestate_global->ClassDef_type; |
| 5644 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5645 | if (isinstance == -1) { |
| 5646 | return 1; |
| 5647 | } |
| 5648 | if (isinstance) { |
| 5649 | identifier name; |
| 5650 | asdl_seq* bases; |
| 5651 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5652 | asdl_seq* body; |
| 5653 | asdl_seq* decorator_list; |
| 5654 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5655 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5656 | return 1; |
| 5657 | } |
| 5658 | if (tmp == NULL) { |
| 5659 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 5660 | return 1; |
| 5661 | } |
| 5662 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5663 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5664 | res = obj2ast_identifier(tmp, &name, arena); |
| 5665 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5666 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5667 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5668 | if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5669 | return 1; |
| 5670 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5671 | if (tmp == NULL) { |
| 5672 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 5673 | return 1; |
| 5674 | } |
| 5675 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5676 | int res; |
| 5677 | Py_ssize_t len; |
| 5678 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5679 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5680 | 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] | 5681 | goto failed; |
| 5682 | } |
| 5683 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5684 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5685 | if (bases == NULL) goto failed; |
| 5686 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5687 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5688 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5689 | Py_INCREF(tmp2); |
| 5690 | res = obj2ast_expr(tmp2, &val, arena); |
| 5691 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5692 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5693 | if (len != PyList_GET_SIZE(tmp)) { |
| 5694 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 5695 | goto failed; |
| 5696 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5697 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5698 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5699 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5700 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5701 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 5702 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5703 | return 1; |
| 5704 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5705 | if (tmp == NULL) { |
| 5706 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 5707 | return 1; |
| 5708 | } |
| 5709 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5710 | int res; |
| 5711 | Py_ssize_t len; |
| 5712 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5713 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5714 | 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] | 5715 | goto failed; |
| 5716 | } |
| 5717 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5718 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5719 | if (keywords == NULL) goto failed; |
| 5720 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5721 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5722 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5723 | Py_INCREF(tmp2); |
| 5724 | res = obj2ast_keyword(tmp2, &val, arena); |
| 5725 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5726 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5727 | if (len != PyList_GET_SIZE(tmp)) { |
| 5728 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 5729 | goto failed; |
| 5730 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5731 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5732 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5733 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5734 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5735 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5736 | return 1; |
| 5737 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5738 | if (tmp == NULL) { |
| 5739 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 5740 | return 1; |
| 5741 | } |
| 5742 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5743 | int res; |
| 5744 | Py_ssize_t len; |
| 5745 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5746 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5747 | 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] | 5748 | goto failed; |
| 5749 | } |
| 5750 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5751 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5752 | if (body == NULL) goto failed; |
| 5753 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5754 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5755 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5756 | Py_INCREF(tmp2); |
| 5757 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5758 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5759 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5760 | if (len != PyList_GET_SIZE(tmp)) { |
| 5761 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 5762 | goto failed; |
| 5763 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5764 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5765 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5766 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5767 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5768 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5769 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5770 | return 1; |
| 5771 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5772 | if (tmp == NULL) { |
| 5773 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 5774 | return 1; |
| 5775 | } |
| 5776 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5777 | int res; |
| 5778 | Py_ssize_t len; |
| 5779 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5780 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5781 | 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] | 5782 | goto failed; |
| 5783 | } |
| 5784 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5785 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5786 | if (decorator_list == NULL) goto failed; |
| 5787 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5788 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5789 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5790 | Py_INCREF(tmp2); |
| 5791 | res = obj2ast_expr(tmp2, &val, arena); |
| 5792 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5793 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5794 | if (len != PyList_GET_SIZE(tmp)) { |
| 5795 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
| 5796 | goto failed; |
| 5797 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5798 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5799 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5800 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5801 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 5802 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5803 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5804 | if (*out == NULL) goto failed; |
| 5805 | return 0; |
| 5806 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5807 | tp = astmodulestate_global->Return_type; |
| 5808 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5809 | if (isinstance == -1) { |
| 5810 | return 1; |
| 5811 | } |
| 5812 | if (isinstance) { |
| 5813 | expr_ty value; |
| 5814 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5815 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5816 | return 1; |
| 5817 | } |
| 5818 | if (tmp == NULL || tmp == Py_None) { |
| 5819 | Py_CLEAR(tmp); |
| 5820 | value = NULL; |
| 5821 | } |
| 5822 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5823 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5824 | res = obj2ast_expr(tmp, &value, arena); |
| 5825 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5826 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5827 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5828 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 5829 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5830 | if (*out == NULL) goto failed; |
| 5831 | return 0; |
| 5832 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5833 | tp = astmodulestate_global->Delete_type; |
| 5834 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5835 | if (isinstance == -1) { |
| 5836 | return 1; |
| 5837 | } |
| 5838 | if (isinstance) { |
| 5839 | asdl_seq* targets; |
| 5840 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5841 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5842 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5843 | return 1; |
| 5844 | } |
| 5845 | if (tmp == NULL) { |
| 5846 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 5847 | return 1; |
| 5848 | } |
| 5849 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5850 | int res; |
| 5851 | Py_ssize_t len; |
| 5852 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5853 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5854 | 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] | 5855 | goto failed; |
| 5856 | } |
| 5857 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5858 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5859 | if (targets == NULL) goto failed; |
| 5860 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5861 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5862 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5863 | Py_INCREF(tmp2); |
| 5864 | res = obj2ast_expr(tmp2, &val, arena); |
| 5865 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5866 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5867 | if (len != PyList_GET_SIZE(tmp)) { |
| 5868 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 5869 | goto failed; |
| 5870 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5871 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5872 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5873 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5874 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5875 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 5876 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5877 | if (*out == NULL) goto failed; |
| 5878 | return 0; |
| 5879 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5880 | tp = astmodulestate_global->Assign_type; |
| 5881 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5882 | if (isinstance == -1) { |
| 5883 | return 1; |
| 5884 | } |
| 5885 | if (isinstance) { |
| 5886 | asdl_seq* targets; |
| 5887 | expr_ty value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5888 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5889 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5890 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5891 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5892 | return 1; |
| 5893 | } |
| 5894 | if (tmp == NULL) { |
| 5895 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 5896 | return 1; |
| 5897 | } |
| 5898 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5899 | int res; |
| 5900 | Py_ssize_t len; |
| 5901 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5902 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5903 | 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] | 5904 | goto failed; |
| 5905 | } |
| 5906 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5907 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5908 | if (targets == NULL) goto failed; |
| 5909 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5910 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5911 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5912 | Py_INCREF(tmp2); |
| 5913 | res = obj2ast_expr(tmp2, &val, arena); |
| 5914 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5915 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5916 | if (len != PyList_GET_SIZE(tmp)) { |
| 5917 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 5918 | goto failed; |
| 5919 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5920 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5921 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5922 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5923 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5924 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5925 | return 1; |
| 5926 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5927 | if (tmp == NULL) { |
| 5928 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 5929 | return 1; |
| 5930 | } |
| 5931 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5932 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5933 | res = obj2ast_expr(tmp, &value, arena); |
| 5934 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5935 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5936 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5937 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5938 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5939 | return 1; |
| 5940 | } |
| 5941 | if (tmp == NULL || tmp == Py_None) { |
| 5942 | Py_CLEAR(tmp); |
| 5943 | type_comment = NULL; |
| 5944 | } |
| 5945 | else { |
| 5946 | int res; |
| 5947 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5948 | if (res != 0) goto failed; |
| 5949 | Py_CLEAR(tmp); |
| 5950 | } |
| 5951 | *out = Assign(targets, value, type_comment, lineno, col_offset, |
| 5952 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5953 | if (*out == NULL) goto failed; |
| 5954 | return 0; |
| 5955 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5956 | tp = astmodulestate_global->AugAssign_type; |
| 5957 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5958 | if (isinstance == -1) { |
| 5959 | return 1; |
| 5960 | } |
| 5961 | if (isinstance) { |
| 5962 | expr_ty target; |
| 5963 | operator_ty op; |
| 5964 | expr_ty value; |
| 5965 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5966 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 5967 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5968 | return 1; |
| 5969 | } |
| 5970 | if (tmp == NULL) { |
| 5971 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 5972 | return 1; |
| 5973 | } |
| 5974 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5975 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5976 | res = obj2ast_expr(tmp, &target, arena); |
| 5977 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5978 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5979 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5980 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5981 | return 1; |
| 5982 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5983 | if (tmp == NULL) { |
| 5984 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 5985 | return 1; |
| 5986 | } |
| 5987 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5988 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5989 | res = obj2ast_operator(tmp, &op, arena); |
| 5990 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5991 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5992 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5993 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5994 | return 1; |
| 5995 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5996 | if (tmp == NULL) { |
| 5997 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 5998 | return 1; |
| 5999 | } |
| 6000 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6001 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6002 | res = obj2ast_expr(tmp, &value, arena); |
| 6003 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6004 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6005 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6006 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 6007 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6008 | if (*out == NULL) goto failed; |
| 6009 | return 0; |
| 6010 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6011 | tp = astmodulestate_global->AnnAssign_type; |
| 6012 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6013 | if (isinstance == -1) { |
| 6014 | return 1; |
| 6015 | } |
| 6016 | if (isinstance) { |
| 6017 | expr_ty target; |
| 6018 | expr_ty annotation; |
| 6019 | expr_ty value; |
| 6020 | int simple; |
| 6021 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6022 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6023 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6024 | return 1; |
| 6025 | } |
| 6026 | if (tmp == NULL) { |
| 6027 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 6028 | return 1; |
| 6029 | } |
| 6030 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6031 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6032 | res = obj2ast_expr(tmp, &target, arena); |
| 6033 | if (res != 0) goto failed; |
| 6034 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6035 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6036 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) |
| 6037 | < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6038 | return 1; |
| 6039 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6040 | if (tmp == NULL) { |
| 6041 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 6042 | return 1; |
| 6043 | } |
| 6044 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6045 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6046 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6047 | if (res != 0) goto failed; |
| 6048 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6049 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6050 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6051 | return 1; |
| 6052 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6053 | if (tmp == NULL || tmp == Py_None) { |
| 6054 | Py_CLEAR(tmp); |
| 6055 | value = NULL; |
| 6056 | } |
| 6057 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6058 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6059 | res = obj2ast_expr(tmp, &value, arena); |
| 6060 | if (res != 0) goto failed; |
| 6061 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6062 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6063 | if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0) |
| 6064 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6065 | return 1; |
| 6066 | } |
| 6067 | if (tmp == NULL) { |
| 6068 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 6069 | return 1; |
| 6070 | } |
| 6071 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6072 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6073 | res = obj2ast_int(tmp, &simple, arena); |
| 6074 | if (res != 0) goto failed; |
| 6075 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6076 | } |
| 6077 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6078 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6079 | if (*out == NULL) goto failed; |
| 6080 | return 0; |
| 6081 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6082 | tp = astmodulestate_global->For_type; |
| 6083 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6084 | if (isinstance == -1) { |
| 6085 | return 1; |
| 6086 | } |
| 6087 | if (isinstance) { |
| 6088 | expr_ty target; |
| 6089 | expr_ty iter; |
| 6090 | asdl_seq* body; |
| 6091 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6092 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6093 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6094 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6095 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6096 | return 1; |
| 6097 | } |
| 6098 | if (tmp == NULL) { |
| 6099 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 6100 | return 1; |
| 6101 | } |
| 6102 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6103 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6104 | res = obj2ast_expr(tmp, &target, arena); |
| 6105 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6106 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6107 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6108 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6109 | return 1; |
| 6110 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6111 | if (tmp == NULL) { |
| 6112 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 6113 | return 1; |
| 6114 | } |
| 6115 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6116 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6117 | res = obj2ast_expr(tmp, &iter, arena); |
| 6118 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6119 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6120 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6121 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6122 | return 1; |
| 6123 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6124 | if (tmp == NULL) { |
| 6125 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 6126 | return 1; |
| 6127 | } |
| 6128 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6129 | int res; |
| 6130 | Py_ssize_t len; |
| 6131 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6132 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6133 | 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] | 6134 | goto failed; |
| 6135 | } |
| 6136 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6137 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6138 | if (body == NULL) goto failed; |
| 6139 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6140 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6141 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6142 | Py_INCREF(tmp2); |
| 6143 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6144 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6145 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6146 | if (len != PyList_GET_SIZE(tmp)) { |
| 6147 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 6148 | goto failed; |
| 6149 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6150 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6151 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6152 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6153 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6154 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6155 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6156 | return 1; |
| 6157 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6158 | if (tmp == NULL) { |
| 6159 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 6160 | return 1; |
| 6161 | } |
| 6162 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6163 | int res; |
| 6164 | Py_ssize_t len; |
| 6165 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6166 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6167 | 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] | 6168 | goto failed; |
| 6169 | } |
| 6170 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6171 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6172 | if (orelse == NULL) goto failed; |
| 6173 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6174 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6175 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6176 | Py_INCREF(tmp2); |
| 6177 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6178 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6179 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6180 | if (len != PyList_GET_SIZE(tmp)) { |
| 6181 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 6182 | goto failed; |
| 6183 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6184 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6185 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6186 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6187 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6188 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6189 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6190 | return 1; |
| 6191 | } |
| 6192 | if (tmp == NULL || tmp == Py_None) { |
| 6193 | Py_CLEAR(tmp); |
| 6194 | type_comment = NULL; |
| 6195 | } |
| 6196 | else { |
| 6197 | int res; |
| 6198 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6199 | if (res != 0) goto failed; |
| 6200 | Py_CLEAR(tmp); |
| 6201 | } |
| 6202 | *out = For(target, iter, body, orelse, type_comment, lineno, |
| 6203 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6204 | if (*out == NULL) goto failed; |
| 6205 | return 0; |
| 6206 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6207 | tp = astmodulestate_global->AsyncFor_type; |
| 6208 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6209 | if (isinstance == -1) { |
| 6210 | return 1; |
| 6211 | } |
| 6212 | if (isinstance) { |
| 6213 | expr_ty target; |
| 6214 | expr_ty iter; |
| 6215 | asdl_seq* body; |
| 6216 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6217 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6218 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6219 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6220 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6221 | return 1; |
| 6222 | } |
| 6223 | if (tmp == NULL) { |
| 6224 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 6225 | return 1; |
| 6226 | } |
| 6227 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6228 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6229 | res = obj2ast_expr(tmp, &target, arena); |
| 6230 | if (res != 0) goto failed; |
| 6231 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6232 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6233 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6234 | return 1; |
| 6235 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6236 | if (tmp == NULL) { |
| 6237 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 6238 | return 1; |
| 6239 | } |
| 6240 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6241 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6242 | res = obj2ast_expr(tmp, &iter, arena); |
| 6243 | if (res != 0) goto failed; |
| 6244 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6245 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6246 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6247 | return 1; |
| 6248 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6249 | if (tmp == NULL) { |
| 6250 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 6251 | return 1; |
| 6252 | } |
| 6253 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6254 | int res; |
| 6255 | Py_ssize_t len; |
| 6256 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6257 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6258 | 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] | 6259 | goto failed; |
| 6260 | } |
| 6261 | len = PyList_GET_SIZE(tmp); |
| 6262 | body = _Py_asdl_seq_new(len, arena); |
| 6263 | if (body == NULL) goto failed; |
| 6264 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6265 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6266 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6267 | Py_INCREF(tmp2); |
| 6268 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6269 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6270 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6271 | if (len != PyList_GET_SIZE(tmp)) { |
| 6272 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 6273 | goto failed; |
| 6274 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6275 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6276 | } |
| 6277 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6278 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6279 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6280 | { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6281 | return 1; |
| 6282 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6283 | if (tmp == NULL) { |
| 6284 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 6285 | return 1; |
| 6286 | } |
| 6287 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6288 | int res; |
| 6289 | Py_ssize_t len; |
| 6290 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6291 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6292 | 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] | 6293 | goto failed; |
| 6294 | } |
| 6295 | len = PyList_GET_SIZE(tmp); |
| 6296 | orelse = _Py_asdl_seq_new(len, arena); |
| 6297 | if (orelse == NULL) goto failed; |
| 6298 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6299 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6300 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6301 | Py_INCREF(tmp2); |
| 6302 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6303 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6304 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6305 | if (len != PyList_GET_SIZE(tmp)) { |
| 6306 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 6307 | goto failed; |
| 6308 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6309 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6310 | } |
| 6311 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6312 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6313 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6314 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6315 | return 1; |
| 6316 | } |
| 6317 | if (tmp == NULL || tmp == Py_None) { |
| 6318 | Py_CLEAR(tmp); |
| 6319 | type_comment = NULL; |
| 6320 | } |
| 6321 | else { |
| 6322 | int res; |
| 6323 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6324 | if (res != 0) goto failed; |
| 6325 | Py_CLEAR(tmp); |
| 6326 | } |
| 6327 | *out = AsyncFor(target, iter, body, orelse, type_comment, lineno, |
| 6328 | col_offset, end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6329 | if (*out == NULL) goto failed; |
| 6330 | return 0; |
| 6331 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6332 | tp = astmodulestate_global->While_type; |
| 6333 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6334 | if (isinstance == -1) { |
| 6335 | return 1; |
| 6336 | } |
| 6337 | if (isinstance) { |
| 6338 | expr_ty test; |
| 6339 | asdl_seq* body; |
| 6340 | asdl_seq* orelse; |
| 6341 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6342 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6343 | return 1; |
| 6344 | } |
| 6345 | if (tmp == NULL) { |
| 6346 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 6347 | return 1; |
| 6348 | } |
| 6349 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6350 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6351 | res = obj2ast_expr(tmp, &test, arena); |
| 6352 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6353 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6354 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6355 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6356 | return 1; |
| 6357 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6358 | if (tmp == NULL) { |
| 6359 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 6360 | return 1; |
| 6361 | } |
| 6362 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6363 | int res; |
| 6364 | Py_ssize_t len; |
| 6365 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6366 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6367 | 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] | 6368 | goto failed; |
| 6369 | } |
| 6370 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6371 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6372 | if (body == NULL) goto failed; |
| 6373 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6374 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6375 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6376 | Py_INCREF(tmp2); |
| 6377 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6378 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6379 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6380 | if (len != PyList_GET_SIZE(tmp)) { |
| 6381 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 6382 | goto failed; |
| 6383 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6384 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6385 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6386 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6387 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6388 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6389 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6390 | return 1; |
| 6391 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6392 | if (tmp == NULL) { |
| 6393 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 6394 | return 1; |
| 6395 | } |
| 6396 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6397 | int res; |
| 6398 | Py_ssize_t len; |
| 6399 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6400 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6401 | 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] | 6402 | goto failed; |
| 6403 | } |
| 6404 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6405 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6406 | if (orelse == NULL) goto failed; |
| 6407 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6408 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6409 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6410 | Py_INCREF(tmp2); |
| 6411 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6412 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6413 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6414 | if (len != PyList_GET_SIZE(tmp)) { |
| 6415 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 6416 | goto failed; |
| 6417 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6418 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6419 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6420 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6421 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6422 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 6423 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6424 | if (*out == NULL) goto failed; |
| 6425 | return 0; |
| 6426 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6427 | tp = astmodulestate_global->If_type; |
| 6428 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6429 | if (isinstance == -1) { |
| 6430 | return 1; |
| 6431 | } |
| 6432 | if (isinstance) { |
| 6433 | expr_ty test; |
| 6434 | asdl_seq* body; |
| 6435 | asdl_seq* orelse; |
| 6436 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6437 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6438 | return 1; |
| 6439 | } |
| 6440 | if (tmp == NULL) { |
| 6441 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 6442 | return 1; |
| 6443 | } |
| 6444 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6445 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6446 | res = obj2ast_expr(tmp, &test, arena); |
| 6447 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6448 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6449 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6450 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6451 | return 1; |
| 6452 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6453 | if (tmp == NULL) { |
| 6454 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 6455 | return 1; |
| 6456 | } |
| 6457 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6458 | int res; |
| 6459 | Py_ssize_t len; |
| 6460 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6461 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6462 | 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] | 6463 | goto failed; |
| 6464 | } |
| 6465 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6466 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6467 | if (body == NULL) goto failed; |
| 6468 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6469 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6470 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6471 | Py_INCREF(tmp2); |
| 6472 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6473 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6474 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6475 | if (len != PyList_GET_SIZE(tmp)) { |
| 6476 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 6477 | goto failed; |
| 6478 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6479 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6480 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6481 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6482 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6483 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6484 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6485 | return 1; |
| 6486 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6487 | if (tmp == NULL) { |
| 6488 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 6489 | return 1; |
| 6490 | } |
| 6491 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6492 | int res; |
| 6493 | Py_ssize_t len; |
| 6494 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6495 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6496 | 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] | 6497 | goto failed; |
| 6498 | } |
| 6499 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6500 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6501 | if (orelse == NULL) goto failed; |
| 6502 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6503 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6504 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6505 | Py_INCREF(tmp2); |
| 6506 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6507 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6508 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6509 | if (len != PyList_GET_SIZE(tmp)) { |
| 6510 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 6511 | goto failed; |
| 6512 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6513 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6514 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6515 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6516 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6517 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 6518 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6519 | if (*out == NULL) goto failed; |
| 6520 | return 0; |
| 6521 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6522 | tp = astmodulestate_global->With_type; |
| 6523 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6524 | if (isinstance == -1) { |
| 6525 | return 1; |
| 6526 | } |
| 6527 | if (isinstance) { |
| 6528 | asdl_seq* items; |
| 6529 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6530 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6531 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6532 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6533 | return 1; |
| 6534 | } |
| 6535 | if (tmp == NULL) { |
| 6536 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 6537 | return 1; |
| 6538 | } |
| 6539 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6540 | int res; |
| 6541 | Py_ssize_t len; |
| 6542 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6543 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6544 | 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] | 6545 | goto failed; |
| 6546 | } |
| 6547 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6548 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6549 | if (items == NULL) goto failed; |
| 6550 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6551 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6552 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6553 | Py_INCREF(tmp2); |
| 6554 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6555 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6556 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6557 | if (len != PyList_GET_SIZE(tmp)) { |
| 6558 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 6559 | goto failed; |
| 6560 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6561 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6562 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6563 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6564 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6565 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6566 | return 1; |
| 6567 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6568 | if (tmp == NULL) { |
| 6569 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 6570 | return 1; |
| 6571 | } |
| 6572 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6573 | int res; |
| 6574 | Py_ssize_t len; |
| 6575 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6576 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6577 | 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] | 6578 | goto failed; |
| 6579 | } |
| 6580 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6581 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6582 | if (body == NULL) goto failed; |
| 6583 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6584 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6585 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6586 | Py_INCREF(tmp2); |
| 6587 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6588 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6589 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6590 | if (len != PyList_GET_SIZE(tmp)) { |
| 6591 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 6592 | goto failed; |
| 6593 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6594 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6595 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6596 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6597 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6598 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6599 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6600 | return 1; |
| 6601 | } |
| 6602 | if (tmp == NULL || tmp == Py_None) { |
| 6603 | Py_CLEAR(tmp); |
| 6604 | type_comment = NULL; |
| 6605 | } |
| 6606 | else { |
| 6607 | int res; |
| 6608 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6609 | if (res != 0) goto failed; |
| 6610 | Py_CLEAR(tmp); |
| 6611 | } |
| 6612 | *out = With(items, body, type_comment, lineno, col_offset, end_lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6613 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6614 | if (*out == NULL) goto failed; |
| 6615 | return 0; |
| 6616 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6617 | tp = astmodulestate_global->AsyncWith_type; |
| 6618 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6619 | if (isinstance == -1) { |
| 6620 | return 1; |
| 6621 | } |
| 6622 | if (isinstance) { |
| 6623 | asdl_seq* items; |
| 6624 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6625 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6626 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6627 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6628 | return 1; |
| 6629 | } |
| 6630 | if (tmp == NULL) { |
| 6631 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 6632 | return 1; |
| 6633 | } |
| 6634 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6635 | int res; |
| 6636 | Py_ssize_t len; |
| 6637 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6638 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6639 | 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] | 6640 | goto failed; |
| 6641 | } |
| 6642 | len = PyList_GET_SIZE(tmp); |
| 6643 | items = _Py_asdl_seq_new(len, arena); |
| 6644 | if (items == NULL) goto failed; |
| 6645 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6646 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6647 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6648 | Py_INCREF(tmp2); |
| 6649 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6650 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6651 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6652 | if (len != PyList_GET_SIZE(tmp)) { |
| 6653 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 6654 | goto failed; |
| 6655 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6656 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6657 | } |
| 6658 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6659 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6660 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6661 | return 1; |
| 6662 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6663 | if (tmp == NULL) { |
| 6664 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 6665 | return 1; |
| 6666 | } |
| 6667 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6668 | int res; |
| 6669 | Py_ssize_t len; |
| 6670 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6671 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6672 | 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] | 6673 | goto failed; |
| 6674 | } |
| 6675 | len = PyList_GET_SIZE(tmp); |
| 6676 | body = _Py_asdl_seq_new(len, arena); |
| 6677 | if (body == NULL) goto failed; |
| 6678 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6679 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6680 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6681 | Py_INCREF(tmp2); |
| 6682 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6683 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6684 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6685 | if (len != PyList_GET_SIZE(tmp)) { |
| 6686 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 6687 | goto failed; |
| 6688 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6689 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6690 | } |
| 6691 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6692 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6693 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6694 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6695 | return 1; |
| 6696 | } |
| 6697 | if (tmp == NULL || tmp == Py_None) { |
| 6698 | Py_CLEAR(tmp); |
| 6699 | type_comment = NULL; |
| 6700 | } |
| 6701 | else { |
| 6702 | int res; |
| 6703 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6704 | if (res != 0) goto failed; |
| 6705 | Py_CLEAR(tmp); |
| 6706 | } |
| 6707 | *out = AsyncWith(items, body, type_comment, lineno, col_offset, |
| 6708 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6709 | if (*out == NULL) goto failed; |
| 6710 | return 0; |
| 6711 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6712 | tp = astmodulestate_global->Raise_type; |
| 6713 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6714 | if (isinstance == -1) { |
| 6715 | return 1; |
| 6716 | } |
| 6717 | if (isinstance) { |
| 6718 | expr_ty exc; |
| 6719 | expr_ty cause; |
| 6720 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6721 | if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6722 | return 1; |
| 6723 | } |
| 6724 | if (tmp == NULL || tmp == Py_None) { |
| 6725 | Py_CLEAR(tmp); |
| 6726 | exc = NULL; |
| 6727 | } |
| 6728 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6729 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6730 | res = obj2ast_expr(tmp, &exc, arena); |
| 6731 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6732 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6733 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6734 | if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6735 | return 1; |
| 6736 | } |
| 6737 | if (tmp == NULL || tmp == Py_None) { |
| 6738 | Py_CLEAR(tmp); |
| 6739 | cause = NULL; |
| 6740 | } |
| 6741 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6742 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6743 | res = obj2ast_expr(tmp, &cause, arena); |
| 6744 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6745 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6746 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6747 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 6748 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6749 | if (*out == NULL) goto failed; |
| 6750 | return 0; |
| 6751 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6752 | tp = astmodulestate_global->Try_type; |
| 6753 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6754 | if (isinstance == -1) { |
| 6755 | return 1; |
| 6756 | } |
| 6757 | if (isinstance) { |
| 6758 | asdl_seq* body; |
| 6759 | asdl_seq* handlers; |
| 6760 | asdl_seq* orelse; |
| 6761 | asdl_seq* finalbody; |
| 6762 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6763 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6764 | return 1; |
| 6765 | } |
| 6766 | if (tmp == NULL) { |
| 6767 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 6768 | return 1; |
| 6769 | } |
| 6770 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6771 | int res; |
| 6772 | Py_ssize_t len; |
| 6773 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6774 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6775 | 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] | 6776 | goto failed; |
| 6777 | } |
| 6778 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6779 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6780 | if (body == NULL) goto failed; |
| 6781 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6782 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6783 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6784 | Py_INCREF(tmp2); |
| 6785 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6786 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6787 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6788 | if (len != PyList_GET_SIZE(tmp)) { |
| 6789 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 6790 | goto failed; |
| 6791 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6792 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6793 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6794 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6795 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6796 | if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) < |
| 6797 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6798 | return 1; |
| 6799 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6800 | if (tmp == NULL) { |
| 6801 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 6802 | return 1; |
| 6803 | } |
| 6804 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6805 | int res; |
| 6806 | Py_ssize_t len; |
| 6807 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6808 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6809 | 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] | 6810 | goto failed; |
| 6811 | } |
| 6812 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6813 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6814 | if (handlers == NULL) goto failed; |
| 6815 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6816 | excepthandler_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6817 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6818 | Py_INCREF(tmp2); |
| 6819 | res = obj2ast_excepthandler(tmp2, &val, arena); |
| 6820 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6821 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6822 | if (len != PyList_GET_SIZE(tmp)) { |
| 6823 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 6824 | goto failed; |
| 6825 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6826 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6827 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6828 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6829 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6830 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6831 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6832 | return 1; |
| 6833 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6834 | if (tmp == NULL) { |
| 6835 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 6836 | return 1; |
| 6837 | } |
| 6838 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6839 | int res; |
| 6840 | Py_ssize_t len; |
| 6841 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6842 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6843 | 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] | 6844 | goto failed; |
| 6845 | } |
| 6846 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6847 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6848 | if (orelse == NULL) goto failed; |
| 6849 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6850 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6851 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6852 | Py_INCREF(tmp2); |
| 6853 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6854 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6855 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6856 | if (len != PyList_GET_SIZE(tmp)) { |
| 6857 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 6858 | goto failed; |
| 6859 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6860 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6861 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6862 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6863 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6864 | if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) < |
| 6865 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6866 | return 1; |
| 6867 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6868 | if (tmp == NULL) { |
| 6869 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 6870 | return 1; |
| 6871 | } |
| 6872 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6873 | int res; |
| 6874 | Py_ssize_t len; |
| 6875 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6876 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6877 | 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] | 6878 | goto failed; |
| 6879 | } |
| 6880 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6881 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6882 | if (finalbody == NULL) goto failed; |
| 6883 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6884 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6885 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6886 | Py_INCREF(tmp2); |
| 6887 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6888 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6889 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6890 | if (len != PyList_GET_SIZE(tmp)) { |
| 6891 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 6892 | goto failed; |
| 6893 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6894 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6895 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6896 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6897 | } |
| 6898 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6899 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6900 | if (*out == NULL) goto failed; |
| 6901 | return 0; |
| 6902 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6903 | tp = astmodulestate_global->Assert_type; |
| 6904 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6905 | if (isinstance == -1) { |
| 6906 | return 1; |
| 6907 | } |
| 6908 | if (isinstance) { |
| 6909 | expr_ty test; |
| 6910 | expr_ty msg; |
| 6911 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6912 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6913 | return 1; |
| 6914 | } |
| 6915 | if (tmp == NULL) { |
| 6916 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 6917 | return 1; |
| 6918 | } |
| 6919 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6920 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6921 | res = obj2ast_expr(tmp, &test, arena); |
| 6922 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6923 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6924 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6925 | if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6926 | return 1; |
| 6927 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6928 | if (tmp == NULL || tmp == Py_None) { |
| 6929 | Py_CLEAR(tmp); |
| 6930 | msg = NULL; |
| 6931 | } |
| 6932 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6933 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6934 | res = obj2ast_expr(tmp, &msg, arena); |
| 6935 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6936 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6937 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6938 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 6939 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6940 | if (*out == NULL) goto failed; |
| 6941 | return 0; |
| 6942 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6943 | tp = astmodulestate_global->Import_type; |
| 6944 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6945 | if (isinstance == -1) { |
| 6946 | return 1; |
| 6947 | } |
| 6948 | if (isinstance) { |
| 6949 | asdl_seq* names; |
| 6950 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6951 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6952 | return 1; |
| 6953 | } |
| 6954 | if (tmp == NULL) { |
| 6955 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 6956 | return 1; |
| 6957 | } |
| 6958 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6959 | int res; |
| 6960 | Py_ssize_t len; |
| 6961 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6962 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6963 | 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] | 6964 | goto failed; |
| 6965 | } |
| 6966 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6967 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6968 | if (names == NULL) goto failed; |
| 6969 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6970 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6971 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6972 | Py_INCREF(tmp2); |
| 6973 | res = obj2ast_alias(tmp2, &val, arena); |
| 6974 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6975 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6976 | if (len != PyList_GET_SIZE(tmp)) { |
| 6977 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 6978 | goto failed; |
| 6979 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6980 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6981 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6982 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6983 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6984 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6985 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6986 | if (*out == NULL) goto failed; |
| 6987 | return 0; |
| 6988 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6989 | tp = astmodulestate_global->ImportFrom_type; |
| 6990 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6991 | if (isinstance == -1) { |
| 6992 | return 1; |
| 6993 | } |
| 6994 | if (isinstance) { |
| 6995 | identifier module; |
| 6996 | asdl_seq* names; |
| 6997 | int level; |
| 6998 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6999 | if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0) |
| 7000 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7001 | return 1; |
| 7002 | } |
| 7003 | if (tmp == NULL || tmp == Py_None) { |
| 7004 | Py_CLEAR(tmp); |
| 7005 | module = NULL; |
| 7006 | } |
| 7007 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7008 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7009 | res = obj2ast_identifier(tmp, &module, arena); |
| 7010 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7011 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7012 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7013 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7014 | return 1; |
| 7015 | } |
| 7016 | if (tmp == NULL) { |
| 7017 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 7018 | return 1; |
| 7019 | } |
| 7020 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7021 | int res; |
| 7022 | Py_ssize_t len; |
| 7023 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7024 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7025 | 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] | 7026 | goto failed; |
| 7027 | } |
| 7028 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7029 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7030 | if (names == NULL) goto failed; |
| 7031 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7032 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7033 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7034 | Py_INCREF(tmp2); |
| 7035 | res = obj2ast_alias(tmp2, &val, arena); |
| 7036 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7037 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7038 | if (len != PyList_GET_SIZE(tmp)) { |
| 7039 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 7040 | goto failed; |
| 7041 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7042 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7043 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7044 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7045 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7046 | if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7047 | return 1; |
| 7048 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7049 | if (tmp == NULL || tmp == Py_None) { |
| 7050 | Py_CLEAR(tmp); |
| 7051 | level = 0; |
| 7052 | } |
| 7053 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7054 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7055 | res = obj2ast_int(tmp, &level, arena); |
| 7056 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7057 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7058 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7059 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 7060 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7061 | if (*out == NULL) goto failed; |
| 7062 | return 0; |
| 7063 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7064 | tp = astmodulestate_global->Global_type; |
| 7065 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7066 | if (isinstance == -1) { |
| 7067 | return 1; |
| 7068 | } |
| 7069 | if (isinstance) { |
| 7070 | asdl_seq* names; |
| 7071 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7072 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7073 | return 1; |
| 7074 | } |
| 7075 | if (tmp == NULL) { |
| 7076 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 7077 | return 1; |
| 7078 | } |
| 7079 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7080 | int res; |
| 7081 | Py_ssize_t len; |
| 7082 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7083 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7084 | 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] | 7085 | goto failed; |
| 7086 | } |
| 7087 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7088 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7089 | if (names == NULL) goto failed; |
| 7090 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7091 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7092 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7093 | Py_INCREF(tmp2); |
| 7094 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7095 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7096 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7097 | if (len != PyList_GET_SIZE(tmp)) { |
| 7098 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 7099 | goto failed; |
| 7100 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7101 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7102 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7103 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7104 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7105 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7106 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7107 | if (*out == NULL) goto failed; |
| 7108 | return 0; |
| 7109 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7110 | tp = astmodulestate_global->Nonlocal_type; |
| 7111 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7112 | if (isinstance == -1) { |
| 7113 | return 1; |
| 7114 | } |
| 7115 | if (isinstance) { |
| 7116 | asdl_seq* names; |
| 7117 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7118 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7119 | return 1; |
| 7120 | } |
| 7121 | if (tmp == NULL) { |
| 7122 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 7123 | return 1; |
| 7124 | } |
| 7125 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7126 | int res; |
| 7127 | Py_ssize_t len; |
| 7128 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7129 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7130 | 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] | 7131 | goto failed; |
| 7132 | } |
| 7133 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7134 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7135 | if (names == NULL) goto failed; |
| 7136 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7137 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7138 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7139 | Py_INCREF(tmp2); |
| 7140 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7141 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7142 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7143 | if (len != PyList_GET_SIZE(tmp)) { |
| 7144 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 7145 | goto failed; |
| 7146 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7147 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7148 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7149 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7150 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7151 | *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7152 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7153 | if (*out == NULL) goto failed; |
| 7154 | return 0; |
| 7155 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7156 | tp = astmodulestate_global->Expr_type; |
| 7157 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7158 | if (isinstance == -1) { |
| 7159 | return 1; |
| 7160 | } |
| 7161 | if (isinstance) { |
| 7162 | expr_ty value; |
| 7163 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7164 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7165 | return 1; |
| 7166 | } |
| 7167 | if (tmp == NULL) { |
| 7168 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 7169 | return 1; |
| 7170 | } |
| 7171 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7172 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7173 | res = obj2ast_expr(tmp, &value, arena); |
| 7174 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7175 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7176 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7177 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7178 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7179 | if (*out == NULL) goto failed; |
| 7180 | return 0; |
| 7181 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7182 | tp = astmodulestate_global->Pass_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 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7189 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7190 | if (*out == NULL) goto failed; |
| 7191 | return 0; |
| 7192 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7193 | tp = astmodulestate_global->Break_type; |
| 7194 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7195 | if (isinstance == -1) { |
| 7196 | return 1; |
| 7197 | } |
| 7198 | if (isinstance) { |
| 7199 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7200 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7201 | if (*out == NULL) goto failed; |
| 7202 | return 0; |
| 7203 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7204 | tp = astmodulestate_global->Continue_type; |
| 7205 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7206 | if (isinstance == -1) { |
| 7207 | return 1; |
| 7208 | } |
| 7209 | if (isinstance) { |
| 7210 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7211 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7212 | if (*out == NULL) goto failed; |
| 7213 | return 0; |
| 7214 | } |
| 7215 | |
| 7216 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 7217 | failed: |
| 7218 | Py_XDECREF(tmp); |
| 7219 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7220 | } |
| 7221 | |
| 7222 | int |
| 7223 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 7224 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7225 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7226 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7227 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7228 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7229 | int lineno; |
| 7230 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7231 | int end_lineno; |
| 7232 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7233 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7234 | if (obj == Py_None) { |
| 7235 | *out = NULL; |
| 7236 | return 0; |
| 7237 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7238 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7239 | return 1; |
| 7240 | } |
| 7241 | if (tmp == NULL) { |
| 7242 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 7243 | return 1; |
| 7244 | } |
| 7245 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7246 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7247 | res = obj2ast_int(tmp, &lineno, arena); |
| 7248 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7249 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7250 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7251 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 7252 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7253 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7254 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7255 | if (tmp == NULL) { |
| 7256 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 7257 | return 1; |
| 7258 | } |
| 7259 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7260 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7261 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7262 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7263 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7264 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7265 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 7266 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7267 | return 1; |
| 7268 | } |
| 7269 | if (tmp == NULL || tmp == Py_None) { |
| 7270 | Py_CLEAR(tmp); |
| 7271 | end_lineno = 0; |
| 7272 | } |
| 7273 | else { |
| 7274 | int res; |
| 7275 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 7276 | if (res != 0) goto failed; |
| 7277 | Py_CLEAR(tmp); |
| 7278 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7279 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 7280 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7281 | return 1; |
| 7282 | } |
| 7283 | if (tmp == NULL || tmp == Py_None) { |
| 7284 | Py_CLEAR(tmp); |
| 7285 | end_col_offset = 0; |
| 7286 | } |
| 7287 | else { |
| 7288 | int res; |
| 7289 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 7290 | if (res != 0) goto failed; |
| 7291 | Py_CLEAR(tmp); |
| 7292 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7293 | tp = astmodulestate_global->BoolOp_type; |
| 7294 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7295 | if (isinstance == -1) { |
| 7296 | return 1; |
| 7297 | } |
| 7298 | if (isinstance) { |
| 7299 | boolop_ty op; |
| 7300 | asdl_seq* values; |
| 7301 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7302 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7303 | return 1; |
| 7304 | } |
| 7305 | if (tmp == NULL) { |
| 7306 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 7307 | return 1; |
| 7308 | } |
| 7309 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7310 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7311 | res = obj2ast_boolop(tmp, &op, arena); |
| 7312 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7313 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7314 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7315 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7316 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7317 | return 1; |
| 7318 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7319 | if (tmp == NULL) { |
| 7320 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 7321 | return 1; |
| 7322 | } |
| 7323 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7324 | int res; |
| 7325 | Py_ssize_t len; |
| 7326 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7327 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7328 | 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] | 7329 | goto failed; |
| 7330 | } |
| 7331 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7332 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7333 | if (values == NULL) goto failed; |
| 7334 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7335 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7336 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7337 | Py_INCREF(tmp2); |
| 7338 | res = obj2ast_expr(tmp2, &val, arena); |
| 7339 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7340 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7341 | if (len != PyList_GET_SIZE(tmp)) { |
| 7342 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 7343 | goto failed; |
| 7344 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7345 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7346 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7347 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7348 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7349 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 7350 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7351 | if (*out == NULL) goto failed; |
| 7352 | return 0; |
| 7353 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7354 | tp = astmodulestate_global->NamedExpr_type; |
| 7355 | isinstance = PyObject_IsInstance(obj, tp); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7356 | if (isinstance == -1) { |
| 7357 | return 1; |
| 7358 | } |
| 7359 | if (isinstance) { |
| 7360 | expr_ty target; |
| 7361 | expr_ty value; |
| 7362 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7363 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 7364 | { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7365 | return 1; |
| 7366 | } |
| 7367 | if (tmp == NULL) { |
| 7368 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); |
| 7369 | return 1; |
| 7370 | } |
| 7371 | else { |
| 7372 | int res; |
| 7373 | res = obj2ast_expr(tmp, &target, arena); |
| 7374 | if (res != 0) goto failed; |
| 7375 | Py_CLEAR(tmp); |
| 7376 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7377 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7378 | return 1; |
| 7379 | } |
| 7380 | if (tmp == NULL) { |
| 7381 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); |
| 7382 | return 1; |
| 7383 | } |
| 7384 | else { |
| 7385 | int res; |
| 7386 | res = obj2ast_expr(tmp, &value, arena); |
| 7387 | if (res != 0) goto failed; |
| 7388 | Py_CLEAR(tmp); |
| 7389 | } |
| 7390 | *out = NamedExpr(target, value, lineno, col_offset, end_lineno, |
| 7391 | end_col_offset, arena); |
| 7392 | if (*out == NULL) goto failed; |
| 7393 | return 0; |
| 7394 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7395 | tp = astmodulestate_global->BinOp_type; |
| 7396 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7397 | if (isinstance == -1) { |
| 7398 | return 1; |
| 7399 | } |
| 7400 | if (isinstance) { |
| 7401 | expr_ty left; |
| 7402 | operator_ty op; |
| 7403 | expr_ty right; |
| 7404 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7405 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7406 | return 1; |
| 7407 | } |
| 7408 | if (tmp == NULL) { |
| 7409 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 7410 | return 1; |
| 7411 | } |
| 7412 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7413 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7414 | res = obj2ast_expr(tmp, &left, arena); |
| 7415 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7416 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7417 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7418 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7419 | return 1; |
| 7420 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7421 | if (tmp == NULL) { |
| 7422 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 7423 | return 1; |
| 7424 | } |
| 7425 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7426 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7427 | res = obj2ast_operator(tmp, &op, arena); |
| 7428 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7429 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7430 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7431 | if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7432 | return 1; |
| 7433 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7434 | if (tmp == NULL) { |
| 7435 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 7436 | return 1; |
| 7437 | } |
| 7438 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7439 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7440 | res = obj2ast_expr(tmp, &right, arena); |
| 7441 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7442 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7443 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7444 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 7445 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7446 | if (*out == NULL) goto failed; |
| 7447 | return 0; |
| 7448 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7449 | tp = astmodulestate_global->UnaryOp_type; |
| 7450 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7451 | if (isinstance == -1) { |
| 7452 | return 1; |
| 7453 | } |
| 7454 | if (isinstance) { |
| 7455 | unaryop_ty op; |
| 7456 | expr_ty operand; |
| 7457 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7458 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7459 | return 1; |
| 7460 | } |
| 7461 | if (tmp == NULL) { |
| 7462 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 7463 | return 1; |
| 7464 | } |
| 7465 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7466 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7467 | res = obj2ast_unaryop(tmp, &op, arena); |
| 7468 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7469 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7470 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7471 | if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) < |
| 7472 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7473 | return 1; |
| 7474 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7475 | if (tmp == NULL) { |
| 7476 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 7477 | return 1; |
| 7478 | } |
| 7479 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7480 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7481 | res = obj2ast_expr(tmp, &operand, arena); |
| 7482 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7483 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7484 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7485 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 7486 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7487 | if (*out == NULL) goto failed; |
| 7488 | return 0; |
| 7489 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7490 | tp = astmodulestate_global->Lambda_type; |
| 7491 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7492 | if (isinstance == -1) { |
| 7493 | return 1; |
| 7494 | } |
| 7495 | if (isinstance) { |
| 7496 | arguments_ty args; |
| 7497 | expr_ty body; |
| 7498 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7499 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7500 | return 1; |
| 7501 | } |
| 7502 | if (tmp == NULL) { |
| 7503 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 7504 | return 1; |
| 7505 | } |
| 7506 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7507 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7508 | res = obj2ast_arguments(tmp, &args, arena); |
| 7509 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7510 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7511 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7512 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7513 | return 1; |
| 7514 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7515 | if (tmp == NULL) { |
| 7516 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 7517 | return 1; |
| 7518 | } |
| 7519 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7520 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7521 | res = obj2ast_expr(tmp, &body, arena); |
| 7522 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7523 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7524 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7525 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 7526 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7527 | if (*out == NULL) goto failed; |
| 7528 | return 0; |
| 7529 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7530 | tp = astmodulestate_global->IfExp_type; |
| 7531 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7532 | if (isinstance == -1) { |
| 7533 | return 1; |
| 7534 | } |
| 7535 | if (isinstance) { |
| 7536 | expr_ty test; |
| 7537 | expr_ty body; |
| 7538 | expr_ty orelse; |
| 7539 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7540 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7541 | return 1; |
| 7542 | } |
| 7543 | if (tmp == NULL) { |
| 7544 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 7545 | return 1; |
| 7546 | } |
| 7547 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7548 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7549 | res = obj2ast_expr(tmp, &test, arena); |
| 7550 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7551 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7552 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7553 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7554 | return 1; |
| 7555 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7556 | if (tmp == NULL) { |
| 7557 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 7558 | return 1; |
| 7559 | } |
| 7560 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7561 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7562 | res = obj2ast_expr(tmp, &body, arena); |
| 7563 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7564 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7565 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7566 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 7567 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7568 | return 1; |
| 7569 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7570 | if (tmp == NULL) { |
| 7571 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 7572 | return 1; |
| 7573 | } |
| 7574 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7575 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7576 | res = obj2ast_expr(tmp, &orelse, arena); |
| 7577 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7578 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7579 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7580 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 7581 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7582 | if (*out == NULL) goto failed; |
| 7583 | return 0; |
| 7584 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7585 | tp = astmodulestate_global->Dict_type; |
| 7586 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7587 | if (isinstance == -1) { |
| 7588 | return 1; |
| 7589 | } |
| 7590 | if (isinstance) { |
| 7591 | asdl_seq* keys; |
| 7592 | asdl_seq* values; |
| 7593 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7594 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7595 | return 1; |
| 7596 | } |
| 7597 | if (tmp == NULL) { |
| 7598 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 7599 | return 1; |
| 7600 | } |
| 7601 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7602 | int res; |
| 7603 | Py_ssize_t len; |
| 7604 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7605 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7606 | 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] | 7607 | goto failed; |
| 7608 | } |
| 7609 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7610 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7611 | if (keys == NULL) goto failed; |
| 7612 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7613 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7614 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7615 | Py_INCREF(tmp2); |
| 7616 | res = obj2ast_expr(tmp2, &val, arena); |
| 7617 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7618 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7619 | if (len != PyList_GET_SIZE(tmp)) { |
| 7620 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 7621 | goto failed; |
| 7622 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7623 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7624 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7625 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7626 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7627 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7628 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7629 | return 1; |
| 7630 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7631 | if (tmp == NULL) { |
| 7632 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 7633 | return 1; |
| 7634 | } |
| 7635 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7636 | int res; |
| 7637 | Py_ssize_t len; |
| 7638 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7639 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7640 | 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] | 7641 | goto failed; |
| 7642 | } |
| 7643 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7644 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7645 | if (values == NULL) goto failed; |
| 7646 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7647 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7648 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7649 | Py_INCREF(tmp2); |
| 7650 | res = obj2ast_expr(tmp2, &val, arena); |
| 7651 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7652 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7653 | if (len != PyList_GET_SIZE(tmp)) { |
| 7654 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 7655 | goto failed; |
| 7656 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7657 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7658 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7659 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7660 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7661 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 7662 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7663 | if (*out == NULL) goto failed; |
| 7664 | return 0; |
| 7665 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7666 | tp = astmodulestate_global->Set_type; |
| 7667 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7668 | if (isinstance == -1) { |
| 7669 | return 1; |
| 7670 | } |
| 7671 | if (isinstance) { |
| 7672 | asdl_seq* elts; |
| 7673 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7674 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7675 | return 1; |
| 7676 | } |
| 7677 | if (tmp == NULL) { |
| 7678 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 7679 | return 1; |
| 7680 | } |
| 7681 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7682 | int res; |
| 7683 | Py_ssize_t len; |
| 7684 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7685 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7686 | 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] | 7687 | goto failed; |
| 7688 | } |
| 7689 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7690 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7691 | if (elts == NULL) goto failed; |
| 7692 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7693 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7694 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7695 | Py_INCREF(tmp2); |
| 7696 | res = obj2ast_expr(tmp2, &val, arena); |
| 7697 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7698 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7699 | if (len != PyList_GET_SIZE(tmp)) { |
| 7700 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 7701 | goto failed; |
| 7702 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7703 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7704 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7705 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7706 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7707 | *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7708 | if (*out == NULL) goto failed; |
| 7709 | return 0; |
| 7710 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7711 | tp = astmodulestate_global->ListComp_type; |
| 7712 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7713 | if (isinstance == -1) { |
| 7714 | return 1; |
| 7715 | } |
| 7716 | if (isinstance) { |
| 7717 | expr_ty elt; |
| 7718 | asdl_seq* generators; |
| 7719 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7720 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7721 | return 1; |
| 7722 | } |
| 7723 | if (tmp == NULL) { |
| 7724 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 7725 | return 1; |
| 7726 | } |
| 7727 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7728 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7729 | res = obj2ast_expr(tmp, &elt, arena); |
| 7730 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7731 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7732 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7733 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7734 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7735 | return 1; |
| 7736 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7737 | if (tmp == NULL) { |
| 7738 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 7739 | return 1; |
| 7740 | } |
| 7741 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7742 | int res; |
| 7743 | Py_ssize_t len; |
| 7744 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7745 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7746 | 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] | 7747 | goto failed; |
| 7748 | } |
| 7749 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7750 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7751 | if (generators == NULL) goto failed; |
| 7752 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7753 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7754 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7755 | Py_INCREF(tmp2); |
| 7756 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7757 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7758 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7759 | if (len != PyList_GET_SIZE(tmp)) { |
| 7760 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 7761 | goto failed; |
| 7762 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7763 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7764 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7765 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7766 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7767 | *out = ListComp(elt, generators, lineno, col_offset, end_lineno, |
| 7768 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7769 | if (*out == NULL) goto failed; |
| 7770 | return 0; |
| 7771 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7772 | tp = astmodulestate_global->SetComp_type; |
| 7773 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7774 | if (isinstance == -1) { |
| 7775 | return 1; |
| 7776 | } |
| 7777 | if (isinstance) { |
| 7778 | expr_ty elt; |
| 7779 | asdl_seq* generators; |
| 7780 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7781 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7782 | return 1; |
| 7783 | } |
| 7784 | if (tmp == NULL) { |
| 7785 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 7786 | return 1; |
| 7787 | } |
| 7788 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7789 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7790 | res = obj2ast_expr(tmp, &elt, arena); |
| 7791 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7792 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7793 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7794 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7795 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7796 | return 1; |
| 7797 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7798 | if (tmp == NULL) { |
| 7799 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 7800 | return 1; |
| 7801 | } |
| 7802 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7803 | int res; |
| 7804 | Py_ssize_t len; |
| 7805 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7806 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7807 | 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] | 7808 | goto failed; |
| 7809 | } |
| 7810 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7811 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7812 | if (generators == NULL) goto failed; |
| 7813 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7814 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7815 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7816 | Py_INCREF(tmp2); |
| 7817 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7818 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7819 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7820 | if (len != PyList_GET_SIZE(tmp)) { |
| 7821 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 7822 | goto failed; |
| 7823 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7824 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7825 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7826 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7827 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7828 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 7829 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7830 | if (*out == NULL) goto failed; |
| 7831 | return 0; |
| 7832 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7833 | tp = astmodulestate_global->DictComp_type; |
| 7834 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7835 | if (isinstance == -1) { |
| 7836 | return 1; |
| 7837 | } |
| 7838 | if (isinstance) { |
| 7839 | expr_ty key; |
| 7840 | expr_ty value; |
| 7841 | asdl_seq* generators; |
| 7842 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7843 | if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7844 | return 1; |
| 7845 | } |
| 7846 | if (tmp == NULL) { |
| 7847 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 7848 | return 1; |
| 7849 | } |
| 7850 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7851 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7852 | res = obj2ast_expr(tmp, &key, arena); |
| 7853 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7854 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7855 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7856 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7857 | return 1; |
| 7858 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7859 | if (tmp == NULL) { |
| 7860 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 7861 | return 1; |
| 7862 | } |
| 7863 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7864 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7865 | res = obj2ast_expr(tmp, &value, arena); |
| 7866 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7867 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7868 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7869 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7870 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7871 | return 1; |
| 7872 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7873 | if (tmp == NULL) { |
| 7874 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 7875 | return 1; |
| 7876 | } |
| 7877 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7878 | int res; |
| 7879 | Py_ssize_t len; |
| 7880 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7881 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7882 | 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] | 7883 | goto failed; |
| 7884 | } |
| 7885 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7886 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7887 | if (generators == NULL) goto failed; |
| 7888 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7889 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7890 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7891 | Py_INCREF(tmp2); |
| 7892 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7893 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7894 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7895 | if (len != PyList_GET_SIZE(tmp)) { |
| 7896 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 7897 | goto failed; |
| 7898 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7899 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7900 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7901 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7902 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7903 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 7904 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7905 | if (*out == NULL) goto failed; |
| 7906 | return 0; |
| 7907 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7908 | tp = astmodulestate_global->GeneratorExp_type; |
| 7909 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7910 | if (isinstance == -1) { |
| 7911 | return 1; |
| 7912 | } |
| 7913 | if (isinstance) { |
| 7914 | expr_ty elt; |
| 7915 | asdl_seq* generators; |
| 7916 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7917 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7918 | return 1; |
| 7919 | } |
| 7920 | if (tmp == NULL) { |
| 7921 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 7922 | return 1; |
| 7923 | } |
| 7924 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7925 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7926 | res = obj2ast_expr(tmp, &elt, arena); |
| 7927 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7928 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7929 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7930 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7931 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7932 | return 1; |
| 7933 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7934 | if (tmp == NULL) { |
| 7935 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 7936 | return 1; |
| 7937 | } |
| 7938 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7939 | int res; |
| 7940 | Py_ssize_t len; |
| 7941 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7942 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7943 | 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] | 7944 | goto failed; |
| 7945 | } |
| 7946 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7947 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7948 | if (generators == NULL) goto failed; |
| 7949 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7950 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7951 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7952 | Py_INCREF(tmp2); |
| 7953 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7954 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7955 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7956 | if (len != PyList_GET_SIZE(tmp)) { |
| 7957 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 7958 | goto failed; |
| 7959 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7960 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7961 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7962 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7963 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7964 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 7965 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7966 | if (*out == NULL) goto failed; |
| 7967 | return 0; |
| 7968 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7969 | tp = astmodulestate_global->Await_type; |
| 7970 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7971 | if (isinstance == -1) { |
| 7972 | return 1; |
| 7973 | } |
| 7974 | if (isinstance) { |
| 7975 | expr_ty value; |
| 7976 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7977 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7978 | return 1; |
| 7979 | } |
| 7980 | if (tmp == NULL) { |
| 7981 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 7982 | return 1; |
| 7983 | } |
| 7984 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7985 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7986 | res = obj2ast_expr(tmp, &value, arena); |
| 7987 | if (res != 0) goto failed; |
| 7988 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7989 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7990 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7991 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7992 | if (*out == NULL) goto failed; |
| 7993 | return 0; |
| 7994 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7995 | tp = astmodulestate_global->Yield_type; |
| 7996 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7997 | if (isinstance == -1) { |
| 7998 | return 1; |
| 7999 | } |
| 8000 | if (isinstance) { |
| 8001 | expr_ty value; |
| 8002 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8003 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8004 | return 1; |
| 8005 | } |
| 8006 | if (tmp == NULL || tmp == Py_None) { |
| 8007 | Py_CLEAR(tmp); |
| 8008 | value = NULL; |
| 8009 | } |
| 8010 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8011 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8012 | res = obj2ast_expr(tmp, &value, arena); |
| 8013 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8014 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8015 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8016 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8017 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8018 | if (*out == NULL) goto failed; |
| 8019 | return 0; |
| 8020 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8021 | tp = astmodulestate_global->YieldFrom_type; |
| 8022 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8023 | if (isinstance == -1) { |
| 8024 | return 1; |
| 8025 | } |
| 8026 | if (isinstance) { |
| 8027 | expr_ty value; |
| 8028 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8029 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8030 | return 1; |
| 8031 | } |
| 8032 | if (tmp == NULL) { |
| 8033 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 8034 | return 1; |
| 8035 | } |
| 8036 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8037 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8038 | res = obj2ast_expr(tmp, &value, arena); |
| 8039 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8040 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8041 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8042 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8043 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8044 | if (*out == NULL) goto failed; |
| 8045 | return 0; |
| 8046 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8047 | tp = astmodulestate_global->Compare_type; |
| 8048 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8049 | if (isinstance == -1) { |
| 8050 | return 1; |
| 8051 | } |
| 8052 | if (isinstance) { |
| 8053 | expr_ty left; |
| 8054 | asdl_int_seq* ops; |
| 8055 | asdl_seq* comparators; |
| 8056 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8057 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8058 | return 1; |
| 8059 | } |
| 8060 | if (tmp == NULL) { |
| 8061 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 8062 | return 1; |
| 8063 | } |
| 8064 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8065 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8066 | res = obj2ast_expr(tmp, &left, arena); |
| 8067 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8068 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8069 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8070 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8071 | return 1; |
| 8072 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8073 | if (tmp == NULL) { |
| 8074 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 8075 | return 1; |
| 8076 | } |
| 8077 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8078 | int res; |
| 8079 | Py_ssize_t len; |
| 8080 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8081 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8082 | 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] | 8083 | goto failed; |
| 8084 | } |
| 8085 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8086 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8087 | if (ops == NULL) goto failed; |
| 8088 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8089 | cmpop_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8090 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8091 | Py_INCREF(tmp2); |
| 8092 | res = obj2ast_cmpop(tmp2, &val, arena); |
| 8093 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8094 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8095 | if (len != PyList_GET_SIZE(tmp)) { |
| 8096 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 8097 | goto failed; |
| 8098 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8099 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8100 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8101 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8102 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8103 | if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp) |
| 8104 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8105 | return 1; |
| 8106 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8107 | if (tmp == NULL) { |
| 8108 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 8109 | return 1; |
| 8110 | } |
| 8111 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8112 | int res; |
| 8113 | Py_ssize_t len; |
| 8114 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8115 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8116 | 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] | 8117 | goto failed; |
| 8118 | } |
| 8119 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8120 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8121 | if (comparators == NULL) goto failed; |
| 8122 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8123 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8124 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8125 | Py_INCREF(tmp2); |
| 8126 | res = obj2ast_expr(tmp2, &val, arena); |
| 8127 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8128 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8129 | if (len != PyList_GET_SIZE(tmp)) { |
| 8130 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 8131 | goto failed; |
| 8132 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8133 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8134 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8135 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8136 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8137 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 8138 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8139 | if (*out == NULL) goto failed; |
| 8140 | return 0; |
| 8141 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8142 | tp = astmodulestate_global->Call_type; |
| 8143 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8144 | if (isinstance == -1) { |
| 8145 | return 1; |
| 8146 | } |
| 8147 | if (isinstance) { |
| 8148 | expr_ty func; |
| 8149 | asdl_seq* args; |
| 8150 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8151 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8152 | if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8153 | return 1; |
| 8154 | } |
| 8155 | if (tmp == NULL) { |
| 8156 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 8157 | return 1; |
| 8158 | } |
| 8159 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8160 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8161 | res = obj2ast_expr(tmp, &func, arena); |
| 8162 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8163 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8164 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8165 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8166 | return 1; |
| 8167 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8168 | if (tmp == NULL) { |
| 8169 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 8170 | return 1; |
| 8171 | } |
| 8172 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8173 | int res; |
| 8174 | Py_ssize_t len; |
| 8175 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8176 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8177 | 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] | 8178 | goto failed; |
| 8179 | } |
| 8180 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8181 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8182 | if (args == NULL) goto failed; |
| 8183 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8184 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8185 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8186 | Py_INCREF(tmp2); |
| 8187 | res = obj2ast_expr(tmp2, &val, arena); |
| 8188 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8189 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8190 | if (len != PyList_GET_SIZE(tmp)) { |
| 8191 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 8192 | goto failed; |
| 8193 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8194 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8195 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8196 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8197 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8198 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 8199 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8200 | return 1; |
| 8201 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8202 | if (tmp == NULL) { |
| 8203 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 8204 | return 1; |
| 8205 | } |
| 8206 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8207 | int res; |
| 8208 | Py_ssize_t len; |
| 8209 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8210 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8211 | 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] | 8212 | goto failed; |
| 8213 | } |
| 8214 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8215 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8216 | if (keywords == NULL) goto failed; |
| 8217 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8218 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8219 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8220 | Py_INCREF(tmp2); |
| 8221 | res = obj2ast_keyword(tmp2, &val, arena); |
| 8222 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8223 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8224 | if (len != PyList_GET_SIZE(tmp)) { |
| 8225 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 8226 | goto failed; |
| 8227 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8228 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8229 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8230 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8231 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8232 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 8233 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8234 | if (*out == NULL) goto failed; |
| 8235 | return 0; |
| 8236 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8237 | tp = astmodulestate_global->FormattedValue_type; |
| 8238 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8239 | if (isinstance == -1) { |
| 8240 | return 1; |
| 8241 | } |
| 8242 | if (isinstance) { |
| 8243 | expr_ty value; |
| 8244 | int conversion; |
| 8245 | expr_ty format_spec; |
| 8246 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8247 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8248 | return 1; |
| 8249 | } |
| 8250 | if (tmp == NULL) { |
| 8251 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 8252 | return 1; |
| 8253 | } |
| 8254 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8255 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8256 | res = obj2ast_expr(tmp, &value, arena); |
| 8257 | if (res != 0) goto failed; |
| 8258 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8259 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8260 | if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp) |
| 8261 | < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8262 | return 1; |
| 8263 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8264 | if (tmp == NULL || tmp == Py_None) { |
| 8265 | Py_CLEAR(tmp); |
| 8266 | conversion = 0; |
| 8267 | } |
| 8268 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8269 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8270 | res = obj2ast_int(tmp, &conversion, arena); |
| 8271 | if (res != 0) goto failed; |
| 8272 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8273 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8274 | if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp) |
| 8275 | < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8276 | return 1; |
| 8277 | } |
| 8278 | if (tmp == NULL || tmp == Py_None) { |
| 8279 | Py_CLEAR(tmp); |
| 8280 | format_spec = NULL; |
| 8281 | } |
| 8282 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8283 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8284 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 8285 | if (res != 0) goto failed; |
| 8286 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8287 | } |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 8288 | *out = FormattedValue(value, conversion, format_spec, lineno, |
| 8289 | col_offset, end_lineno, end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8290 | if (*out == NULL) goto failed; |
| 8291 | return 0; |
| 8292 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8293 | tp = astmodulestate_global->JoinedStr_type; |
| 8294 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8295 | if (isinstance == -1) { |
| 8296 | return 1; |
| 8297 | } |
| 8298 | if (isinstance) { |
| 8299 | asdl_seq* values; |
| 8300 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8301 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 8302 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8303 | return 1; |
| 8304 | } |
| 8305 | if (tmp == NULL) { |
| 8306 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 8307 | return 1; |
| 8308 | } |
| 8309 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8310 | int res; |
| 8311 | Py_ssize_t len; |
| 8312 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8313 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8314 | 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] | 8315 | goto failed; |
| 8316 | } |
| 8317 | len = PyList_GET_SIZE(tmp); |
| 8318 | values = _Py_asdl_seq_new(len, arena); |
| 8319 | if (values == NULL) goto failed; |
| 8320 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8321 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8322 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8323 | Py_INCREF(tmp2); |
| 8324 | res = obj2ast_expr(tmp2, &val, arena); |
| 8325 | Py_DECREF(tmp2); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8326 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 8327 | if (len != PyList_GET_SIZE(tmp)) { |
| 8328 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 8329 | goto failed; |
| 8330 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8331 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8332 | } |
| 8333 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8334 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8335 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 8336 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8337 | if (*out == NULL) goto failed; |
| 8338 | return 0; |
| 8339 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8340 | tp = astmodulestate_global->Constant_type; |
| 8341 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8342 | if (isinstance == -1) { |
| 8343 | return 1; |
| 8344 | } |
| 8345 | if (isinstance) { |
| 8346 | constant value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8347 | string kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8348 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8349 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8350 | return 1; |
| 8351 | } |
| 8352 | if (tmp == NULL) { |
| 8353 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 8354 | return 1; |
| 8355 | } |
| 8356 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8357 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8358 | res = obj2ast_constant(tmp, &value, arena); |
| 8359 | if (res != 0) goto failed; |
| 8360 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8361 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8362 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) { |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8363 | return 1; |
| 8364 | } |
| 8365 | if (tmp == NULL || tmp == Py_None) { |
| 8366 | Py_CLEAR(tmp); |
| 8367 | kind = NULL; |
| 8368 | } |
| 8369 | else { |
| 8370 | int res; |
| 8371 | res = obj2ast_string(tmp, &kind, arena); |
| 8372 | if (res != 0) goto failed; |
| 8373 | Py_CLEAR(tmp); |
| 8374 | } |
| 8375 | *out = Constant(value, kind, lineno, col_offset, end_lineno, |
| 8376 | end_col_offset, arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8377 | if (*out == NULL) goto failed; |
| 8378 | return 0; |
| 8379 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8380 | tp = astmodulestate_global->Attribute_type; |
| 8381 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8382 | if (isinstance == -1) { |
| 8383 | return 1; |
| 8384 | } |
| 8385 | if (isinstance) { |
| 8386 | expr_ty value; |
| 8387 | identifier attr; |
| 8388 | expr_context_ty ctx; |
| 8389 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8390 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8391 | return 1; |
| 8392 | } |
| 8393 | if (tmp == NULL) { |
| 8394 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 8395 | return 1; |
| 8396 | } |
| 8397 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8398 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8399 | res = obj2ast_expr(tmp, &value, arena); |
| 8400 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8401 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8402 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8403 | if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8404 | return 1; |
| 8405 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8406 | if (tmp == NULL) { |
| 8407 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 8408 | return 1; |
| 8409 | } |
| 8410 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8411 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8412 | res = obj2ast_identifier(tmp, &attr, arena); |
| 8413 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8414 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8415 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8416 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8417 | return 1; |
| 8418 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8419 | if (tmp == NULL) { |
| 8420 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 8421 | return 1; |
| 8422 | } |
| 8423 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8424 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8425 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8426 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8427 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8428 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8429 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 8430 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8431 | if (*out == NULL) goto failed; |
| 8432 | return 0; |
| 8433 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8434 | tp = astmodulestate_global->Subscript_type; |
| 8435 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8436 | if (isinstance == -1) { |
| 8437 | return 1; |
| 8438 | } |
| 8439 | if (isinstance) { |
| 8440 | expr_ty value; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8441 | expr_ty slice; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8442 | expr_context_ty ctx; |
| 8443 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8444 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8445 | return 1; |
| 8446 | } |
| 8447 | if (tmp == NULL) { |
| 8448 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 8449 | return 1; |
| 8450 | } |
| 8451 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8452 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8453 | res = obj2ast_expr(tmp, &value, arena); |
| 8454 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8455 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8456 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8457 | if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8458 | return 1; |
| 8459 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8460 | if (tmp == NULL) { |
| 8461 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 8462 | return 1; |
| 8463 | } |
| 8464 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8465 | int res; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8466 | res = obj2ast_expr(tmp, &slice, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8467 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8468 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8469 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8470 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8471 | return 1; |
| 8472 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8473 | if (tmp == NULL) { |
| 8474 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 8475 | return 1; |
| 8476 | } |
| 8477 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8478 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8479 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8480 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8481 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8482 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8483 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 8484 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8485 | if (*out == NULL) goto failed; |
| 8486 | return 0; |
| 8487 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8488 | tp = astmodulestate_global->Starred_type; |
| 8489 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8490 | if (isinstance == -1) { |
| 8491 | return 1; |
| 8492 | } |
| 8493 | if (isinstance) { |
| 8494 | expr_ty value; |
| 8495 | expr_context_ty ctx; |
| 8496 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8497 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8498 | return 1; |
| 8499 | } |
| 8500 | if (tmp == NULL) { |
| 8501 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 8502 | return 1; |
| 8503 | } |
| 8504 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8505 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8506 | res = obj2ast_expr(tmp, &value, arena); |
| 8507 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8508 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8509 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8510 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8511 | return 1; |
| 8512 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8513 | if (tmp == NULL) { |
| 8514 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 8515 | return 1; |
| 8516 | } |
| 8517 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8518 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8519 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8520 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8521 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8522 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8523 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 8524 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8525 | if (*out == NULL) goto failed; |
| 8526 | return 0; |
| 8527 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8528 | tp = astmodulestate_global->Name_type; |
| 8529 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8530 | if (isinstance == -1) { |
| 8531 | return 1; |
| 8532 | } |
| 8533 | if (isinstance) { |
| 8534 | identifier id; |
| 8535 | expr_context_ty ctx; |
| 8536 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8537 | if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8538 | return 1; |
| 8539 | } |
| 8540 | if (tmp == NULL) { |
| 8541 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 8542 | return 1; |
| 8543 | } |
| 8544 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8545 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8546 | res = obj2ast_identifier(tmp, &id, arena); |
| 8547 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8548 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8549 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8550 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8551 | return 1; |
| 8552 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8553 | if (tmp == NULL) { |
| 8554 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 8555 | return 1; |
| 8556 | } |
| 8557 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8558 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8559 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8560 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8561 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8562 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8563 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8564 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8565 | if (*out == NULL) goto failed; |
| 8566 | return 0; |
| 8567 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8568 | tp = astmodulestate_global->List_type; |
| 8569 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8570 | if (isinstance == -1) { |
| 8571 | return 1; |
| 8572 | } |
| 8573 | if (isinstance) { |
| 8574 | asdl_seq* elts; |
| 8575 | expr_context_ty ctx; |
| 8576 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8577 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8578 | return 1; |
| 8579 | } |
| 8580 | if (tmp == NULL) { |
| 8581 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 8582 | return 1; |
| 8583 | } |
| 8584 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8585 | int res; |
| 8586 | Py_ssize_t len; |
| 8587 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8588 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8589 | 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] | 8590 | goto failed; |
| 8591 | } |
| 8592 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8593 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8594 | if (elts == NULL) goto failed; |
| 8595 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8596 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8597 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8598 | Py_INCREF(tmp2); |
| 8599 | res = obj2ast_expr(tmp2, &val, arena); |
| 8600 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8601 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8602 | if (len != PyList_GET_SIZE(tmp)) { |
| 8603 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 8604 | goto failed; |
| 8605 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8606 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8607 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8608 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8609 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8610 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8611 | return 1; |
| 8612 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8613 | if (tmp == NULL) { |
| 8614 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 8615 | return 1; |
| 8616 | } |
| 8617 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8618 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8619 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8620 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8621 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8622 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8623 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8624 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8625 | if (*out == NULL) goto failed; |
| 8626 | return 0; |
| 8627 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8628 | tp = astmodulestate_global->Tuple_type; |
| 8629 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8630 | if (isinstance == -1) { |
| 8631 | return 1; |
| 8632 | } |
| 8633 | if (isinstance) { |
| 8634 | asdl_seq* elts; |
| 8635 | expr_context_ty ctx; |
| 8636 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8637 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8638 | return 1; |
| 8639 | } |
| 8640 | if (tmp == NULL) { |
| 8641 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 8642 | return 1; |
| 8643 | } |
| 8644 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8645 | int res; |
| 8646 | Py_ssize_t len; |
| 8647 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8648 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8649 | 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] | 8650 | goto failed; |
| 8651 | } |
| 8652 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8653 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8654 | if (elts == NULL) goto failed; |
| 8655 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8656 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8657 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8658 | Py_INCREF(tmp2); |
| 8659 | res = obj2ast_expr(tmp2, &val, arena); |
| 8660 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8661 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8662 | if (len != PyList_GET_SIZE(tmp)) { |
| 8663 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 8664 | goto failed; |
| 8665 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8666 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8667 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8668 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8669 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8670 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8671 | return 1; |
| 8672 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8673 | if (tmp == NULL) { |
| 8674 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 8675 | return 1; |
| 8676 | } |
| 8677 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8678 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8679 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8680 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8681 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8682 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8683 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8684 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8685 | if (*out == NULL) goto failed; |
| 8686 | return 0; |
| 8687 | } |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8688 | tp = astmodulestate_global->Slice_type; |
| 8689 | isinstance = PyObject_IsInstance(obj, tp); |
| 8690 | if (isinstance == -1) { |
| 8691 | return 1; |
| 8692 | } |
| 8693 | if (isinstance) { |
| 8694 | expr_ty lower; |
| 8695 | expr_ty upper; |
| 8696 | expr_ty step; |
| 8697 | |
| 8698 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) { |
| 8699 | return 1; |
| 8700 | } |
| 8701 | if (tmp == NULL || tmp == Py_None) { |
| 8702 | Py_CLEAR(tmp); |
| 8703 | lower = NULL; |
| 8704 | } |
| 8705 | else { |
| 8706 | int res; |
| 8707 | res = obj2ast_expr(tmp, &lower, arena); |
| 8708 | if (res != 0) goto failed; |
| 8709 | Py_CLEAR(tmp); |
| 8710 | } |
| 8711 | if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) { |
| 8712 | return 1; |
| 8713 | } |
| 8714 | if (tmp == NULL || tmp == Py_None) { |
| 8715 | Py_CLEAR(tmp); |
| 8716 | upper = NULL; |
| 8717 | } |
| 8718 | else { |
| 8719 | int res; |
| 8720 | res = obj2ast_expr(tmp, &upper, arena); |
| 8721 | if (res != 0) goto failed; |
| 8722 | Py_CLEAR(tmp); |
| 8723 | } |
| 8724 | if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) { |
| 8725 | return 1; |
| 8726 | } |
| 8727 | if (tmp == NULL || tmp == Py_None) { |
| 8728 | Py_CLEAR(tmp); |
| 8729 | step = NULL; |
| 8730 | } |
| 8731 | else { |
| 8732 | int res; |
| 8733 | res = obj2ast_expr(tmp, &step, arena); |
| 8734 | if (res != 0) goto failed; |
| 8735 | Py_CLEAR(tmp); |
| 8736 | } |
| 8737 | *out = Slice(lower, upper, step, lineno, col_offset, end_lineno, |
| 8738 | end_col_offset, arena); |
| 8739 | if (*out == NULL) goto failed; |
| 8740 | return 0; |
| 8741 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8742 | |
| 8743 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 8744 | failed: |
| 8745 | Py_XDECREF(tmp); |
| 8746 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8747 | } |
| 8748 | |
| 8749 | int |
| 8750 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 8751 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8752 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8753 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8754 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8755 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8756 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8757 | } |
| 8758 | if (isinstance) { |
| 8759 | *out = Load; |
| 8760 | return 0; |
| 8761 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8762 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8763 | if (isinstance == -1) { |
| 8764 | return 1; |
| 8765 | } |
| 8766 | if (isinstance) { |
| 8767 | *out = Store; |
| 8768 | return 0; |
| 8769 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8770 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8771 | if (isinstance == -1) { |
| 8772 | return 1; |
| 8773 | } |
| 8774 | if (isinstance) { |
| 8775 | *out = Del; |
| 8776 | return 0; |
| 8777 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8778 | |
| 8779 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 8780 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8781 | } |
| 8782 | |
| 8783 | int |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8784 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 8785 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8786 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8787 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8788 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8789 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8790 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8791 | } |
| 8792 | if (isinstance) { |
| 8793 | *out = And; |
| 8794 | return 0; |
| 8795 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8796 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8797 | if (isinstance == -1) { |
| 8798 | return 1; |
| 8799 | } |
| 8800 | if (isinstance) { |
| 8801 | *out = Or; |
| 8802 | return 0; |
| 8803 | } |
| 8804 | |
| 8805 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 8806 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8807 | } |
| 8808 | |
| 8809 | int |
| 8810 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 8811 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8812 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8813 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8814 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8815 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8816 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8817 | } |
| 8818 | if (isinstance) { |
| 8819 | *out = Add; |
| 8820 | return 0; |
| 8821 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8822 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8823 | if (isinstance == -1) { |
| 8824 | return 1; |
| 8825 | } |
| 8826 | if (isinstance) { |
| 8827 | *out = Sub; |
| 8828 | return 0; |
| 8829 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8830 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8831 | if (isinstance == -1) { |
| 8832 | return 1; |
| 8833 | } |
| 8834 | if (isinstance) { |
| 8835 | *out = Mult; |
| 8836 | return 0; |
| 8837 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8838 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type); |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8839 | if (isinstance == -1) { |
| 8840 | return 1; |
| 8841 | } |
| 8842 | if (isinstance) { |
| 8843 | *out = MatMult; |
| 8844 | return 0; |
| 8845 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8846 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8847 | if (isinstance == -1) { |
| 8848 | return 1; |
| 8849 | } |
| 8850 | if (isinstance) { |
| 8851 | *out = Div; |
| 8852 | return 0; |
| 8853 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8854 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8855 | if (isinstance == -1) { |
| 8856 | return 1; |
| 8857 | } |
| 8858 | if (isinstance) { |
| 8859 | *out = Mod; |
| 8860 | return 0; |
| 8861 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8862 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8863 | if (isinstance == -1) { |
| 8864 | return 1; |
| 8865 | } |
| 8866 | if (isinstance) { |
| 8867 | *out = Pow; |
| 8868 | return 0; |
| 8869 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8870 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8871 | if (isinstance == -1) { |
| 8872 | return 1; |
| 8873 | } |
| 8874 | if (isinstance) { |
| 8875 | *out = LShift; |
| 8876 | return 0; |
| 8877 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8878 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8879 | if (isinstance == -1) { |
| 8880 | return 1; |
| 8881 | } |
| 8882 | if (isinstance) { |
| 8883 | *out = RShift; |
| 8884 | return 0; |
| 8885 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8886 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8887 | if (isinstance == -1) { |
| 8888 | return 1; |
| 8889 | } |
| 8890 | if (isinstance) { |
| 8891 | *out = BitOr; |
| 8892 | return 0; |
| 8893 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8894 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8895 | if (isinstance == -1) { |
| 8896 | return 1; |
| 8897 | } |
| 8898 | if (isinstance) { |
| 8899 | *out = BitXor; |
| 8900 | return 0; |
| 8901 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8902 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8903 | if (isinstance == -1) { |
| 8904 | return 1; |
| 8905 | } |
| 8906 | if (isinstance) { |
| 8907 | *out = BitAnd; |
| 8908 | return 0; |
| 8909 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8910 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8911 | if (isinstance == -1) { |
| 8912 | return 1; |
| 8913 | } |
| 8914 | if (isinstance) { |
| 8915 | *out = FloorDiv; |
| 8916 | return 0; |
| 8917 | } |
| 8918 | |
| 8919 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 8920 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8921 | } |
| 8922 | |
| 8923 | int |
| 8924 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 8925 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8926 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8927 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8928 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8929 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8930 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8931 | } |
| 8932 | if (isinstance) { |
| 8933 | *out = Invert; |
| 8934 | return 0; |
| 8935 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8936 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8937 | if (isinstance == -1) { |
| 8938 | return 1; |
| 8939 | } |
| 8940 | if (isinstance) { |
| 8941 | *out = Not; |
| 8942 | return 0; |
| 8943 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8944 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8945 | if (isinstance == -1) { |
| 8946 | return 1; |
| 8947 | } |
| 8948 | if (isinstance) { |
| 8949 | *out = UAdd; |
| 8950 | return 0; |
| 8951 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8952 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8953 | if (isinstance == -1) { |
| 8954 | return 1; |
| 8955 | } |
| 8956 | if (isinstance) { |
| 8957 | *out = USub; |
| 8958 | return 0; |
| 8959 | } |
| 8960 | |
| 8961 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 8962 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8963 | } |
| 8964 | |
| 8965 | int |
| 8966 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 8967 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8968 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8969 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8970 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8971 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8972 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8973 | } |
| 8974 | if (isinstance) { |
| 8975 | *out = Eq; |
| 8976 | return 0; |
| 8977 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8978 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8979 | if (isinstance == -1) { |
| 8980 | return 1; |
| 8981 | } |
| 8982 | if (isinstance) { |
| 8983 | *out = NotEq; |
| 8984 | return 0; |
| 8985 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8986 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8987 | if (isinstance == -1) { |
| 8988 | return 1; |
| 8989 | } |
| 8990 | if (isinstance) { |
| 8991 | *out = Lt; |
| 8992 | return 0; |
| 8993 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8994 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8995 | if (isinstance == -1) { |
| 8996 | return 1; |
| 8997 | } |
| 8998 | if (isinstance) { |
| 8999 | *out = LtE; |
| 9000 | return 0; |
| 9001 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9002 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9003 | if (isinstance == -1) { |
| 9004 | return 1; |
| 9005 | } |
| 9006 | if (isinstance) { |
| 9007 | *out = Gt; |
| 9008 | return 0; |
| 9009 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9010 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9011 | if (isinstance == -1) { |
| 9012 | return 1; |
| 9013 | } |
| 9014 | if (isinstance) { |
| 9015 | *out = GtE; |
| 9016 | return 0; |
| 9017 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9018 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9019 | if (isinstance == -1) { |
| 9020 | return 1; |
| 9021 | } |
| 9022 | if (isinstance) { |
| 9023 | *out = Is; |
| 9024 | return 0; |
| 9025 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9026 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9027 | if (isinstance == -1) { |
| 9028 | return 1; |
| 9029 | } |
| 9030 | if (isinstance) { |
| 9031 | *out = IsNot; |
| 9032 | return 0; |
| 9033 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9034 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9035 | if (isinstance == -1) { |
| 9036 | return 1; |
| 9037 | } |
| 9038 | if (isinstance) { |
| 9039 | *out = In; |
| 9040 | return 0; |
| 9041 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9042 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9043 | if (isinstance == -1) { |
| 9044 | return 1; |
| 9045 | } |
| 9046 | if (isinstance) { |
| 9047 | *out = NotIn; |
| 9048 | return 0; |
| 9049 | } |
| 9050 | |
| 9051 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 9052 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9053 | } |
| 9054 | |
| 9055 | int |
| 9056 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 9057 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9058 | PyObject* tmp = NULL; |
| 9059 | expr_ty target; |
| 9060 | expr_ty iter; |
| 9061 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9062 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9063 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9064 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9065 | return 1; |
| 9066 | } |
| 9067 | if (tmp == NULL) { |
| 9068 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 9069 | return 1; |
| 9070 | } |
| 9071 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9072 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9073 | res = obj2ast_expr(tmp, &target, arena); |
| 9074 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9075 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9076 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9077 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9078 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9079 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9080 | if (tmp == NULL) { |
| 9081 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 9082 | return 1; |
| 9083 | } |
| 9084 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9085 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9086 | res = obj2ast_expr(tmp, &iter, arena); |
| 9087 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9088 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9089 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9090 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9091 | return 1; |
| 9092 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9093 | if (tmp == NULL) { |
| 9094 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 9095 | return 1; |
| 9096 | } |
| 9097 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9098 | int res; |
| 9099 | Py_ssize_t len; |
| 9100 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9101 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9102 | 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] | 9103 | goto failed; |
| 9104 | } |
| 9105 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9106 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9107 | if (ifs == NULL) goto failed; |
| 9108 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9109 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9110 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9111 | Py_INCREF(tmp2); |
| 9112 | res = obj2ast_expr(tmp2, &val, arena); |
| 9113 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9114 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9115 | if (len != PyList_GET_SIZE(tmp)) { |
| 9116 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 9117 | goto failed; |
| 9118 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9119 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9120 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9121 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9122 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9123 | if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9124 | return 1; |
| 9125 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9126 | if (tmp == NULL) { |
| 9127 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 9128 | return 1; |
| 9129 | } |
| 9130 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9131 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9132 | res = obj2ast_int(tmp, &is_async, arena); |
| 9133 | if (res != 0) goto failed; |
| 9134 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9135 | } |
| 9136 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9137 | return 0; |
| 9138 | failed: |
| 9139 | Py_XDECREF(tmp); |
| 9140 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9141 | } |
| 9142 | |
| 9143 | int |
| 9144 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 9145 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9146 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 9147 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9148 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9149 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9150 | int lineno; |
| 9151 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9152 | int end_lineno; |
| 9153 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9154 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9155 | if (obj == Py_None) { |
| 9156 | *out = NULL; |
| 9157 | return 0; |
| 9158 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9159 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9160 | return 1; |
| 9161 | } |
| 9162 | if (tmp == NULL) { |
| 9163 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 9164 | return 1; |
| 9165 | } |
| 9166 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9167 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9168 | res = obj2ast_int(tmp, &lineno, arena); |
| 9169 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9170 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9171 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9172 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9173 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9174 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9175 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9176 | if (tmp == NULL) { |
| 9177 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 9178 | return 1; |
| 9179 | } |
| 9180 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9181 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9182 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9183 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9184 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9185 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9186 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9187 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9188 | return 1; |
| 9189 | } |
| 9190 | if (tmp == NULL || tmp == Py_None) { |
| 9191 | Py_CLEAR(tmp); |
| 9192 | end_lineno = 0; |
| 9193 | } |
| 9194 | else { |
| 9195 | int res; |
| 9196 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9197 | if (res != 0) goto failed; |
| 9198 | Py_CLEAR(tmp); |
| 9199 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9200 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9201 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9202 | return 1; |
| 9203 | } |
| 9204 | if (tmp == NULL || tmp == Py_None) { |
| 9205 | Py_CLEAR(tmp); |
| 9206 | end_col_offset = 0; |
| 9207 | } |
| 9208 | else { |
| 9209 | int res; |
| 9210 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9211 | if (res != 0) goto failed; |
| 9212 | Py_CLEAR(tmp); |
| 9213 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9214 | tp = astmodulestate_global->ExceptHandler_type; |
| 9215 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9216 | if (isinstance == -1) { |
| 9217 | return 1; |
| 9218 | } |
| 9219 | if (isinstance) { |
| 9220 | expr_ty type; |
| 9221 | identifier name; |
| 9222 | asdl_seq* body; |
| 9223 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9224 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9225 | return 1; |
| 9226 | } |
| 9227 | if (tmp == NULL || tmp == Py_None) { |
| 9228 | Py_CLEAR(tmp); |
| 9229 | type = NULL; |
| 9230 | } |
| 9231 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9232 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9233 | res = obj2ast_expr(tmp, &type, arena); |
| 9234 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9235 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9236 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9237 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9238 | return 1; |
| 9239 | } |
| 9240 | if (tmp == NULL || tmp == Py_None) { |
| 9241 | Py_CLEAR(tmp); |
| 9242 | name = NULL; |
| 9243 | } |
| 9244 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9245 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9246 | res = obj2ast_identifier(tmp, &name, arena); |
| 9247 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9248 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9249 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9250 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9251 | return 1; |
| 9252 | } |
| 9253 | if (tmp == NULL) { |
| 9254 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 9255 | return 1; |
| 9256 | } |
| 9257 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9258 | int res; |
| 9259 | Py_ssize_t len; |
| 9260 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9261 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9262 | 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] | 9263 | goto failed; |
| 9264 | } |
| 9265 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9266 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9267 | if (body == NULL) goto failed; |
| 9268 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9269 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9270 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9271 | Py_INCREF(tmp2); |
| 9272 | res = obj2ast_stmt(tmp2, &val, arena); |
| 9273 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9274 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9275 | if (len != PyList_GET_SIZE(tmp)) { |
| 9276 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 9277 | goto failed; |
| 9278 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9279 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9280 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9281 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9282 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9283 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 9284 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9285 | if (*out == NULL) goto failed; |
| 9286 | return 0; |
| 9287 | } |
| 9288 | |
| 9289 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 9290 | failed: |
| 9291 | Py_XDECREF(tmp); |
| 9292 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9293 | } |
| 9294 | |
| 9295 | int |
| 9296 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 9297 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9298 | PyObject* tmp = NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9299 | asdl_seq* posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9300 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9301 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9302 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9303 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9304 | arg_ty kwarg; |
| 9305 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9306 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9307 | if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) < |
| 9308 | 0) { |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9309 | return 1; |
| 9310 | } |
| 9311 | if (tmp == NULL) { |
| 9312 | PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments"); |
| 9313 | return 1; |
| 9314 | } |
| 9315 | else { |
| 9316 | int res; |
| 9317 | Py_ssize_t len; |
| 9318 | Py_ssize_t i; |
| 9319 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9320 | 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] | 9321 | goto failed; |
| 9322 | } |
| 9323 | len = PyList_GET_SIZE(tmp); |
| 9324 | posonlyargs = _Py_asdl_seq_new(len, arena); |
| 9325 | if (posonlyargs == NULL) goto failed; |
| 9326 | for (i = 0; i < len; i++) { |
| 9327 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9328 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9329 | Py_INCREF(tmp2); |
| 9330 | res = obj2ast_arg(tmp2, &val, arena); |
| 9331 | Py_DECREF(tmp2); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9332 | if (res != 0) goto failed; |
| 9333 | if (len != PyList_GET_SIZE(tmp)) { |
| 9334 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration"); |
| 9335 | goto failed; |
| 9336 | } |
| 9337 | asdl_seq_SET(posonlyargs, i, val); |
| 9338 | } |
| 9339 | Py_CLEAR(tmp); |
| 9340 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9341 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9342 | return 1; |
| 9343 | } |
| 9344 | if (tmp == NULL) { |
| 9345 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 9346 | return 1; |
| 9347 | } |
| 9348 | else { |
| 9349 | int res; |
| 9350 | Py_ssize_t len; |
| 9351 | Py_ssize_t i; |
| 9352 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9353 | 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] | 9354 | goto failed; |
| 9355 | } |
| 9356 | len = PyList_GET_SIZE(tmp); |
| 9357 | args = _Py_asdl_seq_new(len, arena); |
| 9358 | if (args == NULL) goto failed; |
| 9359 | for (i = 0; i < len; i++) { |
| 9360 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9361 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9362 | Py_INCREF(tmp2); |
| 9363 | res = obj2ast_arg(tmp2, &val, arena); |
| 9364 | Py_DECREF(tmp2); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9365 | if (res != 0) goto failed; |
| 9366 | if (len != PyList_GET_SIZE(tmp)) { |
| 9367 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 9368 | goto failed; |
| 9369 | } |
| 9370 | asdl_seq_SET(args, i, val); |
| 9371 | } |
| 9372 | Py_CLEAR(tmp); |
| 9373 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9374 | if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9375 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9376 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9377 | if (tmp == NULL || tmp == Py_None) { |
| 9378 | Py_CLEAR(tmp); |
| 9379 | vararg = NULL; |
| 9380 | } |
| 9381 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9382 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9383 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9384 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9385 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9386 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9387 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0) |
| 9388 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9389 | return 1; |
| 9390 | } |
| 9391 | if (tmp == NULL) { |
| 9392 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 9393 | return 1; |
| 9394 | } |
| 9395 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9396 | int res; |
| 9397 | Py_ssize_t len; |
| 9398 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9399 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9400 | 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] | 9401 | goto failed; |
| 9402 | } |
| 9403 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9404 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9405 | if (kwonlyargs == NULL) goto failed; |
| 9406 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9407 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9408 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9409 | Py_INCREF(tmp2); |
| 9410 | res = obj2ast_arg(tmp2, &val, arena); |
| 9411 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9412 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9413 | if (len != PyList_GET_SIZE(tmp)) { |
| 9414 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 9415 | goto failed; |
| 9416 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9417 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9418 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9419 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9420 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9421 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) < |
| 9422 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9423 | return 1; |
| 9424 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9425 | if (tmp == NULL) { |
| 9426 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 9427 | return 1; |
| 9428 | } |
| 9429 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9430 | int res; |
| 9431 | Py_ssize_t len; |
| 9432 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9433 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9434 | 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] | 9435 | goto failed; |
| 9436 | } |
| 9437 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9438 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9439 | if (kw_defaults == NULL) goto failed; |
| 9440 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9441 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9442 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9443 | Py_INCREF(tmp2); |
| 9444 | res = obj2ast_expr(tmp2, &val, arena); |
| 9445 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9446 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9447 | if (len != PyList_GET_SIZE(tmp)) { |
| 9448 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 9449 | goto failed; |
| 9450 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9451 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9452 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9453 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9454 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9455 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9456 | return 1; |
| 9457 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9458 | if (tmp == NULL || tmp == Py_None) { |
| 9459 | Py_CLEAR(tmp); |
| 9460 | kwarg = NULL; |
| 9461 | } |
| 9462 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9463 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9464 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 9465 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9466 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9467 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9468 | if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9469 | return 1; |
| 9470 | } |
| 9471 | if (tmp == NULL) { |
| 9472 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 9473 | return 1; |
| 9474 | } |
| 9475 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9476 | int res; |
| 9477 | Py_ssize_t len; |
| 9478 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9479 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9480 | 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] | 9481 | goto failed; |
| 9482 | } |
| 9483 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9484 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9485 | if (defaults == NULL) goto failed; |
| 9486 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9487 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9488 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9489 | Py_INCREF(tmp2); |
| 9490 | res = obj2ast_expr(tmp2, &val, arena); |
| 9491 | Py_DECREF(tmp2); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9492 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9493 | if (len != PyList_GET_SIZE(tmp)) { |
| 9494 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 9495 | goto failed; |
| 9496 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9497 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9498 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9499 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9500 | } |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9501 | *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9502 | defaults, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9503 | return 0; |
| 9504 | failed: |
| 9505 | Py_XDECREF(tmp); |
| 9506 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9507 | } |
| 9508 | |
| 9509 | int |
| 9510 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 9511 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9512 | PyObject* tmp = NULL; |
| 9513 | identifier arg; |
| 9514 | expr_ty annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9515 | string type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9516 | int lineno; |
| 9517 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9518 | int end_lineno; |
| 9519 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9520 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9521 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9522 | return 1; |
| 9523 | } |
| 9524 | if (tmp == NULL) { |
| 9525 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 9526 | return 1; |
| 9527 | } |
| 9528 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9529 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9530 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9531 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9532 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9533 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9534 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0) |
| 9535 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9536 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9537 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9538 | if (tmp == NULL || tmp == Py_None) { |
| 9539 | Py_CLEAR(tmp); |
| 9540 | annotation = NULL; |
| 9541 | } |
| 9542 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9543 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9544 | res = obj2ast_expr(tmp, &annotation, arena); |
| 9545 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9546 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9547 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9548 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) < |
| 9549 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9550 | return 1; |
| 9551 | } |
| 9552 | if (tmp == NULL || tmp == Py_None) { |
| 9553 | Py_CLEAR(tmp); |
| 9554 | type_comment = NULL; |
| 9555 | } |
| 9556 | else { |
| 9557 | int res; |
| 9558 | res = obj2ast_string(tmp, &type_comment, arena); |
| 9559 | if (res != 0) goto failed; |
| 9560 | Py_CLEAR(tmp); |
| 9561 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9562 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9563 | return 1; |
| 9564 | } |
| 9565 | if (tmp == NULL) { |
| 9566 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 9567 | return 1; |
| 9568 | } |
| 9569 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9570 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9571 | res = obj2ast_int(tmp, &lineno, arena); |
| 9572 | if (res != 0) goto failed; |
| 9573 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9574 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9575 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9576 | { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9577 | return 1; |
| 9578 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9579 | if (tmp == NULL) { |
| 9580 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 9581 | return 1; |
| 9582 | } |
| 9583 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9584 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9585 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9586 | if (res != 0) goto failed; |
| 9587 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9588 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9589 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9590 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9591 | return 1; |
| 9592 | } |
| 9593 | if (tmp == NULL || tmp == Py_None) { |
| 9594 | Py_CLEAR(tmp); |
| 9595 | end_lineno = 0; |
| 9596 | } |
| 9597 | else { |
| 9598 | int res; |
| 9599 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9600 | if (res != 0) goto failed; |
| 9601 | Py_CLEAR(tmp); |
| 9602 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9603 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9604 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9605 | return 1; |
| 9606 | } |
| 9607 | if (tmp == NULL || tmp == Py_None) { |
| 9608 | Py_CLEAR(tmp); |
| 9609 | end_col_offset = 0; |
| 9610 | } |
| 9611 | else { |
| 9612 | int res; |
| 9613 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9614 | if (res != 0) goto failed; |
| 9615 | Py_CLEAR(tmp); |
| 9616 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9617 | *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno, |
| 9618 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9619 | return 0; |
| 9620 | failed: |
| 9621 | Py_XDECREF(tmp); |
| 9622 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9623 | } |
| 9624 | |
| 9625 | int |
| 9626 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 9627 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9628 | PyObject* tmp = NULL; |
| 9629 | identifier arg; |
| 9630 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9631 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9632 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9633 | return 1; |
| 9634 | } |
| 9635 | if (tmp == NULL || tmp == Py_None) { |
| 9636 | Py_CLEAR(tmp); |
| 9637 | arg = NULL; |
| 9638 | } |
| 9639 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9640 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9641 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9642 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9643 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9644 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9645 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9646 | return 1; |
| 9647 | } |
| 9648 | if (tmp == NULL) { |
| 9649 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 9650 | return 1; |
| 9651 | } |
| 9652 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9653 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9654 | res = obj2ast_expr(tmp, &value, arena); |
| 9655 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9656 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9657 | } |
| 9658 | *out = keyword(arg, value, arena); |
| 9659 | return 0; |
| 9660 | failed: |
| 9661 | Py_XDECREF(tmp); |
| 9662 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9663 | } |
| 9664 | |
| 9665 | int |
| 9666 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 9667 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9668 | PyObject* tmp = NULL; |
| 9669 | identifier name; |
| 9670 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9671 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9672 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9673 | return 1; |
| 9674 | } |
| 9675 | if (tmp == NULL) { |
| 9676 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 9677 | return 1; |
| 9678 | } |
| 9679 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9680 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9681 | res = obj2ast_identifier(tmp, &name, arena); |
| 9682 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9683 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9684 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9685 | if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9686 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9687 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9688 | if (tmp == NULL || tmp == Py_None) { |
| 9689 | Py_CLEAR(tmp); |
| 9690 | asname = NULL; |
| 9691 | } |
| 9692 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9693 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9694 | res = obj2ast_identifier(tmp, &asname, arena); |
| 9695 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9696 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9697 | } |
| 9698 | *out = alias(name, asname, arena); |
| 9699 | return 0; |
| 9700 | failed: |
| 9701 | Py_XDECREF(tmp); |
| 9702 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9703 | } |
| 9704 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9705 | int |
| 9706 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 9707 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9708 | PyObject* tmp = NULL; |
| 9709 | expr_ty context_expr; |
| 9710 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9711 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9712 | if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) < |
| 9713 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9714 | return 1; |
| 9715 | } |
| 9716 | if (tmp == NULL) { |
| 9717 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 9718 | return 1; |
| 9719 | } |
| 9720 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9721 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9722 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 9723 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9724 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9725 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9726 | if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) < |
| 9727 | 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9728 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9729 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9730 | if (tmp == NULL || tmp == Py_None) { |
| 9731 | Py_CLEAR(tmp); |
| 9732 | optional_vars = NULL; |
| 9733 | } |
| 9734 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9735 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9736 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 9737 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9738 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9739 | } |
| 9740 | *out = withitem(context_expr, optional_vars, arena); |
| 9741 | return 0; |
| 9742 | failed: |
| 9743 | Py_XDECREF(tmp); |
| 9744 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9745 | } |
| 9746 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9747 | int |
| 9748 | obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) |
| 9749 | { |
| 9750 | int isinstance; |
| 9751 | |
| 9752 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9753 | PyObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9754 | |
| 9755 | if (obj == Py_None) { |
| 9756 | *out = NULL; |
| 9757 | return 0; |
| 9758 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9759 | tp = astmodulestate_global->TypeIgnore_type; |
| 9760 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9761 | if (isinstance == -1) { |
| 9762 | return 1; |
| 9763 | } |
| 9764 | if (isinstance) { |
| 9765 | int lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9766 | string tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9767 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9768 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) |
| 9769 | { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9770 | return 1; |
| 9771 | } |
| 9772 | if (tmp == NULL) { |
| 9773 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore"); |
| 9774 | return 1; |
| 9775 | } |
| 9776 | else { |
| 9777 | int res; |
| 9778 | res = obj2ast_int(tmp, &lineno, arena); |
| 9779 | if (res != 0) goto failed; |
| 9780 | Py_CLEAR(tmp); |
| 9781 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9782 | if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) { |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9783 | return 1; |
| 9784 | } |
| 9785 | if (tmp == NULL) { |
| 9786 | PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore"); |
| 9787 | return 1; |
| 9788 | } |
| 9789 | else { |
| 9790 | int res; |
| 9791 | res = obj2ast_string(tmp, &tag, arena); |
| 9792 | if (res != 0) goto failed; |
| 9793 | Py_CLEAR(tmp); |
| 9794 | } |
| 9795 | *out = TypeIgnore(lineno, tag, arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9796 | if (*out == NULL) goto failed; |
| 9797 | return 0; |
| 9798 | } |
| 9799 | |
| 9800 | PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj); |
| 9801 | failed: |
| 9802 | Py_XDECREF(tmp); |
| 9803 | return 1; |
| 9804 | } |
| 9805 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9806 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9807 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 9808 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9809 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9810 | PyObject *m; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9811 | if (!init_types()) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9812 | m = PyState_FindModule(&_astmodule); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9813 | if (!m) return NULL; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9814 | if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) { |
| 9815 | goto error; |
| 9816 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9817 | Py_INCREF(astmodulestate(m)->AST_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9818 | if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) { |
| 9819 | goto error; |
| 9820 | } |
| 9821 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) { |
| 9822 | goto error; |
| 9823 | } |
| 9824 | if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) { |
| 9825 | goto error; |
| 9826 | } |
| 9827 | if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) { |
| 9828 | goto error; |
| 9829 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9830 | Py_INCREF(astmodulestate(m)->mod_type); |
| 9831 | if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9832 | 0) { |
| 9833 | goto error; |
| 9834 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9835 | Py_INCREF(astmodulestate(m)->Module_type); |
| 9836 | if (PyModule_AddObject(m, "Interactive", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9837 | astmodulestate_global->Interactive_type) < 0) { |
| 9838 | goto error; |
| 9839 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9840 | Py_INCREF(astmodulestate(m)->Interactive_type); |
| 9841 | if (PyModule_AddObject(m, "Expression", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9842 | astmodulestate_global->Expression_type) < 0) { |
| 9843 | goto error; |
| 9844 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9845 | Py_INCREF(astmodulestate(m)->Expression_type); |
| 9846 | if (PyModule_AddObject(m, "FunctionType", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9847 | astmodulestate_global->FunctionType_type) < 0) { |
| 9848 | goto error; |
| 9849 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9850 | Py_INCREF(astmodulestate(m)->FunctionType_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9851 | if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) { |
| 9852 | goto error; |
| 9853 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9854 | Py_INCREF(astmodulestate(m)->stmt_type); |
| 9855 | if (PyModule_AddObject(m, "FunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9856 | astmodulestate_global->FunctionDef_type) < 0) { |
| 9857 | goto error; |
| 9858 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9859 | Py_INCREF(astmodulestate(m)->FunctionDef_type); |
| 9860 | if (PyModule_AddObject(m, "AsyncFunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9861 | astmodulestate_global->AsyncFunctionDef_type) < 0) { |
| 9862 | goto error; |
| 9863 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9864 | Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type); |
| 9865 | if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9866 | < 0) { |
| 9867 | goto error; |
| 9868 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9869 | Py_INCREF(astmodulestate(m)->ClassDef_type); |
| 9870 | if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9871 | 0) { |
| 9872 | goto error; |
| 9873 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9874 | Py_INCREF(astmodulestate(m)->Return_type); |
| 9875 | if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9876 | 0) { |
| 9877 | goto error; |
| 9878 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9879 | Py_INCREF(astmodulestate(m)->Delete_type); |
| 9880 | if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9881 | 0) { |
| 9882 | goto error; |
| 9883 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9884 | Py_INCREF(astmodulestate(m)->Assign_type); |
| 9885 | if (PyModule_AddObject(m, "AugAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9886 | astmodulestate_global->AugAssign_type) < 0) { |
| 9887 | goto error; |
| 9888 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9889 | Py_INCREF(astmodulestate(m)->AugAssign_type); |
| 9890 | if (PyModule_AddObject(m, "AnnAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9891 | astmodulestate_global->AnnAssign_type) < 0) { |
| 9892 | goto error; |
| 9893 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9894 | Py_INCREF(astmodulestate(m)->AnnAssign_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9895 | if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) { |
| 9896 | goto error; |
| 9897 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9898 | Py_INCREF(astmodulestate(m)->For_type); |
| 9899 | if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9900 | < 0) { |
| 9901 | goto error; |
| 9902 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9903 | Py_INCREF(astmodulestate(m)->AsyncFor_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9904 | if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) { |
| 9905 | goto error; |
| 9906 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9907 | Py_INCREF(astmodulestate(m)->While_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9908 | if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) { |
| 9909 | goto error; |
| 9910 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9911 | Py_INCREF(astmodulestate(m)->If_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9912 | if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) { |
| 9913 | goto error; |
| 9914 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9915 | Py_INCREF(astmodulestate(m)->With_type); |
| 9916 | if (PyModule_AddObject(m, "AsyncWith", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9917 | astmodulestate_global->AsyncWith_type) < 0) { |
| 9918 | goto error; |
| 9919 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9920 | Py_INCREF(astmodulestate(m)->AsyncWith_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9921 | if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) { |
| 9922 | goto error; |
| 9923 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9924 | Py_INCREF(astmodulestate(m)->Raise_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9925 | if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) { |
| 9926 | goto error; |
| 9927 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9928 | Py_INCREF(astmodulestate(m)->Try_type); |
| 9929 | if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9930 | 0) { |
| 9931 | goto error; |
| 9932 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9933 | Py_INCREF(astmodulestate(m)->Assert_type); |
| 9934 | if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9935 | 0) { |
| 9936 | goto error; |
| 9937 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9938 | Py_INCREF(astmodulestate(m)->Import_type); |
| 9939 | if (PyModule_AddObject(m, "ImportFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9940 | astmodulestate_global->ImportFrom_type) < 0) { |
| 9941 | goto error; |
| 9942 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9943 | Py_INCREF(astmodulestate(m)->ImportFrom_type); |
| 9944 | if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9945 | 0) { |
| 9946 | goto error; |
| 9947 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9948 | Py_INCREF(astmodulestate(m)->Global_type); |
| 9949 | if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9950 | < 0) { |
| 9951 | goto error; |
| 9952 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9953 | Py_INCREF(astmodulestate(m)->Nonlocal_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9954 | if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) { |
| 9955 | goto error; |
| 9956 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9957 | Py_INCREF(astmodulestate(m)->Expr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9958 | if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) { |
| 9959 | goto error; |
| 9960 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9961 | Py_INCREF(astmodulestate(m)->Pass_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9962 | if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) { |
| 9963 | goto error; |
| 9964 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9965 | Py_INCREF(astmodulestate(m)->Break_type); |
| 9966 | if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9967 | < 0) { |
| 9968 | goto error; |
| 9969 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9970 | Py_INCREF(astmodulestate(m)->Continue_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9971 | if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) { |
| 9972 | goto error; |
| 9973 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9974 | Py_INCREF(astmodulestate(m)->expr_type); |
| 9975 | if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9976 | 0) { |
| 9977 | goto error; |
| 9978 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9979 | Py_INCREF(astmodulestate(m)->BoolOp_type); |
| 9980 | if (PyModule_AddObject(m, "NamedExpr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9981 | astmodulestate_global->NamedExpr_type) < 0) { |
| 9982 | goto error; |
| 9983 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9984 | Py_INCREF(astmodulestate(m)->NamedExpr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9985 | if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) { |
| 9986 | goto error; |
| 9987 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9988 | Py_INCREF(astmodulestate(m)->BinOp_type); |
| 9989 | if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9990 | 0) { |
| 9991 | goto error; |
| 9992 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9993 | Py_INCREF(astmodulestate(m)->UnaryOp_type); |
| 9994 | if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9995 | 0) { |
| 9996 | goto error; |
| 9997 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9998 | Py_INCREF(astmodulestate(m)->Lambda_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9999 | if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) { |
| 10000 | goto error; |
| 10001 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10002 | Py_INCREF(astmodulestate(m)->IfExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10003 | if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) { |
| 10004 | goto error; |
| 10005 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10006 | Py_INCREF(astmodulestate(m)->Dict_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10007 | if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) { |
| 10008 | goto error; |
| 10009 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10010 | Py_INCREF(astmodulestate(m)->Set_type); |
| 10011 | if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10012 | < 0) { |
| 10013 | goto error; |
| 10014 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10015 | Py_INCREF(astmodulestate(m)->ListComp_type); |
| 10016 | if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10017 | 0) { |
| 10018 | goto error; |
| 10019 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10020 | Py_INCREF(astmodulestate(m)->SetComp_type); |
| 10021 | if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10022 | < 0) { |
| 10023 | goto error; |
| 10024 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10025 | Py_INCREF(astmodulestate(m)->DictComp_type); |
| 10026 | if (PyModule_AddObject(m, "GeneratorExp", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10027 | astmodulestate_global->GeneratorExp_type) < 0) { |
| 10028 | goto error; |
| 10029 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10030 | Py_INCREF(astmodulestate(m)->GeneratorExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10031 | if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) { |
| 10032 | goto error; |
| 10033 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10034 | Py_INCREF(astmodulestate(m)->Await_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10035 | if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) { |
| 10036 | goto error; |
| 10037 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10038 | Py_INCREF(astmodulestate(m)->Yield_type); |
| 10039 | if (PyModule_AddObject(m, "YieldFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10040 | astmodulestate_global->YieldFrom_type) < 0) { |
| 10041 | goto error; |
| 10042 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10043 | Py_INCREF(astmodulestate(m)->YieldFrom_type); |
| 10044 | if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10045 | 0) { |
| 10046 | goto error; |
| 10047 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10048 | Py_INCREF(astmodulestate(m)->Compare_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10049 | if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) { |
| 10050 | goto error; |
| 10051 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10052 | Py_INCREF(astmodulestate(m)->Call_type); |
| 10053 | if (PyModule_AddObject(m, "FormattedValue", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10054 | astmodulestate_global->FormattedValue_type) < 0) { |
| 10055 | goto error; |
| 10056 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10057 | Py_INCREF(astmodulestate(m)->FormattedValue_type); |
| 10058 | if (PyModule_AddObject(m, "JoinedStr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10059 | astmodulestate_global->JoinedStr_type) < 0) { |
| 10060 | goto error; |
| 10061 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10062 | Py_INCREF(astmodulestate(m)->JoinedStr_type); |
| 10063 | if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10064 | < 0) { |
| 10065 | goto error; |
| 10066 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10067 | Py_INCREF(astmodulestate(m)->Constant_type); |
| 10068 | if (PyModule_AddObject(m, "Attribute", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10069 | astmodulestate_global->Attribute_type) < 0) { |
| 10070 | goto error; |
| 10071 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10072 | Py_INCREF(astmodulestate(m)->Attribute_type); |
| 10073 | if (PyModule_AddObject(m, "Subscript", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10074 | astmodulestate_global->Subscript_type) < 0) { |
| 10075 | goto error; |
| 10076 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10077 | Py_INCREF(astmodulestate(m)->Subscript_type); |
| 10078 | if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10079 | 0) { |
| 10080 | goto error; |
| 10081 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10082 | Py_INCREF(astmodulestate(m)->Starred_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10083 | if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) { |
| 10084 | goto error; |
| 10085 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10086 | Py_INCREF(astmodulestate(m)->Name_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10087 | if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) { |
| 10088 | goto error; |
| 10089 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10090 | Py_INCREF(astmodulestate(m)->List_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10091 | if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) { |
| 10092 | goto error; |
| 10093 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10094 | Py_INCREF(astmodulestate(m)->Tuple_type); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 10095 | if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) { |
| 10096 | goto error; |
| 10097 | } |
| 10098 | Py_INCREF(astmodulestate(m)->Slice_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10099 | if (PyModule_AddObject(m, "expr_context", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10100 | astmodulestate_global->expr_context_type) < 0) { |
| 10101 | goto error; |
| 10102 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10103 | Py_INCREF(astmodulestate(m)->expr_context_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10104 | if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) { |
| 10105 | goto error; |
| 10106 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10107 | Py_INCREF(astmodulestate(m)->Load_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10108 | if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) { |
| 10109 | goto error; |
| 10110 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10111 | Py_INCREF(astmodulestate(m)->Store_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10112 | if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) { |
| 10113 | goto error; |
| 10114 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10115 | Py_INCREF(astmodulestate(m)->Del_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10116 | if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10117 | 0) { |
| 10118 | goto error; |
| 10119 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10120 | Py_INCREF(astmodulestate(m)->boolop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10121 | if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) { |
| 10122 | goto error; |
| 10123 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10124 | Py_INCREF(astmodulestate(m)->And_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10125 | if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) { |
| 10126 | goto error; |
| 10127 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10128 | Py_INCREF(astmodulestate(m)->Or_type); |
| 10129 | if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10130 | < 0) { |
| 10131 | goto error; |
| 10132 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10133 | Py_INCREF(astmodulestate(m)->operator_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10134 | if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) { |
| 10135 | goto error; |
| 10136 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10137 | Py_INCREF(astmodulestate(m)->Add_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10138 | if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) { |
| 10139 | goto error; |
| 10140 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10141 | Py_INCREF(astmodulestate(m)->Sub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10142 | if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) { |
| 10143 | goto error; |
| 10144 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10145 | Py_INCREF(astmodulestate(m)->Mult_type); |
| 10146 | if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10147 | 0) { |
| 10148 | goto error; |
| 10149 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10150 | Py_INCREF(astmodulestate(m)->MatMult_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10151 | if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) { |
| 10152 | goto error; |
| 10153 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10154 | Py_INCREF(astmodulestate(m)->Div_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10155 | if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) { |
| 10156 | goto error; |
| 10157 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10158 | Py_INCREF(astmodulestate(m)->Mod_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10159 | if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) { |
| 10160 | goto error; |
| 10161 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10162 | Py_INCREF(astmodulestate(m)->Pow_type); |
| 10163 | if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10164 | 0) { |
| 10165 | goto error; |
| 10166 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10167 | Py_INCREF(astmodulestate(m)->LShift_type); |
| 10168 | if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10169 | 0) { |
| 10170 | goto error; |
| 10171 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10172 | Py_INCREF(astmodulestate(m)->RShift_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10173 | if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) { |
| 10174 | goto error; |
| 10175 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10176 | Py_INCREF(astmodulestate(m)->BitOr_type); |
| 10177 | if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10178 | 0) { |
| 10179 | goto error; |
| 10180 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10181 | Py_INCREF(astmodulestate(m)->BitXor_type); |
| 10182 | if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10183 | 0) { |
| 10184 | goto error; |
| 10185 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10186 | Py_INCREF(astmodulestate(m)->BitAnd_type); |
| 10187 | if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10188 | < 0) { |
| 10189 | goto error; |
| 10190 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10191 | Py_INCREF(astmodulestate(m)->FloorDiv_type); |
| 10192 | if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10193 | 0) { |
| 10194 | goto error; |
| 10195 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10196 | Py_INCREF(astmodulestate(m)->unaryop_type); |
| 10197 | if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10198 | 0) { |
| 10199 | goto error; |
| 10200 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10201 | Py_INCREF(astmodulestate(m)->Invert_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10202 | if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) { |
| 10203 | goto error; |
| 10204 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10205 | Py_INCREF(astmodulestate(m)->Not_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10206 | if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) { |
| 10207 | goto error; |
| 10208 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10209 | Py_INCREF(astmodulestate(m)->UAdd_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10210 | if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) { |
| 10211 | goto error; |
| 10212 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10213 | Py_INCREF(astmodulestate(m)->USub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10214 | if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) { |
| 10215 | goto error; |
| 10216 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10217 | Py_INCREF(astmodulestate(m)->cmpop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10218 | if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) { |
| 10219 | goto error; |
| 10220 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10221 | Py_INCREF(astmodulestate(m)->Eq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10222 | if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) { |
| 10223 | goto error; |
| 10224 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10225 | Py_INCREF(astmodulestate(m)->NotEq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10226 | if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) { |
| 10227 | goto error; |
| 10228 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10229 | Py_INCREF(astmodulestate(m)->Lt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10230 | if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) { |
| 10231 | goto error; |
| 10232 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10233 | Py_INCREF(astmodulestate(m)->LtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10234 | if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) { |
| 10235 | goto error; |
| 10236 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10237 | Py_INCREF(astmodulestate(m)->Gt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10238 | if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) { |
| 10239 | goto error; |
| 10240 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10241 | Py_INCREF(astmodulestate(m)->GtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10242 | if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) { |
| 10243 | goto error; |
| 10244 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10245 | Py_INCREF(astmodulestate(m)->Is_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10246 | if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) { |
| 10247 | goto error; |
| 10248 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10249 | Py_INCREF(astmodulestate(m)->IsNot_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10250 | if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) { |
| 10251 | goto error; |
| 10252 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10253 | Py_INCREF(astmodulestate(m)->In_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10254 | if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) { |
| 10255 | goto error; |
| 10256 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10257 | Py_INCREF(astmodulestate(m)->NotIn_type); |
| 10258 | if (PyModule_AddObject(m, "comprehension", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10259 | astmodulestate_global->comprehension_type) < 0) { |
| 10260 | goto error; |
| 10261 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10262 | Py_INCREF(astmodulestate(m)->comprehension_type); |
| 10263 | if (PyModule_AddObject(m, "excepthandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10264 | astmodulestate_global->excepthandler_type) < 0) { |
| 10265 | goto error; |
| 10266 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10267 | Py_INCREF(astmodulestate(m)->excepthandler_type); |
| 10268 | if (PyModule_AddObject(m, "ExceptHandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10269 | astmodulestate_global->ExceptHandler_type) < 0) { |
| 10270 | goto error; |
| 10271 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10272 | Py_INCREF(astmodulestate(m)->ExceptHandler_type); |
| 10273 | if (PyModule_AddObject(m, "arguments", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10274 | astmodulestate_global->arguments_type) < 0) { |
| 10275 | goto error; |
| 10276 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10277 | Py_INCREF(astmodulestate(m)->arguments_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10278 | if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) { |
| 10279 | goto error; |
| 10280 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10281 | Py_INCREF(astmodulestate(m)->arg_type); |
| 10282 | if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10283 | 0) { |
| 10284 | goto error; |
| 10285 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10286 | Py_INCREF(astmodulestate(m)->keyword_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10287 | if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) { |
| 10288 | goto error; |
| 10289 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10290 | Py_INCREF(astmodulestate(m)->alias_type); |
| 10291 | if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10292 | < 0) { |
| 10293 | goto error; |
| 10294 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10295 | Py_INCREF(astmodulestate(m)->withitem_type); |
| 10296 | if (PyModule_AddObject(m, "type_ignore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10297 | astmodulestate_global->type_ignore_type) < 0) { |
| 10298 | goto error; |
| 10299 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10300 | Py_INCREF(astmodulestate(m)->type_ignore_type); |
| 10301 | if (PyModule_AddObject(m, "TypeIgnore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10302 | astmodulestate_global->TypeIgnore_type) < 0) { |
| 10303 | goto error; |
| 10304 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10305 | Py_INCREF(astmodulestate(m)->TypeIgnore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 10306 | return m; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10307 | error: |
| 10308 | Py_DECREF(m); |
| 10309 | return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 10310 | } |
| 10311 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10312 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10313 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10314 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10315 | if (!init_types()) |
| 10316 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10317 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10318 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10319 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10320 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 10321 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10322 | { |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 10323 | PyObject *req_type[3]; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 10324 | const char * const req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10325 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10326 | |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 10327 | if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { |
| 10328 | return NULL; |
| 10329 | } |
| 10330 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10331 | req_type[0] = astmodulestate_global->Module_type; |
| 10332 | req_type[1] = astmodulestate_global->Expression_type; |
| 10333 | req_type[2] = astmodulestate_global->Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10334 | |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 10335 | assert(0 <= mode && mode <= 2); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10336 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10337 | if (!init_types()) |
| 10338 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10339 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10340 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 10341 | if (isinstance == -1) |
| 10342 | return NULL; |
| 10343 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10344 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10345 | req_name[mode], _PyType_Name(Py_TYPE(ast))); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10346 | return NULL; |
| 10347 | } |
Dong-hee Na | a05fcd3 | 2019-10-10 16:41:26 +0900 | [diff] [blame] | 10348 | |
| 10349 | mod_ty res = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10350 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 10351 | return NULL; |
| 10352 | else |
| 10353 | return res; |
| 10354 | } |
| 10355 | |
| 10356 | int PyAST_Check(PyObject* obj) |
| 10357 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10358 | if (!init_types()) |
| 10359 | return -1; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10360 | return PyObject_IsInstance(obj, astmodulestate_global->AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10361 | } |
| 10362 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10363 | |